Skip to content

Commit

Permalink
More info on compute ID mapping error (#2490)
Browse files Browse the repository at this point in the history
This is a papercut tweak to remind provider maintainers on what to do
for ComputeID mapping errors.

I'm happy if we don't take this; but it confused me in a recent upgrade
so I thought I'd address it.
  • Loading branch information
guineveresaenger authored Oct 16, 2024
2 parents b9dfc43 + 910ad18 commit 52f4f79
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
17 changes: 16 additions & 1 deletion docs/resource-ids.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/pf/internal/check/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/pf/internal/check/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down

0 comments on commit 52f4f79

Please sign in to comment.