My Terraform Deployment for Azure Resources contains a Budget, which requires a start and end date. When I'm sending my JSON Body/variable value from my Logic App over an http Post, DevOps changes the timeformat of my string values. Terraform requires a specific timeformat which is RFC 3339. Whenever I'm sending my data to DevOps, it gets changed to another standard which isn't valid.
Error from Pipeline:
│ 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
Body I'm sending:
{
"variables": {
"end_date": {
"isSecret:": false,
"value": "2022-07-31T11:53:23.000Z"
},
"start_date": {
"isSecret:": false,
"value": "2022-06-01T11:53:27.000Z"
}
}
}
How can I prevent that it gets changed during the deployment?
CodePudding user response:
The only thing that needs to be changes is to reference one (out of two keys) in the JSON type variable end_date
:
end_date = var.end_date["value"]
This way only the key with name value
will be referenced. Similarly, if you needed to access the value for the isSecret
key (or any other key added to the variable in the future), you would use:
someargument = var.end_date["isSecret"] # or var.end_date["<key-name>"]
More information about accessing values of map
variables can be found in [1].
[1] https://www.terraform.io/language/expressions/type-constraints#map