-
Notifications
You must be signed in to change notification settings - Fork 48
feat(authorization): refactor role_assignment resource and implement folder assignment #1058
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
base: main
Are you sure you want to change the base?
feat(authorization): refactor role_assignment resource and implement folder assignment #1058
Conversation
e8415a6 to
5634558
Compare
|
This PR was marked as stale after 7 days of inactivity and will be closed after another 7 days of further inactivity. If this PR should be kept open, just add a comment, remove the stale label or push new commits to it. |
5634558 to
977ef73
Compare
|
This PR was marked as stale after 7 days of inactivity and will be closed after another 7 days of further inactivity. If this PR should be kept open, just add a comment, remove the stale label or push new commits to it. |
stackit/internal/services/authorization/testdata/resource-folder-role-assignment.tf
Show resolved
Hide resolved
stackit/internal/services/authorization/testdata/resource-project-role-assignment.tf
Show resolved
Hide resolved
Signed-off-by: Mauritz Uphoff <mauritz.uphoff@stackit.cloud>
977ef73 to
8307a83
Compare
| return errRoleAssignmentNotFound | ||
| } | ||
|
|
||
| // Prevent creating duplicate <resource_id, role, subject> assignments. |
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.
Wrote a comment above the function to keep everyone aware working on this resource
Signed-off-by: Mauritz Uphoff <mauritz.uphoff@stackit.cloud>
8307a83 to
cad266e
Compare
Signed-off-by: Mauritz Uphoff <mauritz.uphoff@stackit.cloud>
9078ee6 to
2b60ff8
Compare
marceljk
left a comment
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.
Thanks for your contribution! Looks good to me!
|
Once merged we can close this issue: #1089 |
|
The check duplicate function has one issue. It doesn't detect duplicates, when they will be created at the same time. I used the testing tf config from you and it created the duplicates without any issues. I think to prevent this is very diffcult and I would leave this for now, like it is. But when I remove one of the duplicates (or even if it was removed via the api directly), my tf state is broken. I get the following error: ╷
│ Error: Error reading authorization
│
│ with stackit_authorization_folder_role_assignment.fra,
│ on main.tf line 37, in resource "stackit_authorization_folder_role_assignment" "fra":
│ 37: resource "stackit_authorization_folder_role_assignment" "fra" {
│
│ Processing API payload: response members did not contain expected role assignment
│ Trace ID: "6881a56e47fd9cfffd39ec403532af48"
╵The error is thrown from here: terraform-provider-stackit/stackit/internal/services/authorization/roleassignments/resource.go Lines 227 to 231 in 2b60ff8
I would suggest, that the error check will be extend to this: if err != nil {
if errors.Is(err, errRoleAssignmentNotFound) {
resp.State.RemoveResource(ctx)
return
}
core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading authorization", fmt.Sprintf("Processing API payload: %v", err))
return
}It's then the same like the 404 check we usually have in the read function terraform-provider-stackit/stackit/internal/services/iaas/image/resource.go Lines 519 to 528 in 459122c
|
ed61995 to
3839c65
Compare
Signed-off-by: Mauritz Uphoff <mauritz.uphoff@stackit.cloud>
3839c65 to
b3bb1a5
Compare
stackit/internal/services/authorization/roleassignments/resource.go
Outdated
Show resolved
Hide resolved
Signed-off-by: Mauritz Uphoff <mauritz.uphoff@stackit.cloud>
Description
This PR refactors
stackit_authorization_{project,folder,organization}_role_assignmentresources to align with our coding standards and adds tests for resource.go and utils.go. It also adds the capability to add role assignments to Folder.E2E Results:

Required ENV:
TF_ACC=1
TF_ACC_REGION=eu01
TF_ACC_ORGANIZATION_ID=xxxx
STACKIT_SERVICE_ACCOUNT_TOKEN=ey..
TF_ACC_TEST_PROJECT_SERVICE_ACCOUNT_EMAIL=terraform-xxxx@sa.stackit.cloud
Manual Tests:
Checklist
make fmtexamples/directory)make generate-docs(will be checked by CI)make test(will be checked by CI)make lint(will be checked by CI)