如何使我的数据模板文件识别地形中的数字



我现在面临的问题是这个。我正在努力使我的政策更加灵活。所以我把它们转移到一个文件中,而不是使用EOF。

如何使模板文件识别数字值?

假设CCD_ 1和CCD_。

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"
}
}
]
}

我会尝试以下两个步骤:

  1. 删除"${max_tagged_images}";

  2. 使用称为tonumber的地形函数将其转换为数字:

    吨数("1"(

(请遵循官方文档:https://www.terraform.io/docs/configuration/functions/tonumber.html)

最新更新