Skip to content

Commit 52f4f79

Browse files
More info on compute ID mapping error (#2490)
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.
2 parents b9dfc43 + 910ad18 commit 52f4f79

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

docs/resource-ids.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,22 @@ If the type of the `"id"` attribute is not coercible to a string, you must set `
6060
error: Resource test_res has a problem: no "id" attribute. To map this resource consider specifying ResourceInfo.ComputeID
6161
```
6262

63-
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:
63+
If the resource simply doesn't have an `"id"` attribute, you will need to set `ResourceInfo.ComputeID`.
64+
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.
65+
66+
```go
67+
"test_res": {ComputeID: tfbridge.DelegateIDField("id", "testprovider", "https://github.com/pulumi/pulumi-testprovider")}
68+
```
69+
70+
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",
71+
you may need to map this field to something else:
72+
73+
```go
74+
"test_res": {ComputeID: tfbridge.DelegateIDField("valid_key", "testprovider", "https://github.com/pulumi/pulumi-testprovider")}
75+
```
76+
77+
78+
Otherwise you can pass in any function that complies with:
6479

6580
```go
6681
func(ctx context.Context, state resource.PropertyMap) (resource.ID, error)

pkg/pf/internal/check/check_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func TestMissingIDProperty(t *testing.T) {
100100
})
101101

102102
assert.Equal(t, "error: Resource test_res has a problem: no \"id\" attribute. "+
103-
"To map this resource consider specifying ResourceInfo.ComputeID\n", stderr)
103+
"To map this resource consider specifying ResourceInfo.ComputeID to a valid field on the upstream resource\n", stderr)
104104

105105
assert.ErrorContains(t, err, "There were 1 unresolved ID mapping errors")
106106
}

pkg/pf/internal/check/checks.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func (err errWrongIDType) Error() string {
126126
type errMissingIDAttribute struct{}
127127

128128
func (errMissingIDAttribute) Error() string {
129-
return `no "id" attribute. To map this resource consider specifying ResourceInfo.ComputeID`
129+
return `no "id" attribute. To map this resource consider specifying ResourceInfo.ComputeID to a valid field on the upstream resource`
130130
}
131131

132132
type errInvalidRequiredID struct{}

0 commit comments

Comments
 (0)