HashiCorp./terraform
[Terraform] AWS EC2 count 변수 및 CLB 연결
인쥭
2020. 12. 20. 23:11
반응형
EC2
resource "aws_instance" "common_ec2" {
// 생략
count = var.instance_count
tags = {
Name = "Common-EC2-${count.index}"
}
provisioner "local-exec" {
command = "echo ${self.private_ip} >> ./output/common_backend.txt"
}
}
CLB
resource "aws_elb" "LB_Public" {
name = "LB"
// 생략
listener {
lb_port = 80
lb_protocol = "HTTP"
instance_port = 80
instance_protocol = "HTTP"
}
instances = aws_instance.common_ec2.*.id
provisioner "local-exec" {
command = "echo ${self.dns_name} > output/publicLB.txt"
}
}
variables
variable "instance_count" {
type = number
default = 1
}