You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Terraform中动态设置Key Vault Secret过期日期报错求助

解决Terraform中Azure Key Vault Secret动态过期日期配置错误

错误原因

报错提示timestamp()函数不接受参数,你错误地将time_offset.expiry_date.rfc3339作为参数传入该函数。实际上timestamp()是无参函数,仅用于获取当前时间的RFC3339格式字符串;而time_offset资源的rfc3339属性已经是计算好的、偏移6个月后的时间字符串,直接使用即可。

修正后的代码

resource "time_offset" "expiry_date" {
  offset_months = 6
}

resource "azurerm_key_vault_secret" "local_admin_pwd" {
    name = "LocalAdminPassword"
    value = random_password.pwd.result
    key_vault_id = azurerm_key_vault.keyvault.id
    expiration_date = time_offset.expiry_date.rfc3339
}

说明

  • time_offset.expiry_date.rfc3339会自动计算当前时间加6个月后的RFC3339格式时间,完全符合azurerm_key_vault_secret资源expiration_date字段的格式要求。
  • 无需再调用timestamp()函数,避免因参数错误导致的报错。

内容的提问来源于stack exchange,提问作者Jon

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.13 19:05:31