Skip to content

Data sources for roles #6

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

Closed
dcuenot opened this issue Nov 27, 2020 · 5 comments · Fixed by #4
Closed

Data sources for roles #6

dcuenot opened this issue Nov 27, 2020 · 5 comments · Fixed by #4
Labels
waiting-response Further information is requested

Comments

@dcuenot
Copy link

dcuenot commented Nov 27, 2020

Hi,

First, well done for your provider, it's very useful!
I have a feature request, do you plan to Data sources for existing roles?

Expected code could be like this:

data "postgresql_role" "my_admin" {
  name     = "my_admin"
}

And my expected behaviour is to load an existing role, and to grant new roles to it.

Thanks in advance for your feedback
Regards

Damien

@cyrilgdn
Copy link
Owner

Hi @dcuenot,

What fields would you like to have in this data?

I already had the same thought but at the end, I concluded that I only need the role name (to use in a postgresql_grant for example) and it doesn't make so much sense to load a data with a role name to read its name.
But if you need another role field it could make sense.

@cyrilgdn cyrilgdn added the waiting-response Further information is requested label Nov 28, 2020
@dcuenot
Copy link
Author

dcuenot commented Nov 29, 2020

Hi @cyrilgdn,

Regarding the fields I need in this data, I don't have a clear answer, because I'm not an expert in Terraform.
I will explain my use-case, and maybe it will help you to understand.

In my code, I have a first step to create my Azure PostgreSQL server:

resource "azurerm_postgresql_server" "postgresql" {
  name                = "database-postgresql"
  location            = var.resource-group.location
  resource_group_name = var.resource-group.name

  administrator_login                   = "my-admin"
  administrator_login_password = "my-secret"

  sku_name   = "GP_Gen5_2"
  version    = "11"
  storage_mb = 51200
}

After this creation, I'm creating some roles in this server:

resource "postgresql_role" "admin" {
  name     = "admin"
  login    = false
}
resource "postgresql_role" "materialized_view_owner" {
  name     = "materialized_view_owner"
  login    = false
}

And what I want to do, is to add my-admin into the roles admin & materialized_view_owner.
So to do this, I think I need a data source, in order to modify the roles for my-admin user, but maybe you see another way :)

Thanks in advance for your help
Regards

@cyrilgdn cyrilgdn removed the waiting-response Further information is requested label Nov 30, 2020
@cyrilgdn
Copy link
Owner

@dcuenot

And what I want to do, is to add my-admin into the roles admin & materialized_view_owner.

If you want to GRANT my-admin TO admin, you can just write:

resource "postgresql_role" "admin" {
  name     = "admin"
  login    = false

  roles = [
    "my-admin"
  ]
}

But if you want to GRANT admin TO my-admin, it's currently not possible but will be in the next release (1.9.0) thanks to the work of @dvdliao in #4 .

You'll be able to write:

resource postgresql_grant_role "my_admin" {
  role              = "my-admin"
  grant_role        = "admin
}

@cyrilgdn cyrilgdn added the waiting-response Further information is requested label Dec 12, 2020
@cyrilgdn
Copy link
Owner

@dcuenot FYI, v1.9.0 has just been released with the new postgresql_grant_role resource.

@dcuenot
Copy link
Author

dcuenot commented Dec 31, 2020

I just tested it, and it's working perfectly! Thanks

wilsonjackson referenced this issue in Leafly-com/terraform-provider-postgresql Jan 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting-response Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants