首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何解决策略文档中的以下代码中收到的错误消息

如何解决策略文档中的以下代码中收到的错误消息
EN

Stack Overflow用户
提问于 2021-12-13 21:22:01
回答 1查看 206关注 0票数 0

当我运行terraform时,我得到了下面的错误:无效的模板插值值,var.oidc_condition_statement是包含两个元素的字符串列表,不能将给定的值包含在字符串模板中: string必需。

代码语言:javascript
复制
resource "aws_iam_role" "Orchestration_role"{
    name = var.orchestration_role_name

    assume_role_policy = <<EOF
{
    "Version":"2012-10-17",
    "Statement": [
        {
           "Effect": "Allow",
           "Action": "sts:AssumeRoleWithWebIdentity",
           "Principal":{
               "Federated":"arn:aws:iam::${var.aws_oidc_account}:oidc-provider/token.actions.githubusercontent.com"
           },
           "Condition":{
               "ForAnyValue:StringLike":{
                   "token.actions.githubusercontent.com:sub": "${var.oidc_condition_statement}"
               }
           }
        }
    ]
}
EOF
}

variable.tf

variable "oidc_condition_statement"{
    type = list(string)
}

tfvars

oidc_condition_statement          = ["repo:organization/terraform-aws-githubaction:ref:refs/heads/staging","repo:organization/terraform-aws-githubaction:pull_request"]
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-12-13 23:38:08

请使用jsonencode

代码语言:javascript
复制
resource "aws_iam_role" "Orchestration_role"{
    name = var.orchestration_role_name

    assume_role_policy = <<EOF
{
    "Version":"2012-10-17",
    "Statement": [
        {
           "Effect": "Allow",
           "Action": "sts:AssumeRoleWithWebIdentity",
           "Principal":{
               "Federated":"arn:aws:iam::${var.aws_oidc_account}:oidc-provider/token.actions.githubusercontent.com"
           },
           "Condition":{
               "ForAnyValue:StringLike":{
                   "token.actions.githubusercontent.com:sub": ${jsonencode(var.oidc_condition_statement)}
               }
           }
        }
    ]
}
EOF
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70341071

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档