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

whitespace changes in a formatted JSON string #172

Open
anton-yurchenko opened this issue Apr 18, 2021 · 0 comments
Open

whitespace changes in a formatted JSON string #172

anton-yurchenko opened this issue Apr 18, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@anton-yurchenko
Copy link
Contributor

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 = "[email protected]"

  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 = "[email protected]"

      ~ 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 = "[email protected]"

  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 = "[email protected]"

  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 😉

@DeviaVir DeviaVir added the enhancement New feature or request label Apr 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants