-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #352
- Loading branch information
Showing
2 changed files
with
117 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Resource IDs | ||
|
||
Every Pulumi resource must have an `"id"` field. `"id"` must be a string, and it must be | ||
set by the provider (`Computed` and *not* `Optional` in Terraform parlance). | ||
|
||
## SDKv1 and SDKv2 Based Providers | ||
|
||
The ID requirement is easy to satisfy for SDKv{1,2} based providers since both SDKs | ||
require an ID field of type string set on the provider. If the provider being bridged is | ||
based on SDKv1 or SDKv2, then the bridge handles Pulumi's ID field without intervention. | ||
|
||
## PF Based Providers | ||
|
||
Most PF based providers have an attribute called `"id"` of the right kind for the bridge | ||
to use. If your provider doesn't, then you will see an error when `make tfgen` is | ||
run. Each error has a different kind of resolution. | ||
|
||
### ID of the wrong type | ||
``` | ||
error: Resource dnsimple_email_forward has a problem: "id" attribute is of type "int", expected type "string". To map this resource consider overriding the SchemaInfo.Type field or specifying ResourceInfo.ComputeID. | ||
``` | ||
|
||
This error happens when the upstream resource has an ID but it's not a string. You can fix | ||
it by setting the `SchemaInfo.Type` override for the `"id"` field: | ||
|
||
```go | ||
"dnsimple_email_forward": { | ||
Fields: map[string]*tfbridge.SchemaInfo{ | ||
"id": {Type: "string"}, | ||
}, | ||
}, | ||
``` | ||
|
||
|
||
For providers[^1] where every resource's ID has the wrong type, you can use a `for` loop to apply this: | ||
|
||
```go | ||
prov.P.ResourcesMap().Range(func(key string, value shim.Resource) bool { | ||
if value.Schema().Get("id").Type() != shim.TypeString { | ||
r := prov.Resources[key] | ||
if r.Fields == nil { | ||
r.Fields = make(map[string]*tfbridge.SchemaInfo, 1) | ||
} | ||
r.Fields["id"] = &tfbridge.SchemaInfo{Type: "string"} | ||
} | ||
return true | ||
}) | ||
``` | ||
|
||
|
||
[^1]: https://github.com/pulumi/pulumi-dnsimple/blob/7d7e5f3d88082306f15c3600f3481516ae19454a/provider/resources.go#L126-L140 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters