Skip to content
This repository was archived by the owner on Jun 27, 2021. It is now read-only.
This repository was archived by the owner on Jun 27, 2021. It is now read-only.

whitespace changes in a formatted JSON string #172

@anton-yurchenko

Description

@anton-yurchenko

Hello @DeviaVir,
First of all, thanks for a great provider here! 👑

I have encountered an issue deploying a resource with a JSON string.

The problem arises when a string is provided in a formatted way, like this:

resource "gsuite_user_attributes" "tonys_permit" {
  primary_email = "tony.stark@avengers.com"

  custom_schema {
    name  = "PERMIT"
    value = <<EOF
{
    "Role": [
        {
            "type": "work",
            "value": "aaa"
        },
        {
            "type": "work",
            "value": "bbb"
        }
    ],
    "SessionDuration": "ccc"
}
EOF
  }
}

Terraform seems to be asserting hashes of the content and the API response because it will constantly complain about whitespace and recommend updating the resource:

Terraform will perform the following actions:

  # gsuite_user_attributes.test will be updated in-place
  ~ resource "gsuite_user_attributes" "tonys_permit" {
        id            = "111111111111111111111"
        primary_email = "tony.stark@avengers.com"

      ~ custom_schema {
            name  = "PERMIT"
          ~ value = jsonencode( # whitespace changes
                {
                    Role            = [
                        {
                            type  = "work"
                            value = "aaa"
                        },
                        {
                            type  = "work"
                            value = "bbb"
                        },
                    ]
                    SessionDuration = "ccc"
                }
            )
        }
    }

Plan: 0 to add, 1 to change, 0 to destroy.

I was able to workaround that issue by updating my resource:

resource "gsuite_user_attributes" "tonys_permit" {
  primary_email = "tony.stark@avengers.com"

  custom_schema {
    name  = "PERMIT"
    value = "{\"Role\":[{\"type\":\"work\",\"value\":\"aaa\"},{\"type\":\"work\",\"value\":\"bbb\"}],\"SessionDuration\":\"ccc\"}"
  }
}

But a more suitable solution was ofcourse using the jsonencode:

resource "gsuite_user_attributes" "tonys_permit" {
  primary_email = "tony.stark@avengers.com"

  custom_schema {
    name  = "PERMIT"
    value = jsonencode({
      Role=[
        {
          type="work",
          value="aaa"
        },
        {
          type="work",
          value="bbb"
        }
      ],
      SessionDuration="ccc"
    })
  }
}

Not sure whether it's something that might or even needed to be fixed on a provider level, so feel free to close this issue.

In any case, this is something that might be useful to be noted in the documentation, and of course, this issue here might help others to solve a similar problem 😉

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions