DeviaVir / terraform-provider-gsuite

A @HashiCorp Terraform provider for managing G Suite resources.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`whitespace changes` in a formatted JSON string

anton-yurchenko opened this issue Β· comments

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 πŸ˜‰