반응형
테라폼 concat 함수(function)
: concat은 둘 이상의 목록을 가져와서 단일 목록으로 결합합니다.
instance 모듈
instance.tf 편집
resource "aws_instance" "instance" {
count = var.instance_count
instance_type = var.instance_type
ami = lookup(var.aws_amis, var.aws_region)
key_name = var.key_name
subnet_id = element(var.subnet_id, count.index)
vpc_security_group_ids = var.vpc_security_group_ids
associate_public_ip_address = var.associate_public_ip_address
monitoring = true
root_block_device {
volume_size = var.disk_size
}
lifecycle {
create_before_destroy = true
}
tags = {
Name = "${var.name}${count.index+1}"
Group = "group-${var.group_name}"
Environment = "env-${var.env}"
CreateUser = "terraform"
Owner = "admin@4wxyz.com"
Role = "ec2"
Service = "instance"
CreatedDate = timestamp()
}
}
###################################################
##################### OUTPUTS #####################
###################################################
output "instance_info" {
value = concat([aws_instance.instance.*.private_ip, aws_instance.instance.*.public_ip, aws_instance.instance.*.id])
}
output "instance_info" {
value = concat([aws_instance.instance.*.private_ip, aws_instance.instance.*.public_ip, aws_instance.instance.*.id])
}
instance 메인
main.tf 편집
module "ec2-web" {
source = "../../../module/ec2/instance/"
env = "prod"
instance_count = 2
name = "web1"
group_name = "web"
#aws_amis = "ami-0742b4e673072066f"
aws_region = "us-east-1"
instance_type = "t2.micro"
disk_size = "8"
key_name = "4wxyz"
subnet_id = ["subnet-0381d3", "subnet-00be79"]
vpc_security_group_ids = ["sg-077e2a", "sg-0c261f"]
associate_public_ip_address = true
}
###################################################
##################### OUTPUTS #####################
###################################################
#####EC2 정보
output "aws_instance_info" {
description = "인스턴스 정보"
value = module.ec2-web.instance_info
}
output "aws_instance_info" {
description = "인스턴스 정보"
value = module.ec2-web.instance_info
}
terraform apply
$ terraform apply
...
Outputs:
aws_instance_info = [
[
"10.31.xxx.xxx",
"10.31.xxx.xxx",
],
[
"23.228.xxx.xxx",
"52.54.xxx.xxx",
],
[
"i-0cbcf7",
"i-0a4d89",
],
]
728x90
반응형
'퍼블릭 클라우드' 카테고리의 다른 글
[Terraform] 테라폼 ALB 대상 그룹 등록 (0) | 2021.04.17 |
---|---|
[Terraform] 테라폼 join 함수(function) (0) | 2021.04.17 |
[VPN] Amazon Linux 2에 WireGuard를 설치하는 방법 (0) | 2021.03.16 |
AWS 교차 계정 접근(Cross-Account Access)을 설정하는 방법 (0) | 2021.02.20 |
[Terraform] 테라폼 모듈화 테스트 (0) | 2021.02.17 |