Reputation: 5250
I am trying to update terraform google provider to 3.58
from 3.55
to add big query deletion protection.
When running a terraform plan
I get # forces replacement
warnings:
# google_bigquery_table.my_table must be replaced
...
+ deletion_protection = true
...
~ schema = jsonencode(
~ [ # forces replacement
~ {
~ fields = [
# (6 unchanged elements hidden)
{
description = "Location of the data schema."
name = "dataSchema"
type = "STRING"
},
~ {
~ type = "BOOLEAN" -> "BOOL"
# (2 unchanged elements hidden)
},
]
~ type = "RECORD" -> "STRUCT"
# (2 unchanged elements hidden)
} # forces replacement,
~ {
~ type = "RECORD" -> "STRUCT"
# (3 unchanged elements hidden)
} # forces replacement,
~ {
~ type = "RECORD" -> "STRUCT"
# (3 unchanged elements hidden)
} # forces replacement,
]
)
Can anyone help me understand (a) why am I getting a forced replacement on this update when I haven't changed my schemas and (b) how can I update my google provider without deleting the data in my table.
Any help would be much appreciated.
Upvotes: 0
Views: 1794
Reputation: 2326
Sometimes it seems that Terraform is aggressive on flagging needs replacement. I am not sure if it is related, but I have seen sometimes a more 'conservative' flagging of this when changing versions of Terraform (by conservative, I mean it appears to try to replace more often - I am unsure if the upgraded versions don't realize that settings that were not previously settable in TF, but are now, are flagged as potentially changed and thus need replacement). I agree that if your schema hasn't changed, there is no need to replace the resource.
Identify the resource as ignore_changes
by ensuring it is specified in the lifecycle
block within the resource body.
From the Terraform documentation:
The
ignore_changes
feature is intended to be used when a resource is created with references to data that may change in the future, but should not affect said resource after its creation. In some rare cases, settings of a remote object are modified by processes outside of Terraform, which Terraform would then attempt to "fix" on the next run. In order to make Terraform share management responsibilities of a single object with a separate process, the ignore_changes meta-argument specifies resource attributes that Terraform should ignore when planning updates to the associated remote object.
Some example code from that:
resource "aws_instance" "example" {
# ...
lifecycle {
ignore_changes = [
# Ignore changes to tags, e.g. because a management agent
# updates these based on some ruleset managed elsewhere.
tags,
]
}
}
Also note that you can use the keyword all
instead of a list in ignore_changes
to ignore all attributes.
Upvotes: 1