From 4e39b75286fb29456f7cf460e99ca6974d446c27 Mon Sep 17 00:00:00 2001 From: guineveresaenger Date: Wed, 16 Oct 2024 12:47:41 -0700 Subject: [PATCH 1/2] Add info to compute ID mapping error, adjust test, and add to doc --- docs/resource-ids.md | 16 +++++++++++++++- pkg/pf/internal/check/check_test.go | 2 +- pkg/pf/internal/check/checks.go | 2 +- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/docs/resource-ids.md b/docs/resource-ids.md index f9b5a073e..8a3fb386c 100644 --- a/docs/resource-ids.md +++ b/docs/resource-ids.md @@ -60,7 +60,21 @@ 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`. + +```go +"test_res": {ComputeID: computeIDField("id")} +``` + +Note that the computeIDField 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: computeIDField("valid_key")} +``` + +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: ```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{} From 910ad18946b3f9eb9ecca5a1e03e1cbfb00f872e Mon Sep 17 00:00:00 2001 From: guineveresaenger Date: Wed, 16 Oct 2024 14:16:21 -0700 Subject: [PATCH 2/2] use bridge functions in doc --- docs/resource-ids.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/docs/resource-ids.md b/docs/resource-ids.md index 8a3fb386c..342df5326 100644 --- a/docs/resource-ids.md +++ b/docs/resource-ids.md @@ -60,20 +60,21 @@ 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 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: computeIDField("id")} +"test_res": {ComputeID: tfbridge.DelegateIDField("id", "testprovider", "https://github.com/pulumi/pulumi-testprovider")} ``` -Note that the computeIDField needs to be a valid property, i.e. if the mapped resource does not have a field called "id", +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: computeIDField("valid_key")} +"test_res": {ComputeID: tfbridge.DelegateIDField("valid_key", "testprovider", "https://github.com/pulumi/pulumi-testprovider")} ``` -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: ```go