Update resource

Hi, I’m writing terraform provider. I want up update resource.
Resource has computed parameter guid_id. For update I need to have this parameter as input.
Do we have possibility to describe schema for every operation (For CreateContent, ReadContext,UpdateContect, DeleteContext)? Then I will describe updatecontext schema accordingly

Dmitriy

Um, no? Resources have one schema, which defines how a user is supposed to write them in their Terraform files, and what is stored in the state. That is inherently common to all operations.

Thanks for the response.

How I should to describe guid attribute.

It is created in POST method( I described as calculated) and used in PUT( not clear how to described)

Terraform throws error:
Can’t configure a value for “guid_id”: its value will be decided automatically based on the result of applying this configuration.

Best regards,
Dmitriy

Please show your actual code.

Hi,
here is main.tf
terraform {
required_providers {
orch = {
version = “1.0.1”
source = “localhost/company/orch”
}
}
}

provider “orch” {

}
variable “iaas_name” {
description=“Name of iaas provider”
}

variable “iaas_url” {
description=“Url of iaas provider”
}
variable “iaas_update_url” {
description=“Url of iaas provider”
}
variable “iaas_type” {
description=“Url of iaas provider”
}
variable “iaas_guid” {
description=“guild of iaas provider”
}
resource “orch_iaas_resource” “my_iaas” {

type=var.iaas_type
name=var.iaas_name
url=var.iaas_url
}
output “my_iaas_output” {
value=[orch_iaas_resource.my_iaas.guid_id,orch_iaas_resource.my_iaas.name]
}
resource “orch_iaas_resource” “my_iaas1” {
guid_id=orch_iaas_resource.my_iaas.guid_id
type=var.iaas_type
name=var.iaas_name
url=var.iaas_update_url

}

output “my_iaas_output1” {
value=[orch_iaas_resource.my_iaas1.guid_id,orch_iaas_resource.my_iaas1.url]
}

resource my_iaas created resource. guid_id has been generated
Then my_iaas1 updated the same resource. Call has been failed with the error

When expanding the plan for orch_iaas_resource.my_iaas1 to include new values learned so far during apply, provider "localhost/company/orch
" produced an
│ invalid new value for .guid_id: was null, but now cty.StringVal(“a93a5416-d9fa-4191-8fd7-11751449ea20”).

In different topic someone advised to have update in the same block.
I will try to implement it. I described guid_id as optional.

If you have an another idea how to update resource where key is generated please let me know.

Best regards,
Dmitriy

Hi @dtrvno :wave:

Are you able to share the code for your provider? Specifically the schema and the code you are using in the CRUD operations?

This thread appears to be a duplicate of Custom terraform provider, update issue

Hi,

looks like you asked the same question from that thread.
It is impossible based on that thread.

Best regards,
Dmitriy

@dtrvno The user you’re replying to appears to be a link spammer, using ChatGPT or similar to construct a vaguely plausible but pointless message. They will later return and edit a link to some other website they’re trying pump the search engine ranking of, when they think no-one is paying attention to this topic any more.

There is sadly an epidemic of this abuse on this forum right now. I’ve seen the pattern so many times by now, so I’ve already reported the post to moderators.