01
시작하기
프로바이더
프로바이더가 클라우드 플랫폼을 정의합니다.
terraform
provider "aws" {
region = "us-east-1"
}리소스
리소스로 인프라 객체를 정의합니다.
terraform
resource "aws_instance" "web" {
ami = "ami-123456"
instance_type = "t2.micro"
tags = { Name = "WebServer" }
}명령어
핵심 워크플로: init, plan, apply, destroy.
terraform
# terraform init
# terraform plan
# terraform apply
# terraform destroy02
주요 기능
변수
변수로 설정을 파라미터화합니다.
terraform
variable "region" {
type = string
default = "us-east-1"
}
resource "aws_instance" "web" {
region = var.region
}출력
outputs는 apply 후 값을 노출합니다.
terraform
output "instance_ip" {
value = aws_instance.web.public_ip
}데이터 소스
데이터 소스로 기존 리소스를 조회합니다.
terraform
data "aws_ami" "ubuntu" {
most_recent = true
filter { name = "name"; values = ["ubuntu-*"] }
}Was this helpful?