Skip to content

Make IdentitySchema Attributes Available as Resource References #1244

@miton18

Description

@miton18

Feature Request: Make IdentitySchema Attributes Available as Resource References

Current Behavior

When a resource defines an id attribute only in the IdentitySchema (via resource.ResourceWithIdentity interface), this attribute is not available for reference by other resources in Terraform configurations.

Example:

// Resource with IdentitySchema only
func (r *ResourceKubernetes) IdentitySchema(ctx context.Context, req resource.IdentitySchemaRequest, res *resource.IdentitySchemaResponse) {
    res.IdentitySchema = identityschema.Schema{
        Attributes: map[string]identityschema.Attribute{
            "id": identityschema.StringAttribute{RequiredForImport: true},
        },
    }
}

func (r ResourceR) Schema(_ context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
    resp.Schema = schema.Schema{
        Attributes: map[string]schema.Attribute{
            "name":       schema.StringAttribute{Required: true},
            // Note: no "id" attribute here
        },
    }
}

Attempted Usage:

resource "clevercloud_s" "nodes" {
  kubernetes_id = clevercloud_r.cluster.id  # ❌ Error: Unsupported attribute
  name          = "worker-nodes"
  flavor        = "XS"
  size          = 3
}

Error:

Error: Unsupported attribute

  on terraform_plugin_test.tf line 20, in resource "clevercloud_s":
  20:   kubernetes_id = "${clevercloud_r.cluster.id}"

This object does not have an attribute named "id".

Expected Behavior

Attributes defined in IdentitySchema should be automatically available as computed attributes in the resource's main schema, allowing them to be referenced by other resources without requiring manual duplication.

Current Workaround

Currently, providers must manually duplicate the id attribute in both schemas:

func (r ResourceR) Schema(_ context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
    resp.Schema = schema.Schema{
        Attributes: map[string]schema.Attribute{
            "id":         schema.StringAttribute{Computed: true, PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()}},
            "name":       schema.StringAttribute{Required: true},
            "kubeconfig": schema.StringAttribute{Computed: true},
        },
    }
}

func (r *ResourceR) IdentitySchema(ctx context.Context, req resource.IdentitySchemaRequest, res *resource.IdentitySchemaResponse) {
    res.IdentitySchema = identityschema.Schema{
        Attributes: map[string]identityschema.Attribute{
            "id": identityschema.StringAttribute{RequiredForImport: true},
        },
    }
}

This creates unnecessary duplication and potential for inconsistency between the two schemas.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions