-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
New resource: aws_ssoadmin_customer_managed_policy_attachment #25915
New resource: aws_ssoadmin_customer_managed_policy_attachment #25915
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Welcome @oakbramble 👋
It looks like this is your first Pull Request submission to the Terraform AWS Provider! If you haven’t already done so please make sure you have checked out our CONTRIBUTING guide and FAQ to make sure your contribution is adhering to best practice and has all the necessary elements in place for a successful approval.
Also take a look at our FAQ which details how we prioritize Pull Requests for inclusion.
Thanks again, and welcome to the community! 😃
Ok, I had the tests working, however now I am having trouble attaching multiple policies, both when testing manually and in the acc tests.
It has a conflict when adding or deleting more than one Any advice on how I can make sure these calls are handled properly, so they do not cause conflict, would be much apprecated. Update: I think this was an issue in my environment. Everything is working now and I have tested repeatedly, both manually and the acc tests. |
Tested with your branch and I can reproduce the same error on both additions and deletions. When adding or detaching multiple CMPolicies. This is def a raise condition documented in the code.
The suggested mitigation in the AWS docs is to perform a backoff and retry (https://github.com/aws/aws-sdk-go/blob/ea9ec95e2434772e82b415093f9b660bd849322f/service/ssoadmin/api.go#L92). Initial testing has shown the nicer solution might be to querying ListCustomerManagedPolicyReferencesInPermissionSetInput until the result is returned (or not returned), with some sane limits on the amount of times this would be tried before returning the conflict error to the user.
|
Thanks @csanders-git for taking a look and providing feedback. I have added retry conditions to the create and delete attachment functions (I know you mention a nicer solution, but this is what I could get working). I find that the tests are now consistently passing and with manual testing I can attach and detach multiple customer managed policies at the same time. (Side note: I do wonder why this conflict doesn't seem to be an issue for the AWS managed policy attachments, unless I am missing a different retry logic around them?) Please let me know if there is anything else you see issue with, or if you do not find that this solution for multiple attachments is working. |
The AWS CLI and API docs both use a config block for the I also think we should call it what it is, which is a reference to a policy. Please also make sure in the docs it is clear that in order for this to work, the customer managed policy has to first be present in the account that is getting assigned to the permission set.
This would be more inline with the AWS API docs and be easier to understand and support. Also, doing it with a config block allows for better terraform logic with the ability to use dynamics to find and attach policies only for permission sets that are deployed in accounts where the policies exist. |
@oakbramble thank you so much for working on this, I'll be using the new feature as soon as it's released! I believe I've seen the equivalent issue with AWS managed policy attachments, resulting in timeouts and failure to apply when trying to attach managed policies to large numbers of accounts and groups at the same time via a module. I worked around the issue by adding an otherwise unnecessary |
Thanks for the feedback @nomeelnoj . I had been thinking from a user perspective it would be more readable without a config block, particularly when I have not had much time to look at this today, however have reconfigured to use the config block and tested manually that this is working (basic, multiple policies, force new and delete). I have not sorted the tests or docs yet, but will look at them tomorrow. In the meantime, I have pushed the WIP, just in case there are any further tips forthcoming 😄 (I am getting to grips with the repo/ Go, thank you for bearing with me.) @paulschwarzenberger thanks for the info about the managed policy attachments - I'll watch out for that :) |
internal/service/ssoadmin/customer_managed_policy_attachment.go
Outdated
Show resolved
Hide resolved
website/docs/r/ssoadmin_customer_managed_policy_attachment.html.markdown
Outdated
Show resolved
Hide resolved
Following @nomeelnoj 's comments, there is now a functioning @ColinHarrington thanks for the review. I will look at removing the path default and updating documentation tomorrow morning. |
Ok, docs have been updated and all looks to be in order. To update on the initial post, this is what the final resource looks like:
This is the current output from the acceptance testing:
|
After the pipeline tests were run last week, I had some errors to correct (sorry I did not see all these extra tests in the make file beforehand). Below is summary of the corrections I have made, based on these errors.
In addition to the acc tests, the following are now also passing when I run locally:
I'm having trouble running Please let me know if there are any more concerns, or if there's anything else I should be doing to get this merged. (I know the branch doesn't match the naming convention, but I didn't see this until it was too late; will do better next time.) |
I have retested the latest version of the PR, it works flawlessly. The contribution guidelines indicate that comments are also an important part of prioritizing PRs, so here we go: Let me take a stab at discussing why this is so critical to many orgs. AWS-SSO allows for a proper SCIM based integration with IdP's such as Okta. This is only available in a hacky manner via the IAM SAML integration because it doesn't speak SCIM AND it doesn't provide an OIDC Authorization Server for accessing credentials via the CLI which leads to terrible command line tools to assume roles via CLI. This change, that @oakbramble so quickly added support for, frees up many organizations to migrate to AWS-SSO and GREATLY improve their security posture. |
Going to add another vote here to help prioritise this. Naturally AWS released this feature about 2 weeks after we complete our migration to SSO managed inline policies, but this would still be very useful to us. |
In addition to what @csanders-git mentions, another business need that support for customer managed policies in permission sets is providing flexibility to application owners / developers to directly manage the permissions at the AWS account level without having to modify the centrally defined permission set. For organizations in which an internal shared responsibility model is implemented, this adds agility. |
Please note that many AWS customers were waiting for Amazon to release this feature, and many are now blocked from deploying if they are Terraform customers, even if they don't realize it yet. The inability to manage AWS permissions in Okta via Terraform has been a long-standing pain point, and we're very much looking forward to seeing this feature implemented! |
This is a huge deal for us as we're in the midst of a migration from IAM users to AWS SSO in our org. We can't be fine-grained with the SSO inline policies, and we easily bust the 10KB limits if we try, and this feature appearing when it did would have been excellent had the Terraform provider been updated to support it. This would solve so many problems that I'd say it's desperately needed. |
I am in the same boat as @c0mput3rj0n3s. We are trying to migrate from IAM to AWS SSO and have similar concerns. This terraform resource is badly needed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall the contribution looks great, thanks @oakbramble 👏 . I've left a few comments here and there to make things a bit more clear.
Regarding tests; I seem to be unable to run the tests as I'm getting an access denied exception (something I have to sort out).
Next to the above, I do think that the id we construct isn't that pretty - especially as the terraform import
requires this identifier (TestPolicy,/,arn:aws:sso:::permissionSet/ssoins-2938j0x8920sbj72/ps-80383020jr9302rk,arn:aws:sso:::instance/ssoins-2938j0x8920sbj72
) - What are your thoughts on this? @ewbankkit
I believe that @ewbankkit will perform an additional review before we merge this.
internal/service/ssoadmin/customer_managed_policy_attachment.go
Outdated
Show resolved
Hide resolved
internal/service/ssoadmin/customer_managed_policy_attachment.go
Outdated
Show resolved
Hide resolved
internal/service/ssoadmin/customer_managed_policy_attachment.go
Outdated
Show resolved
Hide resolved
internal/service/ssoadmin/customer_managed_policy_attachment.go
Outdated
Show resolved
Hide resolved
internal/service/ssoadmin/customer_managed_policy_attachment.go
Outdated
Show resolved
Hide resolved
internal/service/ssoadmin/customer_managed_policy_attachment_test.go
Outdated
Show resolved
Hide resolved
website/docs/r/ssoadmin_customer_managed_policy_attachment.html.markdown
Outdated
Show resolved
Hide resolved
Thanks for the comments @bschaatsbergen |
Ok, the semgrep check failed on the last run. I saw that several semgrep changes were merged yesterday and it looks like that was the cause of the failure. I have rebased again to remedy this. As ever, if you think that isn't the case and I have missed something, please let me know. |
…otFound check in Read.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🚀.
% make testacc TESTARGS='-run=TestAccSSOAdminCustomerManagedPolicyAttachment_' PKG=ssoadmin ACCTEST_PARALLELISM=2
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/ssoadmin/... -v -count 1 -parallel 2 -run=TestAccSSOAdminCustomerManagedPolicyAttachment_ -timeout 180m
=== RUN TestAccSSOAdminCustomerManagedPolicyAttachment_basic
=== PAUSE TestAccSSOAdminCustomerManagedPolicyAttachment_basic
=== RUN TestAccSSOAdminCustomerManagedPolicyAttachment_forceNew
=== PAUSE TestAccSSOAdminCustomerManagedPolicyAttachment_forceNew
=== RUN TestAccSSOAdminCustomerManagedPolicyAttachment_disappears
--- PASS: TestAccSSOAdminCustomerManagedPolicyAttachment_disappears (29.85s)
=== RUN TestAccSSOAdminCustomerManagedPolicyAttachment_Disappears_permissionSet
--- PASS: TestAccSSOAdminCustomerManagedPolicyAttachment_Disappears_permissionSet (20.95s)
=== RUN TestAccSSOAdminCustomerManagedPolicyAttachment_multipleManagedPolicies
=== PAUSE TestAccSSOAdminCustomerManagedPolicyAttachment_multipleManagedPolicies
=== CONT TestAccSSOAdminCustomerManagedPolicyAttachment_basic
=== CONT TestAccSSOAdminCustomerManagedPolicyAttachment_multipleManagedPolicies
--- PASS: TestAccSSOAdminCustomerManagedPolicyAttachment_basic (32.87s)
=== CONT TestAccSSOAdminCustomerManagedPolicyAttachment_forceNew
--- PASS: TestAccSSOAdminCustomerManagedPolicyAttachment_multipleManagedPolicies (52.84s)
--- PASS: TestAccSSOAdminCustomerManagedPolicyAttachment_forceNew (56.37s)
PASS
ok github.com/hashicorp/terraform-provider-aws/internal/service/ssoadmin 143.892s
Nice work @oakbramble 👍 |
This functionality has been released in v4.30.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you! |
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
Community Note
Closes #25904.
Closes #26068.
This is my first contribution and first time working with Go, so thank you in advance for your feedback.
I have added
aws_ssoadmin_customer_managed_policy_attachment
and manually tested that it is working, creating the following resource:I based the acceptance tests on
managed_policy_attachment_test.go
. They are passing (see below), however there are a couple of areas I am unsure about:testAccCheckCustomerManagedPolicyAttachmentDestroy
?Update: The tests are working and all resources being destroyed properly. I have marked the PR ready for review
Thanks for bearing with me as I get used to the repo and I hope this PR is helpful.
Output from acceptance testing: