我在迭代函数解释的模板内的对象列表时遇到问题templatefile。
我有以下变量:
variable "destinations" {
description = "A list of EML Channel Destinations."
type = list(object({
id = string
url = string
}))
}
Run Code Online (Sandbox Code Playgroud)
templatefile这将作为传递给函数destinations。相关模板的片段是这样的:
Destinations:
%{ for dest in destinations ~}
- Id: ${dest.id}
Settings:
URL: ${dest.url}
%{ endfor }
Run Code Online (Sandbox Code Playgroud)
规划 Terraform 时会出现以下错误:
Error: "template_body" contains an invalid YAML: yaml: line 26: did not find expected key
Run Code Online (Sandbox Code Playgroud)
我尝试将模板代码切换为以下内容:
Destinations:
%{ for id, url in destinations ~}
- Id: ${id}
Settings:
URL: ${url}
%{ endfor …Run Code Online (Sandbox Code Playgroud) 我正在使用 AWS 和 Terraform 来启动基础设施,但特别是我在使用混合实例策略启动 ASG 时遇到了问题。我正在尝试启动一个 ASG,其中一个实例始终是按需提供的,其余位置(所有类型都相同),从表面上看,这看起来很容易,但我已经尝试了一段时间并不断遇到各种错误. 这是我目前正在使用的:
resource "aws_launch_template" "lt" {
name_prefix = "danny_test-"
vpc_security_group_ids = [
"${module.sec_groups.security_group_id_common}",
"${module.sec_groups.security_group_id_ssh}",
"${module.sec_groups.security_group_id_web}"
]
image_id = "${module.core_ami.core_ami_id}"
instance_type = "t2.small"
key_name = "${var.ssh_privkey_name}"
user_data = "${base64encode(data.template_file.common_user_data.rendered)}"
iam_instance_profile {
name = "${module.infradev_remote_state.iam_profile_updater_id}"
}
lifecycle {
create_before_destroy = true
}
}
resource "aws_autoscaling_group" "asg" {
name = "danny_test"
vpc_zone_identifier = ["${split(",", module.environment.private_subnet_ids)}"]
#launch_configuration = "${aws_launch_configuration.lc.name}"
min_size = "0"
max_size = "1"
desired_capacity = "1"
health_check_grace_period = "600"
health_check_type = "EC2"
launch_template {
id …Run Code Online (Sandbox Code Playgroud) amazon-web-services autoscaling terraform terraform-provider-aws infrastructure-as-code