Skip to content

Conversation

@h3adex
Copy link
Contributor

@h3adex h3adex commented Nov 14, 2025

Description

This PR refactors stackit_authorization_{project,folder,organization}_role_assignment resources 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:
Screenshot 2025-11-14 at 11 09 06

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:

locals {
  org_id      = "xxxx"
  owner_email = "terraform-xxxx@sa.stackit.cloud"
}

resource "stackit_resourcemanager_folder" "folder" {
  parent_container_id = local.org_id
  name                = "e2e-test-folder"
  owner_email         = local.owner_email
}

resource "stackit_resourcemanager_project" "project" {
  parent_container_id = local.org_id
  name                = "e2e-test-folder"
  owner_email         = local.owner_email
}

resource "stackit_authorization_folder_role_assignment" "fra" {
  resource_id = stackit_resourcemanager_folder.folder.folder_id
  role        = "editor"
  subject     = local.owner_email
}

resource "stackit_authorization_folder_role_assignment" "fra_duplicate" {
  resource_id = stackit_resourcemanager_folder.folder.folder_id
  role        = "editor"
  subject     = local.owner_email
}

resource "stackit_authorization_project_role_assignment" "pra" {
  resource_id = stackit_resourcemanager_project.project.project_id
  role        = "reader"
  subject     = local.owner_email
}

resource "stackit_authorization_organization_role_assignment" "ora" {
  resource_id = local.org_id
  role        = "iaas.project.admin"
  subject     = local.owner_email
}

Checklist

  • Issue was linked above
  • Code format was applied: make fmt
  • Examples were added / adjusted (see examples/ directory)
  • Docs are up-to-date: make generate-docs (will be checked by CI)
  • Unit tests got implemented or updated
  • Acceptance tests got implemented or updated (see e.g. here)
  • Unit tests are passing: make test (will be checked by CI)
  • No linter issues: make lint (will be checked by CI)

@h3adex h3adex requested a review from a team as a code owner November 14, 2025 10:18
@h3adex h3adex changed the title feat(authorization): implement folder_role_assignment resource feat(authorization): refactor and implement folder for role_assignment resource Nov 14, 2025
@h3adex h3adex force-pushed the feat/implement-folder-role-assignments branch 3 times, most recently from e8415a6 to 5634558 Compare November 14, 2025 11:27
@h3adex h3adex changed the title feat(authorization): refactor and implement folder for role_assignment resource feat(authorization): refactor role_assignment resource and implement folder assignment Nov 14, 2025
@github-actions
Copy link

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.

@github-actions github-actions bot added the Stale PR is marked as stale due to inactivity. label Nov 25, 2025
@rubenhoenle rubenhoenle removed the Stale PR is marked as stale due to inactivity. label Nov 25, 2025
@h3adex h3adex force-pushed the feat/implement-folder-role-assignments branch from 5634558 to 977ef73 Compare December 2, 2025 07:52
@github-actions
Copy link

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.

@github-actions github-actions bot added the Stale PR is marked as stale due to inactivity. label Dec 10, 2025
@rubenhoenle rubenhoenle removed the Stale PR is marked as stale due to inactivity. label Dec 16, 2025
Signed-off-by: Mauritz Uphoff <mauritz.uphoff@stackit.cloud>
@h3adex h3adex force-pushed the feat/implement-folder-role-assignments branch from 977ef73 to 8307a83 Compare January 21, 2026 12:33
@h3adex h3adex requested a review from GokceGK January 21, 2026 12:39
return errRoleAssignmentNotFound
}

// Prevent creating duplicate <resource_id, role, subject> assignments.
Copy link
Contributor Author

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>
@h3adex h3adex force-pushed the feat/implement-folder-role-assignments branch from 8307a83 to cad266e Compare January 21, 2026 12:41
Signed-off-by: Mauritz Uphoff <mauritz.uphoff@stackit.cloud>
@h3adex h3adex force-pushed the feat/implement-folder-role-assignments branch from 9078ee6 to 2b60ff8 Compare January 21, 2026 13:33
marceljk
marceljk previously approved these changes Jan 23, 2026
Copy link
Contributor

@marceljk marceljk 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 contribution! Looks good to me!

@h3adex
Copy link
Contributor Author

h3adex commented Jan 23, 2026

Once merged we can close this issue: #1089

@marceljk
Copy link
Contributor

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:

err = mapListMembersResponse(listResp, &model)
if err != nil {
core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading authorization", fmt.Sprintf("Processing API payload: %v", err))
return
}

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

imageResp, err := r.client.GetImage(ctx, projectId, region, imageId).Execute()
if err != nil {
oapiErr, ok := err.(*oapierror.GenericOpenAPIError) //nolint:errorlint //complaining that error.As should be used to catch wrapped errors, but this error should not be wrapped
if ok && oapiErr.StatusCode == http.StatusNotFound {
resp.State.RemoveResource(ctx)
return
}
core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading image", fmt.Sprintf("Calling API: %v", err))
return
}

@h3adex h3adex force-pushed the feat/implement-folder-role-assignments branch 4 times, most recently from ed61995 to 3839c65 Compare January 23, 2026 15:01
Signed-off-by: Mauritz Uphoff <mauritz.uphoff@stackit.cloud>
@h3adex h3adex force-pushed the feat/implement-folder-role-assignments branch from 3839c65 to b3bb1a5 Compare January 23, 2026 15:03
Signed-off-by: Mauritz Uphoff <mauritz.uphoff@stackit.cloud>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants