-
Notifications
You must be signed in to change notification settings - Fork 137
feat(iam): add support for identity #3661
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -8,6 +8,7 @@ import ( | |||||||||
| iam "github.com/scaleway/scaleway-sdk-go/api/iam/v1alpha1" | ||||||||||
| "github.com/scaleway/scaleway-sdk-go/scw" | ||||||||||
| "github.com/scaleway/terraform-provider-scaleway/v2/internal/httperrors" | ||||||||||
| "github.com/scaleway/terraform-provider-scaleway/v2/internal/identity" | ||||||||||
| "github.com/scaleway/terraform-provider-scaleway/v2/internal/services/account" | ||||||||||
| "github.com/scaleway/terraform-provider-scaleway/v2/internal/types" | ||||||||||
| ) | ||||||||||
|
|
@@ -23,6 +24,7 @@ func ResourceApplication() *schema.Resource { | |||||||||
| }, | ||||||||||
| SchemaVersion: 0, | ||||||||||
| SchemaFunc: applicationSchema, | ||||||||||
| Identity: identity.FlatIdentity("id", "Application UUID"), | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
|
|
@@ -79,7 +81,7 @@ func resourceIamApplicationCreate(ctx context.Context, d *schema.ResourceData, m | |||||||||
| return diag.FromErr(err) | ||||||||||
| } | ||||||||||
|
|
||||||||||
| d.SetId(app.ID) | ||||||||||
| err = identity.SetFlatIdentity(d, "id", app.ID) | ||||||||||
|
||||||||||
| err = identity.SetFlatIdentity(d, "id", app.ID) | |
| if err := identity.SetFlatIdentity(d, "id", app.ID); err != nil { | |
| return diag.FromErr(err) | |
| } |
Copilot
AI
Feb 11, 2026
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.
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.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ import ( | |
| iam "github.com/scaleway/scaleway-sdk-go/api/iam/v1alpha1" | ||
| "github.com/scaleway/scaleway-sdk-go/scw" | ||
| "github.com/scaleway/terraform-provider-scaleway/v2/internal/httperrors" | ||
| "github.com/scaleway/terraform-provider-scaleway/v2/internal/identity" | ||
| "github.com/scaleway/terraform-provider-scaleway/v2/internal/services/account" | ||
| "github.com/scaleway/terraform-provider-scaleway/v2/internal/types" | ||
| "github.com/scaleway/terraform-provider-scaleway/v2/internal/verify" | ||
|
|
@@ -24,6 +25,7 @@ func ResourceGroup() *schema.Resource { | |
| }, | ||
| SchemaVersion: 0, | ||
| SchemaFunc: groupSchema, | ||
| Identity: identity.FlatIdentity("id", "Group UUID"), | ||
| } | ||
|
Comment on lines
27
to
29
|
||
| } | ||
|
|
||
|
|
@@ -135,6 +137,12 @@ func resourceIamGroupRead(ctx context.Context, d *schema.ResourceData, m any) di | |
| return diag.FromErr(err) | ||
| } | ||
|
|
||
| setGroupState(d, group) | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func setGroupState(d *schema.ResourceData, group *iam.Group) { | ||
| _ = d.Set("name", group.Name) | ||
| _ = d.Set("description", group.Description) | ||
| _ = d.Set("created_at", types.FlattenTime(group.CreatedAt)) | ||
|
|
@@ -146,8 +154,6 @@ func resourceIamGroupRead(ctx context.Context, d *schema.ResourceData, m any) di | |
| _ = d.Set("user_ids", group.UserIDs) | ||
| _ = d.Set("application_ids", group.ApplicationIDs) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func resourceIamGroupUpdate(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -9,6 +9,7 @@ import ( | |||||
| iam "github.com/scaleway/scaleway-sdk-go/api/iam/v1alpha1" | ||||||
| "github.com/scaleway/scaleway-sdk-go/scw" | ||||||
| "github.com/scaleway/terraform-provider-scaleway/v2/internal/httperrors" | ||||||
| "github.com/scaleway/terraform-provider-scaleway/v2/internal/identity" | ||||||
| "github.com/scaleway/terraform-provider-scaleway/v2/internal/services/account" | ||||||
| "github.com/scaleway/terraform-provider-scaleway/v2/internal/types" | ||||||
| "github.com/scaleway/terraform-provider-scaleway/v2/internal/verify" | ||||||
|
|
@@ -25,6 +26,7 @@ func ResourcePolicy() *schema.Resource { | |||||
| }, | ||||||
| SchemaVersion: 0, | ||||||
| SchemaFunc: policySchema, | ||||||
| Identity: identity.FlatIdentity("id", "Policy UUID"), | ||||||
| } | ||||||
|
Comment on lines
27
to
30
|
||||||
| } | ||||||
|
|
||||||
|
|
@@ -158,7 +160,7 @@ func resourceIamPolicyCreate(ctx context.Context, d *schema.ResourceData, m any) | |||||
| func resourceIamPolicyRead(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { | ||||||
| api := NewAPI(m) | ||||||
|
|
||||||
| pol, err := api.GetPolicy(&iam.GetPolicyRequest{ | ||||||
| policy, err := api.GetPolicy(&iam.GetPolicyRequest{ | ||||||
| PolicyID: d.Id(), | ||||||
| }, scw.WithContext(ctx)) | ||||||
| if err != nil { | ||||||
|
|
@@ -171,38 +173,42 @@ func resourceIamPolicyRead(ctx context.Context, d *schema.ResourceData, m any) d | |||||
| return diag.FromErr(err) | ||||||
| } | ||||||
|
|
||||||
| _ = d.Set("name", pol.Name) | ||||||
| _ = d.Set("description", pol.Description) | ||||||
| _ = d.Set("created_at", types.FlattenTime(pol.CreatedAt)) | ||||||
| _ = d.Set("updated_at", types.FlattenTime(pol.UpdatedAt)) | ||||||
| _ = d.Set("organization_id", pol.OrganizationID) | ||||||
| _ = d.Set("editable", pol.Editable) | ||||||
| _ = d.Set("tags", types.FlattenSliceString(pol.Tags)) | ||||||
|
|
||||||
| if pol.UserID != nil { | ||||||
| _ = d.Set("user_id", types.FlattenStringPtr(pol.UserID)) | ||||||
| rules, err := api.ListRules(&iam.ListRulesRequest{ | ||||||
| PolicyID: policy.ID, | ||||||
| }) | ||||||
|
||||||
| }) | |
| }, scw.WithContext(ctx)) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ import ( | |
| iam "github.com/scaleway/scaleway-sdk-go/api/iam/v1alpha1" | ||
| "github.com/scaleway/scaleway-sdk-go/scw" | ||
| "github.com/scaleway/terraform-provider-scaleway/v2/internal/httperrors" | ||
| "github.com/scaleway/terraform-provider-scaleway/v2/internal/identity" | ||
| "github.com/scaleway/terraform-provider-scaleway/v2/internal/services/account" | ||
| "github.com/scaleway/terraform-provider-scaleway/v2/internal/types" | ||
| "golang.org/x/crypto/ssh" | ||
|
|
@@ -26,6 +27,7 @@ func ResourceSSKKey() *schema.Resource { | |
| }, | ||
| SchemaVersion: 0, | ||
| SchemaFunc: sshKeySchema, | ||
| Identity: identity.FlatIdentity("id", "SSH key UUID"), | ||
| } | ||
|
Comment on lines
29
to
31
|
||
| } | ||
|
|
||
|
|
@@ -110,7 +112,10 @@ func resourceIamSSKKeyCreate(ctx context.Context, d *schema.ResourceData, m any) | |
| } | ||
| } | ||
|
|
||
| d.SetId(res.ID) | ||
| err = identity.SetFlatIdentity(d, "id", res.ID) | ||
| if err != nil { | ||
| return diag.FromErr(err) | ||
| } | ||
|
Comment on lines
+115
to
+118
|
||
|
|
||
| return resourceIamSSHKeyRead(ctx, d, m) | ||
| } | ||
|
|
||
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.
ResourceAPIKeynow declares anIdentityschema, 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.