aws_lb 를 공식문서에서 본다.
→ 로드밸런서 생성코드
# Configure the AWS Provider
provider "aws" {
region = "ap-northeast-2"
}
resource "aws_security_group" "allow_alb_song" {
name = "allow_alb_song"
description = "Allow alb_song inbound traffic"
vpc_id = "vpc-0312d1996462eb0a0"
ingress {
description = "webSong from VPC"
from_port = 0
to_port = 0
protocol = "-1" #모든 프로토콜에 대해서
cidr_blocks = ["0.0.0.0/0"] #모든 ip에 대해서
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
tags = {
Name = "allow_webSong_alb"
}
}
resource "aws_lb" "test" {
name = "test-lb-tf"
internal = false
load_balancer_type = "application"
security_groups = [aws_security_group.allow_alb_song.id]
subnets = [for subnet in aws_subnet.public : subnet.id]
enable_deletion_protection = true
access_logs {
bucket = aws_s3_bucket.lb_logs.bucket
prefix = "test-lb"
enabled = true
}
tags = {
Environment = "production"
}
}
# Configure the AWS Provider
provider "aws" {
region = "ap-northeast-2"
}
variable "vpc_id"{
default = "vpc-0312d1996462eb0a0"
}
variable "subnet_id"{
default = ["subnet-097b40615c674f993","subnet-033fcb86690c20369"]
}
resource "aws_security_group" "allow_alb_song" {
name = "allow_alb_song"
description = "Allow alb_song inbound traffic"
vpc_id = var.vpc_id #variable 참조
ingress {
description = "webSong from VPC"
from_port = 0
to_port = 0
protocol = "-1" #모든 프로토콜에 대해서
cidr_blocks = ["0.0.0.0/0"] #모든 ip에 대해서
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
tags = {
Name = "allow_webSong_alb"
}
}
resource "aws_lb" "test" {
name = "test-lb-tf"
internal = false
load_balancer_type = "application"
security_groups = [aws_security_group.allow_alb_song.id]
subnets = var.subnet_id #variable참조
enable_deletion_protection = false
#alb가 삭제되지 않도록 보호하는 기능 ,true 상태에서 tf desotry 하게되면 정상적으로 안되기 때문에 fasle
tags = {
Name = "alb_song"
}
}
참조