我正在尝试创建启动配置、ELB 和 2 ASG。我想一个 ELB 可以创建 2 个 ASG(我不确定)。
所以我在一个调用 as 模块的文件中有一个启动配置和 asg 代码。我的问题是,我可以使用单个 terraform 文件还是使用单个 repo 中的文件创建 2 个 ASG?
另外,请让我知道这是否是一个好的配置。
当我尝试将两个不同的文件调用同一个模块时,我收到以下错误。
Error downloading modules: Error loading modules: module asg: duplicated. module names must be unique
我的地形代码:
自动缩放.tf
resource "aws_launch_configuration" "launch_config" {
image_id = "${var.ec2ami_id}"
instance_type = "${var.ec2_instance_type}"
security_groups = ["${aws_security_group.*******.id}"]
key_name = "${var.keypair}"
lifecycle {
create_before_destroy = true
}
}
module "asg" {
source = ****
name = "*****"
environment = "***"
service = "****"
product = "**"
team = "****"
owner = "*****"
ami = "${var.ec2_id}"
#instance_profile = "******"
instance_type = "t2.micro"
ebs_optimized = true
key_name = "${var.keypair}"
security_group = ["${aws_security_group.****.id}"]
user_data = "${path.root}/blank_user_data.sh"
load_balancer_names = "${module.elb.elb_name}"
associate_public_ip = false
asg_instances = 2
asg_min_instances = 2
asg_max_instances = 4
root_volume_size = 250
asg_wait_for_capacity_timeout = "5m"
vpc_zone_subnets = "${module.vpc.private_subnets}"
}
###elb.tf###
module "elb" {
source = "*****"
name = "***elb"
subnet_ids = "${element(split(",",
module.vpc.private_subnets), 0)}"
security_groups = "${aws_security_group.****.id}"
s3_access_logs_bucket = "****"
}
我想在一个子网中创建 2 个 ASG。