diff --git a/docs/resource-ids.md b/docs/resource-ids.md index f9b5a073e..342df5326 100644 --- a/docs/resource-ids.md +++ b/docs/resource-ids.md @@ -60,7 +60,22 @@ If the type of the `"id"` attribute is not coercible to a string, you must set ` error: Resource test_res has a problem: no "id" attribute. To map this resource consider specifying ResourceInfo.ComputeID ``` -If the resource simply doesn't have an `"id"` attribute, you will need to set `ResourceInfo.ComputeID`. If you want to delegate the ID field in Pulumi to another attribute, you should use `tfbridge.DelegateIDField` to produce a `ResourceInfo.ComputeID` compatible function. Otherwise you can pass in any function that complies with: +If the resource simply doesn't have an `"id"` attribute, you will need to set `ResourceInfo.ComputeID`. +If you want to delegate the ID field in Pulumi to another attribute, you should use `tfbridge.DelegateIDField` to produce a `ResourceInfo.ComputeID` compatible function. + +```go +"test_res": {ComputeID: tfbridge.DelegateIDField("id", "testprovider", "https://github.com/pulumi/pulumi-testprovider")} +``` + +Note that the delegated ID field needs to be a valid property, i.e. if the mapped resource does not have a field called "id", +you may need to map this field to something else: + +```go +"test_res": {ComputeID: tfbridge.DelegateIDField("valid_key", "testprovider", "https://github.com/pulumi/pulumi-testprovider")} +``` + + +Otherwise you can pass in any function that complies with: ```go func(ctx context.Context, state resource.PropertyMap) (resource.ID, error) diff --git a/pkg/pf/internal/check/check_test.go b/pkg/pf/internal/check/check_test.go index 548400a92..51d079d9a 100644 --- a/pkg/pf/internal/check/check_test.go +++ b/pkg/pf/internal/check/check_test.go @@ -100,7 +100,7 @@ func TestMissingIDProperty(t *testing.T) { }) assert.Equal(t, "error: Resource test_res has a problem: no \"id\" attribute. "+ - "To map this resource consider specifying ResourceInfo.ComputeID\n", stderr) + "To map this resource consider specifying ResourceInfo.ComputeID to a valid field on the upstream resource\n", stderr) assert.ErrorContains(t, err, "There were 1 unresolved ID mapping errors") } diff --git a/pkg/pf/internal/check/checks.go b/pkg/pf/internal/check/checks.go index 6b8673d08..9a54a6f6a 100644 --- a/pkg/pf/internal/check/checks.go +++ b/pkg/pf/internal/check/checks.go @@ -126,7 +126,7 @@ func (err errWrongIDType) Error() string { type errMissingIDAttribute struct{} func (errMissingIDAttribute) Error() string { - return `no "id" attribute. To map this resource consider specifying ResourceInfo.ComputeID` + return `no "id" attribute. To map this resource consider specifying ResourceInfo.ComputeID to a valid field on the upstream resource` } type errInvalidRequiredID struct{}