Skip to content

Commit 4e39b75

Browse files
Add info to compute ID mapping error, adjust test, and add to doc
1 parent b9dfc43 commit 4e39b75

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

docs/resource-ids.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,21 @@ 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+
65+
```go
66+
"test_res": {ComputeID: computeIDField("id")}
67+
```
68+
69+
Note that the computeIDField needs to be a valid property, i.e. if the mapped resource does not have a field called "id",
70+
you may need to map this field to something else:
71+
72+
```go
73+
"test_res": {ComputeID: computeIDField("valid_key")}
74+
```
75+
76+
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.
77+
Otherwise you can pass in any function that complies with:
6478

6579
```go
6680
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)