【问题标题】:unknown function called: formatdate - what is equivalent of 'formatdate' in terraform 0.11.x?称为未知函数:formatdate - terraform 0.11.x 中的“formatdate”是什么?
【发布时间】:2019-07-09 14:25:36
【问题描述】:

我想为我的 ec2 实例名称引入一个简单的时间戳

   tags = {

    "Name" = "windows server 2012 ${var.env} - ${formatdate("YYYYMMDD", timestamp())}"
}

但是当我运行terraform validate时,

我知道了

Error: aws_instance.convertor: 1 error(s) occurred:

* aws_instance.convertor: 1:33: unknown function called: formatdate in:

 windows server 2012 ${var.env} - ${formatdate("YYYYMMDD", timestamp())}

显然 formatdate 在我的 terraform (v0.11.7) 版本中不可用。如何在 0.11.7 的 HCL 中获得相同的结果?

【问题讨论】:

    标签: terraform


    【解决方案1】:

    formatdate 函数仅适用于 terraform v0.12。你可以做的是使用一些字符串操作来得到你的结果,解释在这里 (Terraform timestamp() to numbers only string) 并做一个简单的子字符串,不是一个非常优雅的解决方案,但它可以工作。

    locals {
     timestamp = "${timestamp()}"
     timestamp_sanitized = "${substr(replace("${local.timestamp}", "/[-| |T|Z|:]/", ""),0,8)}"
    }
    
    output "timestamp" {
      value = "${local.timestamp_sanitized}"
    }
    

    【讨论】:

      猜你喜欢
      • 2021-04-12
      • 1970-01-01
      • 1970-01-01
      • 2013-11-29
      • 2016-11-26
      • 1970-01-01
      • 2012-05-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多