amazon-web-services - 在 Terraform 中使用不同的模板创建多个启动配置
问题描述
我正在尝试编写一些 Terraform 代码来使用一个资源块创建多个启动配置。它变得棘手的部分是每个启动配置我需要为每个启动配置使用一个独特的模板。我正在使用 Terraform 0.11.10,所以我认为需要使用 count 。下面的代码使用相同的模板创建多个启动配置,我需要能够为每个配置使用不同的模板。任何意见将是有益的。
启动配置
resource "aws_launch_configuration" "launch_configuration" {
count = "${(var.enable ? 1 : 0) * var.number_of_zones}"
name = "${var.cluster_name}-launch_node_${count.index}"
key_name = "${var.key_name2}"
image_id = "${lookup(var.amis, "${var.aws_region}.${var.licensee_key == "" && var.licensee == "" ? "enterprise" : "byol"}")}"
user_data = "${element(data.template_file.user_data.*.rendered, count.index)}"
security_groups = [
"${aws_security_group.instance_security_group.id}",
]
instance_type = "${var.instance_type}"
iam_instance_profile = "${aws_iam_instance_profile.instance_host_profile.name}"
ebs_block_device {
device_name = "/dev/sdf"
no_device = true
}
模板文件
data "template_file" "user_data" {
count = "${(var.enable ? 1 : 0) * var.number_of_zones}"
template = "${file("userdata.sh")}"
vars {
node = "Node${count.index + 1}_#"
master = "${count.index == 0 ? 1 : 0}"
licensee = "${var.licensee}"
licensee_key = "${var.licensee_key}"
cluster_name = "${var.cluster_name}"
ebs_volume = "${element(aws_ebs_volume.volume.*.id, count.index)}"
volume_size = "${var.volume_size}"
volume_type = "${var.volume_type}"
ansible_git_ssh_key = "${var.ansible_git_ssh_key}"
ansible_pull_url = "${var.ansible_pull_url}"
ansible_playbook_file = "${var.ansible_playbook_file}"
ansible_inventory_file = "${var.ansible_inventory_file}"
ansible_pull_branch = "${var.ansible_pull_branch}"
}
解决方案
推荐阅读
- angular - 如何使用 angular2 将可迭代 id 存储在 div 标签内的#refernce 变量中?
- c# - Entity Framework 6.2.0 不生成某些类(数据库优先)
- php - 如何访问数组中的值或数组中的数组
- database - 使用没有 ACE.OLEDB 提供程序的数据库
- react-native - 运行 detox/wix 测试用例 android.util.AndroidException: INSTRUMENTATION_FAILED:
- android - 必须在 Android Studio 中实现 OnFragmentInteractionListener 错误
- c# - C# WPF Treeview ItemContainerStyle 使 mouseclick 事件发送者丢失 TreeviewItem 引用
- c - 比较 C 中的哈希值
- php - codeigniter中的登录错误消息验证
- key - Hashicorp Vault PKI 最小密钥大小