# Jsonencode with aws tag policy

**URL:** <https://discuss.hashicorp.com/t/jsonencode-with-aws-tag-policy/31831>\
**Category:** AWS\
**Created:** [November 12, 2021, 10:04am UTC](https://discuss.hashicorp.com/t/jsonencode-with-aws-tag-policy/31831 "2021-11-12T10:04:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jan-ludvik](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/jan-ludvik/32/23270_2.png) [@jan-ludvik](https://discuss.hashicorp.com/u/jan-ludvik)\
**Post date:** [November 12, 2021, 10:04am UTC](https://discuss.hashicorp.com/t/jsonencode-with-aws-tag-policy/31831/1 "2021-11-12T10:04:57Z")

</div>

Hi,

I am retrieveing values for our [teams from tool OpsLevel](https://registry.terraform.io/providers/OpsLevel/opslevel/latest/docs/data-sources/teams) and trying to insert those into AWS Organizations Tag Policy. I keep getting `MalformedPolicyDocumentException: The provided policy document does not meet the requirements of the specified policy type.` error message no matter what I try.

I am getting a list of teams from Opslevel which looks like this:

```auto
opslevel_teams = [
        teamA,
        teamB, 
        teamC,
    ]

```

And I want to use this in AWS Tag policy in tag values which has this format:

```auto
tag_policy = {
  "tags": {
    "team": {
      "tag_key": {
        "@@assign": "team"
      },
    "tag_value": {
        "@@assign": jsonencode(data.opslevel_teams.all.names)
      }
  }
}
}

```

And then use the policy in the resource:

```auto
resource "aws_organizations_policy" "tagging_policy" {
  name = "tags"
  type = "TAG_POLICY"
  content = jsonencode(local.tag_policy)
}

```

I tried many different ways with `for` and `jsonencode` adding this into the @@asign array but still getting the same error. When I manually change the content of that array to something like “test” it works.

Can anyone help me solve this?

If I take the policy above and subsitute the teams list with `["test"]` array I can add that in the console.

```auto
{
  "tags": {
    "team": {
      "tag_key": {
        "@@assign": "team"
      },
      "tag_value": {
        "@@assign": [
          "test"
        ]
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![jan-ludvik](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/jan-ludvik/32/23270_2.png) [@jan-ludvik](https://discuss.hashicorp.com/u/jan-ludvik)\
**Post date:** [November 12, 2021, 10:48am UTC](https://discuss.hashicorp.com/t/jsonencode-with-aws-tag-policy/31831/2 "2021-11-12T10:48:02Z")

</div>

I figured it out. The problem is that some of our company teams have `&` and `,` in their names so it’s a problem of allowed characters in tag values and not very informative AWS error message.
