DevOps 管道在将变量值作为 JSON 正文发送以使用 Terraform 部署 Azure 资源时更改时间格式

DevOps Pipeline changing Timeformat when sending variable values as JSON Body to Deploy Azure Resources with Terraform

我的 Azure 资源 Terraform 部署包含一个预算,它需要一个开始和结束日期。当我通过 http Post 从我的逻辑应用程序发送我的 JSON Body/variable 值时,DevOps 更改了我的字符串值的时间格式。 Terraform 需要特定的时间格式,即 RFC 3339。每当我将数据发送到 DevOps 时,它都会更改为另一个无效的标准。

管道错误:

│ Error: expected "time_period.0.end_date" to be a valid RFC3339 date, got "06/01/2022 11:53:27": parsing time "06/01/2022 11:53:27" as "2006-01-02T15:04:05Z07:00": cannot parse "1/2022 11:53:27" as "2006"
│ 
│   with azurerm_consumption_budget_resource_group.management,
│   on costmanagement.tf line 33, in resource "azurerm_consumption_budget_resource_group" "management":
│   33:     end_date   = var.end_date
│ 
╵
##[error]Terraform command 'plan' failed with exit code '1'.
##[error]╷
│ Error: expected "time_period.0.end_date" to be a valid RFC3339 date, got "06/01/2022 11:53:27": parsing time "06/01/2022 11:53:27" as "2006-01-02T15:04:05Z07:00": cannot parse "1/2022 11:53:27" as "2006"
│ 
│   with azurerm_consumption_budget_resource_group.management,
│   on costmanagement.tf line 33, in resource "azurerm_consumption_budget_resource_group" "management":
│   33:     end_date   = var.end_date

我要发送的正文:

{
  "variables": {
    "end_date": {
      "isSecret:": false,
      "value": "2022-07-31T11:53:23.000Z"
    },
    "start_date": {
      "isSecret:": false,
      "value": "2022-06-01T11:53:27.000Z"
    }
  }
}

如何防止它在部署期间被更改?

唯一需要更改的是在 JSON 类型变量 end_date:

中引用一个(两个键中的一个)
end_date = var.end_date["value"]

这样只会引用名称为 value 的键。同样,如果您需要访问 isSecret 键(或将来添加到变量的任何其他键)的值,您将使用:

someargument = var.end_date["isSecret"] # or var.end_date["<key-name>"]

有关访问 map 变量值的更多信息,请参阅 [1]。


[1] https://www.terraform.io/language/expressions/type-constraints#map