Skip to content

feat(iam): add support for identity#3661

Draft
remyleone wants to merge 1 commit intoscaleway:mainfrom
remyleone:identity_iam
Draft

feat(iam): add support for identity#3661
remyleone wants to merge 1 commit intoscaleway:mainfrom
remyleone:identity_iam

Conversation

@remyleone
Copy link
Copy Markdown
Member

No description provided.

Copilot AI review requested due to automatic review settings February 11, 2026 17:51
@remyleone remyleone requested a review from a team as a code owner February 11, 2026 17:51
@github-actions github-actions Bot added the iam IAM issues, bugs and feature requests label Feb 11, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces Terraform Plugin SDKv2 ResourceIdentity support for several IAM resources, and updates acceptance/unit tests to validate import behavior and identity coverage.

Changes:

  • Add Identity schemas to IAM resources (api key, application, group, policy, SSH key, user) via a new identity.FlatIdentity(...) helper.
  • Update IAM acceptance tests to include ImportState / ImportStateVerify steps.
  • Update the provider-level test that enforces non-nil Resource.Identity across resources.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
provider/sdkv2_test.go Removes IAM resources from the “no identity” exceptions list.
internal/identity/identity.go Adds FlatIdentity helper for single-field identities.
internal/services/iam/application.go Adds identity schema + uses flat identity setter (needs error handling + read-path identity set).
internal/services/iam/api_key.go Adds identity schema + sets flat identity on create (read-path identity set missing).
internal/services/iam/group.go Adds identity schema (but Create/Read still don’t populate identity).
internal/services/iam/policy.go Adds identity schema + refactors read (but identity not populated; ListRules missing ctx).
internal/services/iam/ssh_key.go Adds identity schema + sets flat identity on create (create has ordering bug when disabled is set; read-path identity missing).
internal/services/iam/user.go Adds identity schema + sets flat identity on create/read.
internal/services/iam/*_test.go Adds import verification steps for IAM resources.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

}

d.SetId(app.ID)
err = identity.SetFlatIdentity(d, "id", app.ID)
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

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

identity.SetFlatIdentity can return an error (e.g., if identity support isn't available for this resource data). The returned err is currently ignored, which can leave d.Id() unset and cause the subsequent Read call to query with an empty ID. Handle the error and return diagnostics if it occurs.

Suggested change
err = identity.SetFlatIdentity(d, "id", app.ID)
if err := identity.SetFlatIdentity(d, "id", app.ID); err != nil {
return diag.FromErr(err)
}

Copilot uses AI. Check for mistakes.
Comment on lines 103 to +107
}

setApplicationState(d, app)

return nil
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

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

This resource declares an Identity schema, but the Read path never populates it. Consider calling identity.SetFlatIdentity(d, "id", app.ID) (and handling the error) so imported/refreshed state keeps the identity fields consistent.

Copilot uses AI. Check for mistakes.
_ = d.Set("expires_at", types.FlattenTime(res.ExpiresAt))
_ = d.Set("access_key", res.AccessKey)
setAPIKeyState(d, apiKey)

Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

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

ResourceAPIKey now declares an Identity schema, but the Read path doesn't set it. To keep identity data consistent after refresh/import, set it from the API response (e.g., identity.SetFlatIdentity(d, "id", apiKey.AccessKey)) and handle any error.

Suggested change
if err := identity.SetFlatIdentity(d, "id", apiKey.AccessKey); err != nil {
return diag.FromErr(err)
}

Copilot uses AI. Check for mistakes.
Comment on lines 27 to 30
SchemaVersion: 0,
SchemaFunc: policySchema,
Identity: identity.FlatIdentity("id", "Policy UUID"),
}
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

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

ResourcePolicy declares an Identity schema, but the implementation still uses d.SetId(...) and never sets the identity fields (in Create/Read). To fully support identity-based import/state, use identity.SetFlatIdentity(d, "id", pol.ID) in Create and set it again in Read from the fetched policy, handling any error.

Copilot uses AI. Check for mistakes.
Comment on lines 29 to 31
SchemaFunc: sshKeySchema,
Identity: identity.FlatIdentity("id", "SSH key UUID"),
}
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

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

ResourceSSKKey now declares an Identity schema, but the Read path doesn't populate it. Consider setting the identity in Read (e.g., identity.SetFlatIdentity(d, "id", res.ID)) so the identity fields stay consistent after refresh/import.

Copilot uses AI. Check for mistakes.
Comment on lines 27 to 29
SchemaFunc: groupSchema,
Identity: identity.FlatIdentity("id", "Group UUID"),
}
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

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

ResourceGroup declares an Identity schema, but the implementation still uses d.SetId(...) and does not populate the identity fields (in Create/Read). To actually support identity-based import/state, switch to identity.SetFlatIdentity(d, "id", group.ID) (and similarly in Read) and handle the returned error.

Copilot uses AI. Check for mistakes.
_ = d.Set("user_id", types.FlattenStringPtr(pol.UserID))
rules, err := api.ListRules(&iam.ListRulesRequest{
PolicyID: policy.ID,
})
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

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

api.ListRules is invoked without scw.WithContext(ctx), so request cancellation/timeouts from the Terraform context won't propagate to this API call. Pass the context as a request option, consistent with the other IAM API calls in this function.

Suggested change
})
}, scw.WithContext(ctx))

Copilot uses AI. Check for mistakes.
Comment on lines +115 to +118
err = identity.SetFlatIdentity(d, "id", res.ID)
if err != nil {
return diag.FromErr(err)
}
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

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

When disabled is set during create, the code calls UpdateSSHKey using d.Id() before the ID is assigned (the ID is only set later via identity.SetFlatIdentity). This will send an empty SSHKeyID and fail. Set the ID/identity immediately after CreateSSHKey (or use res.ID directly in the update request) before attempting the update.

Copilot uses AI. Check for mistakes.
Comment thread provider/sdkv2_test.go
"scaleway_iam_ssh_key",
"scaleway_iam_user",
"scaleway_inference_deployment",
"scaleway_inference_model",
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

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

scaleway_iam_group_membership was removed from the exceptions list, but ResourceGroupMembership() currently does not declare Identity (so d.Identity remains nil). This will make TestSDKProvider_ResourceIdentityNotEmpty fail unless group membership gets an Identity schema, or it is re-added to the exceptions list.

Suggested change
"scaleway_inference_model",
"scaleway_inference_model",
"scaleway_iam_group_membership",

Copilot uses AI. Check for mistakes.
@remyleone remyleone deleted the branch scaleway:main February 27, 2026 10:20
@remyleone remyleone closed this Feb 27, 2026
@yfodil yfodil reopened this Feb 27, 2026
@yfodil yfodil changed the base branch from master to main February 27, 2026 10:30
@remyleone remyleone marked this pull request as draft March 12, 2026 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

iam IAM issues, bugs and feature requests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants