简体   繁体   English

使用 Terraform 创建 StringLike 条件

[英]Creating a StringLike condition with Terraform

I am trying to generate some terraform for an aws IAM policy.我正在尝试为 aws IAM 策略生成一些 terraform。 The condition in the policy looks like this政策中的条件看起来像这样

"StringLike": {
 "kms:EncryptionContext:aws:cloudtrail:arn": [
 "arn:aws:cloudtrail:*:aws-account-id:trail/*"
 ]

I am looking at the documentation for aws_iam_policy_document : https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document , but it's not clear to me as to how to write this in terraform. Any help would be greatly apprecaited.我正在查看aws_iam_policy_document的文档: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document ,但我不清楚如何在 terraform 中编写此文档。任何帮助将不胜感激。 This is my attempt这是我的尝试

condition {
        test = "StringLike"
        variable = "kms:EncryptionContext:aws:cloudtrail:arn"

        values = [
            "arn:aws:cloudtrail:*:aws-account-id:trail/*"
        ]
    }

Hello Evan you logic is correct just to add:你好埃文你的逻辑是正确的只是添加:

Each document configuration may have one or more statement每个文档配置可能有一个或多个statement

data "aws_iam_policy_document" "example" {
  statement {
    actions = [
      "*", *//specify your actions here*
    ]

    resources = [
      "*", *//specify your resources here*
    ]
    condition {
     test = "StringLike"
     variable = "kms:EncryptionContext:aws:cloudtrail:arn"

     values = [
        "arn:aws:cloudtrail:*:aws-account-id:trail/*"
     ]
    }
}

Each policy statement may have zero or more condition blocks, which each accept the following arguments:每个策略语句可能有零个或多个条件块,每个条件块接受以下 arguments:

  • test (Required) The name of the IAM condition operator to evaluate. test (必需)要评估的 IAM 条件运算符的名称。
  • variable (Required) The name of a Context Variable to apply the condition to. variable (必需)要应用条件的上下文变量的名称。 Context variables may either be standard AWS variables starting with aws:, or service-specific variables prefixed with the service name.上下文变量可以是以 aws: 开头的标准 AWS 变量,也可以是以服务名称为前缀的特定于服务的变量。
  • values (Required) The values to evaluate the condition against. values (必需)用于评估条件的值。 If multiple values are provided, the condition matches if at least one of them applies.如果提供了多个值,则如果其中至少一个适用,则条件匹配。 (That is, the tests are combined with the "OR" boolean operation.) (即测试与“或”boolean 操作相结合。)

When multiple condition blocks are provided, they must all evaluate to true for the policy statement to apply.当提供多个条件块时,它们必须全部评估为真才能应用策略语句。 (In other words, the conditions are combined with the "AND" boolean operation.) (换句话说,条件与“AND” boolean 运算相结合。)

Here's the REF from terraform这是来自terraform的 REF

IN Addition to create the policy from the document you created you use it like this:除了从您创建的文档创建策略外,您还可以像这样使用它:

resource "aws_iam_policy" "example" {
  policy = data.aws_iam_policy_document.example.json
}

Here's A ref from Hashicorp这是来自Hashicorp的参考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Terraform 在 zip 准备好之前创建 lambda - Terraform creating lambda before zip is ready terraform aws:创建安全组时的协议不正确 - terraform aws: Incorrect protocol in creating a security group 从 terraform 创建的 pubsub 模式定义错误 - Error in pubsub schema definition creating from terraform 使用 terraform 和自定义轻量级机器创建 CloudSQL 实例 - Creating a CloudSQL instance with terraform and custom lightweight machine Terraform 错误:运行 terraform 计划时条件类型不正确 - Terraform Error: Incorrect condition type when running terraform plan terraform aws_lb_listener_rule 条件争论未在 terraform 0.12.20 中得到认可 - terraform aws_lb_listener_rule condition arguement not getting recognized in terraform 0.12.20 在 Terraform 嵌套循环中创建 AWS 安全组 - Creating AWS Security Groups in a Terraform Nested Loop 使用 Eventarc 创建一个目标为云函数的 terraform - Creating a terraform with Eventarc with its destination to cloud function 为 alb 侦听器规则创建动态 Terraform 规则时出错 - Error when creating dynamic terraform rule for alb listener rule 在 Terraform for Cloud Run 中创建动态秘密变量块 - Creating a dynamic secret variable block within Terraform for Cloud Run
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM