Hello everyone!
I am currently writing a small custom provider for my thesis project, and I ran into problems
the provider is supposed to create a simple resource on a local running Bitbucket.
I studied the Terraform guides about writing providers and some existing providers to understand how Terraform interacts with providers and golang itself.
I got it working, somewhat - but I run into the same problem not matter what I do. When I try to create a resource using my custom providers, this error pops up:
When applying changes to customResource, provider
“customProvider” produced an unexpected new value: Root resource
was present, but now absent.
Sadly, this error almost never comes up in the entire internet - I looked into it all day. As I understand it, the “inconsistent result after apply” error is the result of the provider changing ResourceData in a way that isn’t nessecary, so Terraform thinks a change has been made? I don’t undertand what “Root resource” refers to in this context, though.
I think the problem stems from the fact that the id of my object is an int (server-side), but Terraform forces me to use TypeString - or because it is a Computed value, or a combination of both. I convert the id into string in the resourceSomethingRead-function, of course. My logs indicate that the entire create and read operation runs into no problems: the response from the server is accepted with correct codes and all content is parsed correctly, too. But still, the error is thrown.
I looked into this all day and wasn’t able to find any answers or pointer to understanding Root resource correctly, or how the read-function works and when it is called by Terraform. I think the problem lies somewhere in there.
Did anyone ever run into similar problems, or does someone understand what the problem is? Does anyone know a provider that successfully maps an external non-string ID into Terraform?
For context, here is the full content of my relevant provider files (its really simple, or should be):
resource_project.go
provider.go
client.go
Some more context: this is what a successful POST to the server returns, the POST body contains all information but the ID (because it is exclusively computed by the server and can’t be set manually)
1 post - 1 participant
Read full topic