Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"panic: Failed to serialize resource instance in state: Instance" in terraform import in v1.3.0 #31851

Closed
SimonG-Kontentai opened this issue Sep 23, 2022 · 5 comments · Fixed by #31871
Assignees
Labels
bug confirmed a Terraform Core team member has reproduced this issue v1.3 Issues (primarily bugs) reported against v1.3 releases

Comments

@SimonG-Kontentai
Copy link

SimonG-Kontentai commented Sep 23, 2022

Terraform Version

Terraform: 1.3
AzureRM: 3.23.0
AzureAD: 2.28.1
Fastly: 2.3.2

Terraform Configuration Files

simplified/cropped configuration

**Configuration**
data "azurerm_managed_api" "type" {
  name     = var.api_connection_type
  location = var.resource_group.location
}

resource "azurerm_api_connection" "connection" {
  name                = var.name
  resource_group_name = var.resource_group.name
  managed_api_id      = data.azurerm_managed_api.type.id
  display_name        = var.display_name

  parameter_values = var.parameters

  lifecycle {
    ignore_changes = [parameter_values]
  }
}

Debug Output

Crash output in "Actual Behavior"

Expected Behavior

Everything is fine with Terraform 1.2.9

Actual Behavior

!!!!!!!!!!!!!!!!!!!!!!!!!!! TERRAFORM CRASH !!!!!!!!!!!!!!!!!!!!!!!!!!!!

Terraform crashed! This is always indicative of a bug within Terraform.
Please report the crash with Terraform1 so that we can fix this.

When reporting bugs, please include your terraform version, the stack trace
shown below, and any additional information which may help replicate the issue.

!!!!!!!!!!!!!!!!!!!!!!!!!!! TERRAFORM CRASH !!!!!!!!!!!!!!!!!!!!!!!!!!!!

Failed to serialize resource instance in state: Instance module.client.module.env_config_generator.module.blob_connection.data.azurerm_managed_api.type has status ObjectPlanned, which cannot be saved in state.
goroutine 1 [running]:
runtime/debug.Stack()
/usr/local/go/src/runtime/debug/stack.go:24 +0x65
runtime/debug.PrintStack()
/usr/local/go/src/runtime/debug/stack.go:16 +0x19
github.com/hashicorp/terraform/internal/logging.PanicHandler()
/home/circleci/project/project/internal/logging/panic.go:55 +0x153
panic({0x23c03c0, 0xc00c0cb488})
/usr/local/go/src/runtime/panic.go:890 +0x262
github.com/hashicorp/terraform/internal/states/statefile.StatesMarshalEqual(0xc004759880, 0xc001e9c8f0)
/home/circleci/project/project/internal/states/statefile/marshal_equal.go:31 +0x191
github.com/hashicorp/terraform/internal/states/remote.(*State).PersistState(0xc00159f1a0, 0x0?)
/home/circleci/project/project/internal/states/remote/state.go:164 +0x106
github.com/hashicorp/terraform/internal/command.(*ImportCommand).Run(0xc000125860, {0xc0000ce020, 0x3, 0x6})
/home/circleci/project/project/internal/command/import.go:265 +0x1f5f
github.com/mitchellh/cli.(*CLI).Run(0xc000604c80)
/home/circleci/go/pkg/mod/github.com/mitchellh/cli@v1.1.4/cli.go:262 +0x5f8
main.realMain()
/home/circleci/project/project/main.go:315 +0x15f4
main.main()
/home/circleci/project/project/main.go:58 +0x19

Steps to Reproduce

A new environment with few resources that must be first imported

Terraform import

Additional Context

No response

References

Split from

@SimonG-Kontentai SimonG-Kontentai added bug new new issue not yet triaged labels Sep 23, 2022
@SimonG-Kontentai SimonG-Kontentai changed the title "panic: Failed to serialize resource instance in state: Instance" in terraform apply in v1.3.0 "panic: Failed to serialize resource instance in state: Instance" in terraform import in v1.3.0 Sep 23, 2022
@dataclouder
Copy link

I have the same issue in vmware/terraform-provider-vcd.
During a test import, where I want to import a resource, I get an error saying that it can't save the state of some data sources:

