使用不同的模板在 Terraform 中创建多个启动配置

问题描述

我正在尝试编写一些 terraform 代码,以使用一个资源块创建多个启动配置。它变得棘手的部分是每个启动配置我需要有一个用于每个启动配置的唯一模板。我正在使用 terraform 0.11.10,所以我相信需要使用计数。下面的代码使用相同的模板创建多个启动配置,我需要能够为每个启动配置使用不同的模板。任何建议都会有所帮助。

启动配置

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}"
  }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...