Terraform:在aws_autoscaling_schedule资源

时间:2019-03-16 18:44:00

标签: terraform terraform-provider-aws

将模块输出解析到另一个模块资源时出现错误。

错误:

* module.scheduled_action.aws_autoscaling_schedule.asg[0]: 1 error(s) occurred:

    * aws_autoscaling_schedule.asg.0: Error Creating Autoscaling Scheduled Action: ValidationError: AutoScalingGroup name not found - null
        status code: 400, request id: eedacea2-4819-11e9-a48e-2178a7946e4b
    * module.scheduled_action.aws_autoscaling_schedule.asg[1]: 1 error(s) occurred:

    * aws_autoscaling_schedule.asg.1: Error Creating Autoscaling Scheduled Action: ValidationError: AutoScalingGroup name not found - null
        status code: 400, request id: eedbb8f2-4819-11e9-a103-ed59f82b87f3

代码:

scheduled.tf

resource "aws_autoscaling_schedule" "asg" {
  count = "${var.actions_count}"
  ..
  ...
  ....
  autoscaling_group_name = "{var.autoscaling_group_name}"
}

variables.tf

variable "autoscaling_group_name" {}

main.tf

autoscaling_group_name = "${module.launch_configs.asg_name}"

1 个答案:

答案 0 :(得分:0)

您将模块变量与局部变量混合在一起。

print(json.encode({a=1, b={1,2}, [3]="test"})) 中,{ "cod":"200", "message":0.0036, "cnt":40, "list":[{ "dt":1485799200, "main":{ "temp":261.45, "temp_min":259.086, "temp_max":261.45, "pressure":1023.48, "sea_level":1045.39, "grnd_level":1023.48, "humidity":79, "temp_kf":2.37}, "weather":[ { "id":800, "main":"Clear", "description":"clear sky", "icon":"02n" }], "clouds":{"all":8}, "wind":{"speed":4.77,"deg":232.505}, "snow":{}, "sys":{"pod":"n"}, "dt_txt":"2017-01-30 18:00:00"} ], "city":{ "id":524901, "name":"Moscow", "coord":{ "lat":55.7522, "lon":37.6156 }, "country":"none" } } 的值来自名为main.tf的模块,因此您可以在资源autoscaling_group_name中使用相同的名称

代码可以更改为

launch_configs

在您的情况下,aws_autoscaling_schedule中的变量resource "aws_autoscaling_schedule" "asg" { count = "${var.actions_count}" .. ... .... autoscaling_group_name = "${module.launch_configs.asg_name}" } 的定义是无用的。您可以删除它。