如何使数据模板文件识别terraform中的数字
我现在面临的问题是这个。我正在努力使我的政策更加灵活。因此,我将它们转换为一个文件,而不是使用EOF 如何使模板文件识别数字值如何使数据模板文件识别terraform中的数字,terraform,terragrunt,Terraform,Terragrunt,我现在面临的问题是这个。我正在努力使我的政策更加灵活。因此,我将它们转换为一个文件,而不是使用EOF 如何使模板文件识别数字值 “${max\u untaged\u images}”和“${max\u taged\u images}”假定为数字 Aws生命周期策略: resource "aws_ecr_lifecycle_policy" "lifecycle" { count = length(aws_ecr_repository.repo)
“${max\u untaged\u images}”和“${max\u taged\u images}”假定为数字
Aws生命周期策略:
resource "aws_ecr_lifecycle_policy" "lifecycle" {
count = length(aws_ecr_repository.repo)
repository = aws_ecr_repository.repo[count.index].name
depends_on = [aws_ecr_repository.repo]
policy = var.policy_type == "app" ? data.template_file.lifecycle_policy_app.rendered : data.template_file.lifecycle_policy_infra.rendered
}
数据模板:
data "template_file" "lifecycle_policy_app" {
template = file("lifecyclePolicyApp.json")
vars = {
max_untagged_images = var.max_untagged_images
max_tagged_images = var.max_tagged_images
env = var.env
}
}
政策:
{
"rules": [
{
"rulePriority": 1,
"description": "Expire untagged images older than ${max_untagged_images} days",
"selection": {
"tagStatus": "untagged",
"countType": "sinceImagePushed",
"countUnit": "days",
"countNumber": "${max_untagged_images}"
},
"action": {
"type": "expire"
}
},
{
"rulePriority": 2,
"description": "Expire tagged images of ${env}, older than ${max_tagged_images} days",
"selection": {
"tagStatus": "tagged",
"countType": "imageCountMoreThan",
"countNumber": "${max_tagged_images}",
"tagPrefixList": [
"${env}"
]
},
"action": {
"type": "expire"
}
}
]
}
我将尝试以下两个步骤:
删除“${max\u taged\u images}”周围的双引号
使用名为tonumber的地形函数将其转换为数字:
数字(“1”)
(遵循官方文档:)删除引号就足够了。谢谢。我尝试过删除引号,效果很好。