I’m creating a simple tag
resource in my custom provider that will look something like:
resource "provider_tag" "my-foo-tag" {
name = "foo"
}
It will have name
attribute and another id
that will have the same value as name. When changing the name
I get:
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
~ update in-place
Terraform will perform the following actions:
# provider_tag.my-foo-tag will be updated in-place
~ resource "provider_tag" "my-foo-tag" {
~ id = "foo" -> (known after apply)
~ name = "foo" -> "bar"
}
Plan: 0 to add, 1 to change, 0 to destroy.
I’m curios how does Terraform execution plan knows when to perform an update in-place
or a complete destroy and recreation? It seems to me that since the id
changes it should not be an update in place, but maybe I’m missing something.
Thanks for any input!
Hi @zuzuleinen,
There is nothing special about id
from Terraform’s perspective, it’s just an attribute like any other. It’s up to the provider to indicate when a change is going to cause replacement. For example, if you are using the plugin framework you could add a stringplanmodifier.RequiresReplace()
to indicate that a change to an attribute will force replacement of the resource instance.
1 Like
Thanks @jbardin,
stringplanmodifier.RequiresReplace()
is useful. So it is safe to assume that when an attribute is changed, the update will alayws be in-place, and if this behavior has to be changed a RequiresReplace
modified should be added?
later edit: Actually I see this is the case as I wrote above:
In-place update is part of the basic Terraform lifecycle for managing resources. To ensure that Terraform plans replacement of a resource, rather than perform an in-place update, use the [
resource.RequiresReplace() attribute plan modifier](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/resource#RequiresReplace) in the schema or implement [resource plan modification](https://developer.hashicorp.com/terraform/plugin/framework/resources/plan-modification).
source
Thank you!