未找到terraform random_string keepers属性

时间:2017-12-01 15:03:39

标签: string random terraform

我正在尝试将random_string terraform资源与keepers属性一起使用。

resource "random_string" "rand" {
  length = 16
  special = false
  upper = false

  keepers = {
    md5 = "${md5(file("./terraform/batch.tf"))}"
    service_role = "arn:aws:iam::${var.target_aws_account_id}:role/BatchService"
    instance_role  = "${aws_iam_instance_profile.service_role.arn}"
    spot_iam_fleet_role = "${aws_iam_role.spot_fleet_role.arn}"
    image_id = "${data.aws_ami.base_ami.image_id}"
    max_vcpus = 1000
    min_vcpus = 0
    bid_percentage = 50
    security_group_id = "${aws_security_group.outbound_sg.id}"
    private_subnets = "${join(", ", var.private_subnets)}"
  }
}

然后我尝试引用其他资源的守护者属性,比如

resource "aws_batch_compute_environment" "compute_env" {
  compute_environment_name = "compute-env-v1-${random_string.rand.result}"
  compute_resources {
    instance_role =  "${random_string.rand.keepers.instance_role}"
    ...
  }
  type = "MANAGED"

  lifecycle {
    create_before_destroy = true
  }
}

但是,这会导致错误,例如

aws_batch_compute_environment.compute_env: Resource 'random_string.rand' does not have attribute 'keepers.instance_role' for variable 'random_string.rand.keepers.instance_role'

我在这里做错了什么?为什么random_string资源没有keepers值的这些属性?

谢谢, 大卫

0 个答案:

没有答案