Write, Plan, Apply
Deliver Infrastructure as Code
resource "aws_instance" "iac_in_action" {
ami = var.ami_id
instance_type = var.instance_type
availability_zone = var.availability_zone
// dynamically retrieve SSH Key Name
key_name = aws_key_pair.iac_in_action.key_name
// dynamically set Security Group ID (firewall)
vpc_security_group_ids = [aws_security_group.iac_in_action.id]
tags = {
Name = "Terraform-managed EC2 Instance for IaC in Action"
}
}
Write
Write infrastructure as code using declarative configuration files. HashiCorp Configuration Language (HCL) allows for concise descriptions of resources using blocks, arguments, and expressions.
$ terraform plan
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# aws_ebs_volume.iac_in_action will be created
+ resource "aws_ebs_volume" "iac_in_action" {
+ arn = (known after apply)
+ availability_zone = "us-east-1a"
+ encrypted = (known after apply)
+ id = (known after apply)
+ iops = 1000
+ kms_key_id = (known after apply)
+ size = 100
+ snapshot_id = (known after apply)
+ tags = {
+ "Name" = "Terraform-managed EBS Volume for IaC in Action"
}
+ type = "io1"
}
Plan: 1 to add, 0 to change, 0 to destroy.
Plan
Run terraform plan
to check whether the execution plan for a configuration matches your expectations before provisioning or changing infrastructure.
Apply
Apply changes to hundreds of cloud providers with terraform apply
to reach the desired state of the configuration.
Features
variable "ami_id" {
type = string
description = "AMI ID to use"
default = "ami-09d95fab7fff3776c"
}
variable "instance_type" {
type = string
description = "Instance type to use"
default = "t3.micro"
}
variable "availability_zone" {
type = string
description = "Availability Zone to use"
default = "us-east-1a"
}
Why Terraform
Codify your application infrastructure
Reduce human error and increase automation by provisioning infrastructure as code.
Manage infrastructure across clouds
Provision infrastructure across 300+ public clouds and services using a single workflow.
Create reproducible infrastructure
Provision consistent testing, staging, and production environments with the same configuration.
How Terraform Works
Terraform allows infrastructure to be expressed as code in a simple, human readable language called HCL (HashiCorp Configuration Language). It reads configuration files and provides an execution plan of changes, which can be reviewed for safety and then applied and provisioned.
Extensible providers allow Terraform to manage a broad range of resources, including IaaS, PaaS, SaaS, and hardware services.
A strong community
- 450,000+ Commits
- 4,000+ Modules
- 500+ Providers
Open source projects benefit from the scrutiny of a broad and diverse user base. Keeping the code available helps empower the community of users while also providing an easy mechanism for feedback, improvement, and customization.