Terraform: unable to delete value when attribute is omitted
Expected behavior:
When a user omits an attribute value from Terraform config, the next update should delete the value from Teleport state.
Current behavior:
When a user omits an attribute, the provider does not delete the the value from the Teleport state.
Example:
Omitting the logins and db_labels_expression attributes results in an empty plan.
resource "teleport_role" "example-bug" {
version = "v8"
metadata = {
name = "example-bug"
}
spec = {
allow = {
# logins = ["example"]
# db_labels_expression = "labels.example == `example`"
}
}
}$ terraform plan
...
No changes. Your infrastructure matches the configuration.
Terraform has compared your real infrastructure against your configuration and found no differences, so no changes are needed.Users must explicitly set the zero/default value
resource "teleport_role" "example-bug" {
version = "v8"
metadata = {
name = "example-bug"
}
spec = {
allow = {
logins = []
db_labels_expression = ""
}
}
}$ terraform plan
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:
# teleport_role.example-bug will be updated in-place
~ resource "teleport_role" "example-bug" {
id = "example-bug"
~ spec = {
~ allow = {
~ db_labels_expression = "labels.example == `example`" -> ""
~ logins = [
- "example",
]
# (44 unchanged attributes hidden)
}
# (2 unchanged attributes hidden)
}
# (4 unchanged attributes hidden)
}
Plan: 0 to add, 1 to change, 0 to destroy.Context
After upgrading to protoc-gen-terraform v4 in https://github.com/gravitational/teleport/pull/67080, many attributes have been converted into optional + computed attributes. This results in the undesirable user experience described above.
When a user omits a computed attribute, the provider does not interpret this as an indication to delete the attribute value. Instead the provider preserves the prior state.
Bug details:
- Teleport version: v19
Source: gravitational/teleport