01
Getting Started
Provider
Providers define cloud platforms.
terraform
provider "aws" {
region = "us-east-1"
}Resource
Resources define infrastructure objects.
terraform
resource "aws_instance" "web" {
ami = "ami-123456"
instance_type = "t2.micro"
tags = { Name = "WebServer" }
}Commands
Core workflow: init, plan, apply, destroy.
terraform
# terraform init
# terraform plan
# terraform apply
# terraform destroy02
Features
Variables
Variables for parameterization.
terraform
variable "region" {
type = string
default = "us-east-1"
}
resource "aws_instance" "web" {
region = var.region
}Outputs
Outputs expose values after apply.
terraform
output "instance_ip" {
value = aws_instance.web.public_ip
}Data Sources
Data sources query existing resources.
terraform
data "aws_ami" "ubuntu" {
most_recent = true
filter { name = "name"; values = ["ubuntu-*"] }
}Was this helpful?