2022-09-23T10:42:43.177+0200 [TRACE] sdk.helper_resource: Called Terraform CLI import command: test_name=TestAccVcdDistributedFirewall test_step_number=3 test_terraform_path=/usr/local/bin/terraform test_working_directory=/var/folders/rz/cn7hvgzd1dl5y23l378dsf_c0000gn/T/plugintest3181630485/work1768856104
2022-09-23T10:42:43.177+0200 [WARN]  sdk.helper_resource: Error running Terraform CLI command: test_name=TestAccVcdDistributedFirewall test_step_number=3 test_terraform_path=/usr/local/bin/terraform
  error=
  | exit status 1
  | Error writing state file: 3 problems:
  |
  | - Failed to serialize resource instance in state: Instance data.vcd_nsxt_network_context_profile.cp1 has status ObjectPlanned, which cannot be saved in state.
  | - Failed to serialize resource instance in state: Instance data.vcd_nsxt_network_context_profile.cp2 has status ObjectPlanned, which cannot be saved in state.
  | - Failed to serialize resource instance in state: Instance data.vcd_nsxt_network_context_profile.cp3 has status ObjectPlanned, which cannot be saved in state.
   test_working_directory=/var/folders/rz/cn7hvgzd1dl5y23l378dsf_c0000gn/T/plugintest3181630485/work1768856104

This behavior seems similar to the one reported to the plugin SDK Issue #1066, where a data source is erroneously compared to a resource.

@adrian-ungureanu
Copy link

Same problem here - trying to import a resource and we exhibit:

Instance data.azurerm_key_vault_secret.machine_login_credentials has status ObjectPlanned, which cannot be saved in state.

My use case is a generated Azure Key Vault secret.

@jbardin jbardin self-assigned this Sep 23, 2022
@jbardin jbardin added the confirmed a Terraform Core team member has reproduced this issue label Sep 23, 2022
@kda33
Copy link

kda33 commented Sep 26, 2022

Same and what to do?


!!!!!!!!!!!!!!!!!!!!!!!!!!! TERRAFORM CRASH !!!!!!!!!!!!!!!!!!!!!!!!!!!!

Terraform crashed! This is always indicative of a bug within Terraform.
Please report the crash with Terraform[1] so that we can fix this.

When reporting bugs, please include your terraform version, the stack trace
shown below, and any additional information which may help replicate the issue.

[1]: https://github.com/hashicorp/terraform/issues

!!!!!!!!!!!!!!!!!!!!!!!!!!! TERRAFORM CRASH !!!!!!!!!!!!!!!!!!!!!!!!!!!!

Failed to serialize resource instance in state: Instance data.aws_vpc_endpoint.s3 has status ObjectPlanned, which cannot be saved in state.
goroutine 1 [running]:
runtime/debug.Stack()
        /usr/local/go/src/runtime/debug/stack.go:24 +0x65
runtime/debug.PrintStack()
        /usr/local/go/src/runtime/debug/stack.go:16 +0x19
github.com/hashicorp/terraform/internal/logging.PanicHandler()
        /home/circleci/project/project/internal/logging/panic.go:55 +0x153
panic({0x249cb80, 0xc0027e58c0})
        /usr/local/go/src/runtime/panic.go:890 +0x262
github.com/hashicorp/terraform/internal/states/statefile.StatesMarshalEqual(0xc00081f6d0, 0xc0000a1810)
        /home/circleci/project/project/internal/states/statefile/marshal_equal.go:31 +0x191
github.com/hashicorp/terraform/internal/states/remote.(*State).PersistState(0xc000a450e0, 0x0?)
        /home/circleci/project/project/internal/states/remote/state.go:164 +0x106
github.com/hashicorp/terraform/internal/command.(*ImportCommand).Run(0xc000582d00, {0xc0001a8140, 0x4, 0x4})
        /home/circleci/project/project/internal/command/import.go:265 +0x1f5f
github.com/mitchellh/cli.(*CLI).Run(0xc0001ec780)
        /home/circleci/go/pkg/mod/github.com/mitchellh/cli@v1.1.4/cli.go:262 +0x5f8
main.realMain()
        /home/circleci/project/project/main.go:315 +0x15d4
main.main()
        /home/circleci/project/project/main.go:58 +0x19`

@jim-hill-r
Copy link

I have also seen this using AWS provider. Downgrade to 1.2.7 fixed it.

@github-actions
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug confirmed a Terraform Core team member has reproduced this issue v1.3 Issues (primarily bugs) reported against v1.3 releases
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants