-
Notifications
You must be signed in to change notification settings - Fork 200
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
Add new resource to support ALTER ROLE #211
base: main
Are you sure you want to change the base?
Add new resource to support ALTER ROLE #211
Conversation
4202967
to
65eb45c
Compare
Sorry to bump this, but is this good to merge and release @cyrilgdn ? |
same question to @cyrilgdn , any chance to have such feature ? |
@robinjhector the CI tests are failing. |
@bmedlock-depop The test are failing because the test setup run them both as a superuser role and a less privileged roles. This can be fixed by adding the following line to the top of the test that require superuser access: |
@jenrik Thanks for the help! I should have time this week to fix this. |
@cyrilgdn Tests should now be passing. Thanks for your patience, everyone! |
@cyrilgdn can you please take a look on this request ? ;) |
@cyrilgdn I've just fixed the conflicts on the branch. Everything should be good. Please could you take look? |
This proposed resource is inconsistent with the declarative model of Terraform. A resource is a thing, not an operation. The resource is the role, and this resource already exists ( The right way to implement this would be to add configuration parameter support to In the Terraform configuration, that would look something like: resource "postgresql_role" "foo" {
name = "foo"
parameter {
name = "pgaudit.log"
value = "all"
}
} |
I completely agree, however, sometimes the role was created by a different terraform provider that does not provide the ability to make the necessary changes. See #234 |
Having the same with google_sql_user resources which I need to ALTER. A more declarative resource approach could be to restrict the ALTER ROLE to configuration parameters and call the resource "postgresql_role_configuration_parameter", the thing to be created being the configuration parameter on the role. This essentially leads to #305 Edit in response to @jbg: google_sql_user is explicitly created, but falls in the same 'at mercy' category as mentioned by @rowanmoul |
Generally you'd deal with this by importing the implicitly-created resource after the other provider has created it, after which you can deal with it declaratively like normal. This has been improved recently with the addition of import blocks, though there is still work to do there. |
I understand the concern and agree in principle, but I don't see an inconsistency with this proposed PR, perhaps the naming of the resource can be better. In fact, if you look at the parameters for This is very similar to how we have @bmedlock-depop My suggestion would be to call this resource I think this PR is the simpler and more flexible solution relative to the other proposal of adding this in-line to the |
For special permissions like CREATEROLE, CREATEDB, etc the following doesnt work. Would it be possible to get some special case queries for these. i.e. func createAlterRoleQuery(d *schema.ResourceData) string {
alterRole, _ := d.Get("role_name").(string)
alterParameterKey, _ := d.Get("parameter_key").(string)
alterParameterValue, _ := d.Get("parameter_value").(string)
query := fmt.Sprintf(
"ALTER ROLE %s SET %s TO %s",
pq.QuoteIdentifier(alterRole),
pq.QuoteIdentifier(alterParameterKey),
pq.QuoteIdentifier(alterParameterValue),
)
switch key := strings.ToUpper(alterParameterKey); key {
case "SUPERUSER",
"CREATEDB",
"CREATEROLE",
"INHERIT",
"LOGIN",
"REPLICATION",
"BYPASSRLS":
query = fmt.Sprintf("ALTER ROLE %s %s", pq.QuoteIdentifier(alterRole), key)
}
return query
}
func createResetAlterRoleQuery(d *schema.ResourceData) string {
alterRole, _ := d.Get("role_name").(string)
alterParameterKey, _ := d.Get("parameter_key").(string)
query := fmt.Sprintf(
"ALTER ROLE %s RESET %s",
pq.QuoteIdentifier(alterRole),
pq.QuoteIdentifier(alterParameterKey),
)
switch key := strings.ToUpper(alterParameterKey); key {
case "SUPERUSER",
"CREATEDB",
"CREATEROLE",
"INHERIT",
"LOGIN",
"REPLICATION",
"BYPASSRLS":
query = fmt.Sprintf("ALTER ROLE %s NO%s", pq.QuoteIdentifier(alterRole), key)
}
return query
} |
Taken from cyrilgdn#211
f2c2e47
to
dea1401
Compare
This change will add in a new resource to the provider,
ALTER_ROLE
.The resource is designed to be used where you need to alter certain attributes on a role. For example, when setting attributes associated with PGAudit,
ALTER ROLE testrole SET pgaudit.log to 'all'
Closes #210