terraform
terraform copied to clipboard
terraform plan -generate-config-out fails for schemas with nested and computed "id" attributes
Terraform Version
Terraform v1.8.3
on darwin_amd64
Terraform Configuration Files
terraform {
required_version = ">=1.1"
required_providers {
example = {
version = "~> 0.0.1"
source = "example/example"
}
}
}
provider "example" {
}
import {
to = example_import_error.generated
id = "idVal"
}
Debug Output
https://gist.github.com/henryrecker-pingidentity/96529224dfd95a19d58bdd1843371048
Expected Behavior
terraform plan -generate-config-out should create the HCL in generated.tf as expected, including all attribute values.
Actual Behavior
An error occurs when using an attribute named "id" that is computed in a listnested attribute. The "id" value is left out of the resulting generated HCL file. Note: A normal terraform import
works fine. It's just the terraform plan -generate-config-out
that fails.
Error:
example_import_error.generated: Preparing import... [id=idVal]
example_import_error.generated: Refreshing state...
Planning failed. Terraform encountered an error while generating this plan.
╷
│ Warning: Config generation is experimental
│
│ Generating configuration during import is currently experimental, and the generated configuration format may change in future
│ versions.
╵
╷
│ Error: attribute "list_val": incorrect list element type: attribute "id" is required
│
│
╵
Output generated HCL file:
# __generated__ by Terraform
# Please review these resources and move them into your main configuration files.
# __generated__ by Terraform
resource "example_import_error" "generated" {
list_val = [
{
},
]
test_id = "id"
}
Steps to Reproduce
I used a sample provider I built with terraform-plugin-framework. The provider has an example_import_error
resource with one basic test_id
attribute, and one listnested attribute with an id
attribute in the nested object.
The implementation of this resource is in this gist - https://gist.github.com/henryrecker-pingidentity/490a9ee2d0a7702463807686ff276c00 The full provider is located here (on the linked ImportBlockBug branch) - https://github.com/henryrecker-pingidentity/terraform-provider-example/tree/ImportBlockBug
Then with a locally built provider, I ran terraform plan -generate-config-out=generated.tf
with the configuration file above.
Additional Context
This does not occur with normal terraform import (terraform import example_import_error.ex test
for example) or with normal terraform CRUD operations.
This seems to specifically be related to the attribute name "id". If I change the listnested attribute to use a different string attribute name, the error goes away.
It also seems to be specific to the "id" value being computed. If not computed, the error also goes away.
References
No response