Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

postgresql_role incorrectly resets any granted role #285

Open
johnlister opened this issue Feb 23, 2023 · 2 comments
Open

postgresql_role incorrectly resets any granted role #285

johnlister opened this issue Feb 23, 2023 · 2 comments

Comments

@johnlister
Copy link

Hi there,

Thank you for opening an issue. Please provide the following information:

Terraform Version

v1.3.6

Affected Resource(s)

postgresql_role

Terraform Configuration Files

n/a

Debug Output

n/a

Panic Output

n/a

Expected Behavior

Create a role using role using postgresql_role with the roles value missing shouldn't result in existing roles being removed.
It is expected that if the list is optional then no changes are made to roles

Actual Behavior

Running apply a second time, removes all role memberships from the created role as it treats the expected list as empty. Running a third time will reassign all the roles using the explicit grant and so on.

Steps to Reproduce

Create a role using role using postgresql_role with the roles value missing shouldn't result in existing roles being removed.
Manually grant the role membership of another role using postgresql_grant_role. When you run apply the first time, the role is created and granted membership to the second role.
Running apply a subsequent time should not make any changes as the optional list of roles is empty.

Important Factoids

Why is roles an option any way, except as a shortcut? You can manually grant them using postgresql_grant_role. As a minimum the documentation should reflect that you need to use ignore_changes if manually making a role a member of another role.

References

No

@estokes-vs
Copy link

@johnlister i ran into this issue recently as well, and found the documentation indicates to use a Lifecycle mechanism to ignore changes on the role itself. It's goofy as the grant_role should ideally override the role creation declaration but it worked for us.
https://registry.terraform.io/providers/cyrilgdn/postgresql/latest/docs/resources/postgresql_grant_role#usage

  lifecycle {
    ignore_changes = [
      roles,
    ]
  }

@johnlister
Copy link
Author

I ended up using the lifecycle to skip changes, but wouldn't expect it to treat a missing list as an empty list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants