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

feat: Add postgresql_security_label resource #482

Merged
merged 8 commits into from
Oct 30, 2024

Conversation

stanleyz
Copy link
Contributor

@stanleyz stanleyz commented Oct 22, 2024

This PR is based on the great job @jbunting did in #365, which fixed the quoted identifier for object name and provider in the pg_seclabels table.

Additional changes:

  1. Update the doc to explain the import process

@stanleyz stanleyz force-pushed the feat/security-label branch 2 times, most recently from 14b7748 to ad70419 Compare October 22, 2024 10:01
@stanleyz
Copy link
Contributor Author

@cyrilgdn can you please take a look? Thanks.

@cyrilgdn
Copy link
Owner

Hi @stanleyz ,

Can't you push in @jbunting PR directly? (it's possible if the PR author allowed it)

Update main.go to add -debug option

Could you create a specific PR for that so we don't mix unrelated stuff 🙏 ?

@stanleyz stanleyz force-pushed the feat/security-label branch from 25db301 to ab06076 Compare October 22, 2024 20:21
@stanleyz
Copy link
Contributor Author

stanleyz commented Oct 22, 2024

Can't you push in @jbunting PR directly? (it's possible if the PR author allowed it)

I tried to get the communication going in the original PR #365 but didn't see @jbunting responding, hence this PR.

Saying that however, this PR is based on and cherry-picked from the work @jbunting did in #365, so we are co-authored for this PR effectively.

Could you create a specific PR for that so we don't mix unrelated stuff 🙏 ?

Cool, I have removed that change from this PR, please take a look. Thanks.

@jbunting
Copy link
Contributor

Sorry I haven't really had time to get back to this. I'm happy to change my pr to let you edit it (how?), or just close it out, whatever is easier.

@stanleyz
Copy link
Contributor Author

Sorry I haven't really had time to get back to this. I'm happy to change my pr to let you edit it (how?), or just close it out, whatever is easier.

I'd suggest we close the previous one #365 and just use this one since the work is mostly done already.

@stanleyz stanleyz force-pushed the feat/security-label branch from ab06076 to ca97be0 Compare October 24, 2024 06:01
@stanleyz
Copy link
Contributor Author

@cyrilgdn can you please make it to the main if no issues found? Thanks.

The branch quickly turns out of data, I clicked on rebase which requires the checks to run again.

@cyrilgdn
Copy link
Owner

@cyrilgdn can you please make it to the main if no issues found? Thanks.

The branch quickly turns out of data, I clicked on rebase which requires the checks to run again.

I started the review yesterday but it takes time and I have a job too 😅 , so please be patient 🙏

@martindz
Copy link

thank you, guys, for your work and commitment.

@stanleyz
Copy link
Contributor Author

@cyrilgdn can you please make it to the main if no issues found? Thanks.
The branch quickly turns out of data, I clicked on rebase which requires the checks to run again.

I started the review yesterday but it takes time and I have a job too 😅 , so please be patient 🙏

Even as powerful as @cyrilgdn, you still need a job, I don't believe it, must be a lie 😅

Copy link
Owner

@cyrilgdn cyrilgdn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your work 💪 , some minor comments/questions but otherwise 👍

postgresql/resource_postgresql_security_label.go Outdated Show resolved Hide resolved
postgresql/resource_postgresql_security_label.go Outdated Show resolved Hide resolved
postgresql/resource_postgresql_security_label.go Outdated Show resolved Hide resolved
row := db.QueryRow(query, objectType, quoteIdentifier(objectName), quoteIdentifier(provider))

var label string
err = row.Scan(&objectType, &provider, &label)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a point to scan objectType and provider as you use them in the filters of the request?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is Read function right, I believe the point of the Read function in Terraform providers is to re-conciliate the state values with the actual value in the remote system, so yes, it's good to read and update the local.

I didn't include the objname in the scan because of the difficulties involved with handling the quote_ident, I probably should still do that, will push new commit to change this.

@stanleyz stanleyz force-pushed the feat/security-label branch from 5d30436 to 4f1956f Compare October 25, 2024 05:19
@stanleyz
Copy link
Contributor Author

Thanks @cyrilgdn for the review, have updated with the below, please take a look, thanks.

  1. Revert the if err := resourcePostgreSQLSecurityLabelUpdateImpl(db, d, pq.QuoteLiteral(label)); err != nil { in the resourcePostgreSQLSecurityLabelCreate function
  2. Add block to resourcePostgreSQLSecurityLabelReadImpl to check whether objname and provider are in sync with the remote system.

@cyrilgdn
Copy link
Owner

cyrilgdn commented Oct 25, 2024

The failing tests are unrelated to your PR, I'll have a look

actually it's related, cf #482 (comment)

tests/build/Dockerfile Show resolved Hide resolved
Copy link
Owner

@cyrilgdn cyrilgdn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't bother with the failing test on version 11, I was planning to remove this version from the tests as it's not supported by Postgres anymore.

@stanleyz
Copy link
Contributor Author

Last question, why not quoteIdentifier everything to simplify (and avoid the need of this function)?

Adding quote to identifiers that doesn't have special characters is a no-op operation, PostgreSQL will remove the quote before persistence, for example "test_role" is saved as test_role, but "test-role" is saved as "test-role"

@cyrilgdn
Copy link
Owner

Last question, why not quoteIdentifier everything to simplify (and avoid the need of this function)?

Adding quote to identifiers that doesn't have special characters is a no-op operation, PostgreSQL will remove the quote before persistence, for example "test_role" is saved as test_role, but "test-role" is saved as "test-role"

Thanks, it's clear 👍 Weird behavior from Postgres side though as it does not behave similarly for other resources but it's cool you handle it properly!

Copy link
Owner

@cyrilgdn cyrilgdn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for your work @jbunting and @stanleyz 👏 💪

It will be release in the next days.

@cyrilgdn cyrilgdn merged commit b202448 into cyrilgdn:main Oct 30, 2024
6 checks passed
@stanleyz stanleyz deleted the feat/security-label branch October 30, 2024 20:45
@stanleyz
Copy link
Contributor Author

Thanks a lot for your work @jbunting and @stanleyz 👏 💪

It will be release in the next days.

Great, thanks @cyrilgdn .

@jarpoole
Copy link

@cyrilgdn any chance you could trigger a release when you have a moment?

@binnykmathew-tlnr
Copy link

@cyrilgdn - Nice, if you could make a release of this change, so I can avoid forking it out just to be able to use in my project :)

@martindz
Copy link

Seems it didn't get to last release on 22 Oct. Is there any plan for next one, any eta? Thanks

@cyrilgdn
Copy link
Owner

cyrilgdn commented Dec 5, 2024

@stanleyz @jarpoole @binnykmathew-tlnr @martindz This has just been release in https://github.com/cyrilgdn/terraform-provider-postgresql/releases/tag/v1.25.0

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

Successfully merging this pull request may close these issues.

6 participants