我正在使用terraform 0.11和aws提供程序。我使用hashicorp提供的模块terraform-aws-modules/autoscaling创建了大约20个ASG
ASG示例:
module "role_a" {
source = "terraform-aws-modules/autoscaling/aws"
version = "2.8.0"
name = "Role-A-ASG"
image_id = "ami-123456"
...
min_size = "1"
desired_capacity = "2"
max_size = "3"
}
我知道我可以为20个ASG中的每一个定义20个aws_autoscaling_schedule
资源。但是,我想知道是否有更简单的方法可以使用count
技巧来做到这一点。
我定义了一个变量,该变量包含要将aws_autoscaling_schedule
应用于的ASG列表。
asg_turn_off_morning = [ "asg_role_a" ]
但是我找不到在autoscaling_group_name
resource "aws_autoscaling_schedule" "turn_off_morning" {
count = "${length(var.asg_turn_off_morning)}"
recurrence = "0 7 * * *"
scheduled_action_name = "Turn off in the morning"
...
# interpolating the resource reference works ok, but
autoscaling_group_name = "${module.role_a.this_autoscaling_group_name}"
# interpolating a string with the resource's name does not work
autoscaling_group_name = "${join(".", list("module", "role_a", "this_autoscaling_group_name"))}"
# If it did I could eventually do something like:
# I know this is not valid HCL, I just want to show what I want to do
autoscaling_group_name = "${join(".", list("module", ${element(var.asg_turn_off_morning, count.index)} , "this_autoscaling_group_name"))}"
}
是否有一种反向查询表可以将asg_role_a
资源映射到其属性之一?