Skip to content

Commit 8756d9c

Browse files
jun-kagawaclaude
andauthored
fix: set parent attribute during IAM policy import (#184)
When importing a project-level IAM policy (e.g., `import { id = "projects/foo" }`), `ImportStatePassthroughContext` only sets `d.SetId()` but not the `parent` attribute. The Read function (`dataSourceIAMPolicyRead`) uses `d.Get("parent")` to determine which resource to fetch. Since `parent` is empty, `ResolveWorkspaceParent` falls back to the workspace, causing all project IAM policy imports to incorrectly read the workspace IAM policy instead. This fix replaces `ImportStatePassthroughContext` with a custom import function that sets the `parent` attribute from the import ID before the Read function is called. Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent a861c53 commit 8756d9c

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

provider/resource_iam_policy.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ func resourceIAMPolicy() *schema.Resource {
2626
UpdateContext: resourceIAMPolicyUpsert,
2727
DeleteContext: resourceIAMPolicyDelete,
2828
Importer: &schema.ResourceImporter{
29-
StateContext: schema.ImportStatePassthroughContext,
29+
StateContext: func(ctx context.Context, d *schema.ResourceData, m interface{}) ([]*schema.ResourceData, error) {
30+
if err := d.Set("parent", d.Id()); err != nil {
31+
return nil, err
32+
}
33+
return []*schema.ResourceData{d}, nil
34+
},
3035
},
3136
Schema: map[string]*schema.Schema{
3237
"parent": {

0 commit comments

Comments
 (0)