Open choisungwook opened 2 years ago
nat_gateway생성은 옵션으로
variables.tf
variable create_natgw {
type = bool
default = false
description = "nat gateway생성 여부"
}
main.tf
resource "aws_eip" "nat_eip" {
for_each = var.private_subnets
vpc = true
depends_on = [aws_internet_gateway.igw]
tags = {
Name = "${var.name}-nat"
}
}
resource "aws_nat_gateway" "main" { for_each = var.create_natgw ? var.private_subnets: {}
allocation_id = aws_eip.nat_eip[each.key].id subnet_id = aws_subnet.private[each.key].id
tags = { Name = "${var.name}-${each.key}-natgw" }
depends_on = [aws_internet_gateway.igw] }
# 참고자료
* https://www.reddit.com/r/Terraform/comments/fh7ma1/terraform_conditional_if_in_for_each/