Reputation: 11615
I'm writing a provider for terraform to interface with an API, here's the resource schema I have:
&schema.Resource{
Create: resourceProjectCreate,
Read: resourceProjectRead,
Update: resourceProjectUpdate,
Delete: resourceProjectDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
CustomizeDiff: customdiff.Sequence(
customdiff.ComputedIf("slug", func(d *schema.ResourceDiff, meta interface{}) bool {
return d.HasChange("name")
}),
),
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validateName,
},
"description": {
Type: schema.TypeString,
Optional: true,
},
"issueManagementEnabled": {
Type: schema.TypeBool,
Required: true,
},
"forkedFromId": {
Type: schema.TypeInt,
Required: false,
},
},
}
There are no compile or install errors with go install
, and I'm trying this out locally, so I've set up my .terraformrc
to point to my go bin folder.
Terraform seemingly finds an id somewhere, and complains:
Error: Internal validation of the provider failed! This is always a bug
with the provider itself, and not a user issue. Please report
this bug:
1 error occurred:
* resource onedev_project: id is a reserved field name
The code is here https://github.com/UbiquitousBear/terraform-provider-onedev. Does anyone know where I should be removing the reference to id
? It's not in the resource schema.
Upvotes: 1
Views: 215
Reputation: 1
There's one workaround for this issue without upgrading to SDK v2, you can try to give other name like "id1" instead of "id" on you schema like
"id1": {
Type: schema.TypeInt,
Optional: true,
Description: "",
},
and parse value of this attribute onto you struct as
c.ID = d.Get("id1").(int)
and try to build.
now the only drawback is you need to mention "id1" instead of "id" into your hcl file.
this is working for me, but still upgrading to SDKv2 is better solution
Upvotes: 0
Reputation: 74219
Your go.mod
file suggests that you are using SDK version 1.17.2, where id
is indeed recorded as a reserved attribute name.
However, it no longer seems to be present in the latest SDK release, 2.6.1. It seems that this policy changed as a result of issue #607, and the change was released for the first time in SDK release v2.1.0.
While I can't explain why the code you've shared would be raising that error, you may be able to avoid the problem by upgrading to the latest SDK version. Since it's a new major release there may be some breaking changes to consider elsewhere in the API. There's a Terraform SDK v2 upgrade guide which describes the changes and also includes a link to the tf-sdk-migrator
tool which has some automation to help with the upgrade.
Upvotes: 1