hashicorp / terraform

Terraform enables you to safely and predictably create, change, and improve infrastructure. It is a source-available tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.
https://www.terraform.io/
Other
42.63k stars 9.55k forks source link

TERRAFORM CRASH when importing google_composer_environment resource #35556

Closed jlenuffgsoi closed 1 month ago

jlenuffgsoi commented 2 months ago

Terraform Version

Terraform v1.9.2
on linux_amd64
+ provider registry.terraform.io/hashicorp/google v5.25.0
+ provider registry.terraform.io/hashicorp/google-beta v5.25.0

Your version of Terraform is out of date! The latest version
is 1.9.3. You can update by downloading from https://www.terraform.io/downloads.html

Terraform Configuration Files

module "composer" {
  source = "terraform-google-modules/composer/google//modules/create_environment_v2"

  project_id               = var.project
  region                   = var.region
  network_project_id       = var.network_vpc_project
  network                  = var.network_vpc_name
  subnetwork               = var.subnetwork_vpc_name
  composer_service_account = var.service_account
  environment_size         = var.environment_size
  airflow_config_overrides = local.airflow_config_overrides

  composer_env_name = var.composer_name
  image_version     = local.image_version
  pypi_packages     = local.pypi_packages

  scheduler  = local.scheduler
  web_server = local.webserver
  worker     = local.worker

  labels = {
    "owner" = local.owner_name,
    "env"   = var.env_name
  }

  env_variables = var.env_variables
}

import {
  id = "projects/${local.project}/locations/${var.region}/environments/composer-prod"
  to = module.composer.google_composer_environment.composer_env
}

Debug Output

https://gist.github.com/jlenuffgsoi/7f7c8960d2cbf6959d1b47cea6ced2ef

Expected Behavior

The resource should be imported successfully.

Actual Behavior

Terraform crashes when importing google_composer_environment resource :

!!!!!!!!!!!!!!!!!!!!!!!!!!! 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 !!!!!!!!!!!!!!!!!!!!!!!!!!!!

Steps to Reproduce

terraform init terraform plan

Additional Context

No response

References

No response

jlenuffgsoi commented 2 months ago

Intead, this command ends successfully :

terraform import module.composer.google_composer_environment.composer_env projects/my-project/locations/europe-west1/environments/composer-prod
jlenuffgsoi commented 2 months ago

Then, a simple plan with the import block throws the same error, after the manual import by CLI.

jbardin commented 2 months ago

Hi @jlenuffgsoi, can you please add the output from the error message so we can see where the panic started? Thanks!

jlenuffgsoi commented 2 months ago

Hi @jbardin,

I've provided a gist in my issue : https://gist.github.com/jlenuffgsoi/7f7c8960d2cbf6959d1b47cea6ced2ef.js

After reviewing my input settings for the terraform-google-modules/composer/google//modules/create_environment_v2 module, the issue is gone.

That's strange, all my settings are strings with simple letters, numbers and well-placed hypens.

I think it'related to the module's provider. Should I close my issue ?

jbardin commented 2 months ago

Hi @jlenuffgsoi, the gist does not contain any of the error output, that would have been written to stderr immediately after the TERRAFORM CRASH banner and is required to know what the crash actually was.

There may be an error in the configuration, but configuration errors still should not result in a panic like this, so it would be nice to pinpoint and fix so it can be handled more gracefully.

jlenuffgsoi commented 2 months ago

Sorry, I didn't provide the correct link.

I've updated my issue. Here is the user-friendly output. The error message is at the end. https://gist.githubusercontent.com/jlenuffgsoi/7f7c8960d2cbf6959d1b47cea6ced2ef/raw/0917cee250585be0e606cd39d6a704d0ba907b0b/debug_output

Faster :

!!!!!!!!!!!!!!!!!!!!!!!!!!! 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 !!!!!!!!!!!!!!!!!!!!!!!!!!!!

panic: interface conversion: interface {} is float64, not string
goroutine 22 [running]:
runtime/debug.Stack()
        runtime/debug/stack.go:24 +0x5e
github.com/hashicorp/terraform/internal/logging.PanicHandler()
        github.com/hashicorp/terraform/internal/logging/panic.go:84 +0x18b
panic({0x302fcc0?, 0xc00186b560?})
        runtime/panic.go:770 +0x132
github.com/hashicorp/terraform/internal/command/jsonformat/structured/attribute_path.(*PathMatcher).GetChildWithKey(0xc0022de680, {0xc0009f42c0, 0x1a})
        github.com/hashicorp/terraform/internal/command/jsonformat/structured/attribute_path/matcher.go:154 +0x2ec
github.com/hashicorp/terraform/internal/command/jsonformat/structured.ChangeMap.GetChild({0x0, 0x0, 0xc00186b350, 0x0, 0x0, {0x3e110a8, 0xc0022de680}, {0x3e110e0, 0x5954ca0}, 0x0}, ...)
        github.com/hashicorp/terraform/internal/command/jsonformat/structured/map.go:75 +0x368
github.com/hashicorp/terraform/internal/command/jsonformat/differ.ComputeDiffForBlock({0x1, 0x0, {0x2e27ca0, 0xc0021ba180}, {0x0, 0x0}, {0x2faf440, 0xc00186b350}, {0x2e27ca0, 0xc0021ba588}, ...}, ...)
        github.com/hashicorp/terraform/internal/command/jsonformat/differ/block.go:34 +0x285
github.com/hashicorp/terraform/internal/command/jsonformat/differ.checkForUnknownBlock.func1({0x1, 0x0, {0x2e27ca0, 0xc0021ba180}, {0x0, 0x0}, {0x2faf440, 0xc00186b350}, {0x2e27ca0, 0xc0021ba588}, ...})
        github.com/hashicorp/terraform/internal/command/jsonformat/differ/unknown.go:54 +0x3d
github.com/hashicorp/terraform/internal/command/jsonformat/differ.checkForUnknownBlock.createProcessUnknownWithBefore.func2({0x1, 0x1, {0x2e27ca0, 0xc0021ba180}, {0x0, 0x0}, {0x2e740c0, 0x5730f68}, {0x2e27ca0, 0xc0021ba588}, ...}, ...)
        github.com/hashicorp/terraform/internal/command/jsonformat/differ/unknown.go:64 +0x3d
github.com/hashicorp/terraform/internal/command/jsonformat/structured.Change.CheckForUnknown({0x1, 0x1, {0x2e27ca0, 0xc0021ba180}, {0x0, 0x0}, {0x2e740c0, 0x5730f68}, {0x2e27ca0, 0xc0021ba588}, ...}, ...)
        github.com/hashicorp/terraform/internal/command/jsonformat/structured/unknown.go:64 +0x218
github.com/hashicorp/terraform/internal/command/jsonformat/differ.checkForUnknownBlock({0x1, 0x0, {0x2e27ca0, 0xc0021ba180}, {0x0, 0x0}, {0x2e740c0, 0x5730f68}, {0x2e27ca0, 0xc0021ba588}, ...}, ...)
        github.com/hashicorp/terraform/internal/command/jsonformat/differ/unknown.go:50 +0x176
github.com/hashicorp/terraform/internal/command/jsonformat/differ.ComputeDiffForBlock({0x1, 0x1, {0x2faf440, 0xc001824450}, {0x2faf440, 0xc001824990}, {0x2faf440, 0xc001824c60}, {0x2faf440, 0xc001824f30}, ...}, ...)
        github.com/hashicorp/terraform/internal/command/jsonformat/differ/block.go:77 +0x9e5
github.com/hashicorp/terraform/internal/command/jsonformat/differ.computeBlockDiffsAsList.func1({0x1, 0x1, {0x2faf440, 0xc001824450}, {0x2faf440, 0xc001824990}, {0x2faf440, 0xc001824c60}, {0x2faf440, 0xc001824f30}, ...})
        github.com/hashicorp/terraform/internal/command/jsonformat/differ/list.go:73 +0x59
github.com/hashicorp/terraform/internal/command/jsonformat/differ.processNestedList({0x1, 0x1, {0x2e27ca0, 0xc0021ba2b8}, {0x2e27ca0, 0xc0021ba3a8}, {0x2e27ca0, 0xc0021ba480}, {0x2e27ca0, 0xc0021ba6c0}, ...}, ...)
        github.com/hashicorp/terraform/internal/command/jsonformat/differ/list.go:88 +0xd5
github.com/hashicorp/terraform/internal/command/jsonformat/differ.computeBlockDiffsAsList({0x1, 0x1, {0x2e27ca0, 0xc0021ba2b8}, {0x2e27ca0, 0xc0021ba3a8}, {0x2e27ca0, 0xc0021ba480}, {0x2e27ca0, 0xc0021ba6c0}, ...}, ...)
        github.com/hashicorp/terraform/internal/command/jsonformat/differ/list.go:72 +0x125
github.com/hashicorp/terraform/internal/command/jsonformat/differ.ComputeDiffForBlock({0x0, 0x0, {0x2faf440, 0xc001824420}, {0x2faf440, 0xc001824960}, {0x2faf440, 0xc001824c30}, {0x2faf440, 0xc001824f00}, ...}, ...)
        github.com/hashicorp/terraform/internal/command/jsonformat/differ/block.go:94 +0xd98
github.com/hashicorp/terraform/internal/command/jsonformat.precomputeDiffs({{0x3522922, 0x3}, 0xc0021b5a40, {0xc000374c08, 0x2, 0x2}, {0x0, 0x0, 0x0}, {0xc0017c7900, ...}, ...}, ...)
        github.com/hashicorp/terraform/internal/command/jsonformat/diff.go:61 +0x785
github.com/hashicorp/terraform/internal/command/jsonformat.Plan.renderHuman({{0x3522922, 0x3}, 0xc0021b5a40, {0xc000374c08, 0x2, 0x2}, {0x0, 0x0, 0x0}, {0xc0017c7900, ...}, ...}, ...)
        github.com/hashicorp/terraform/internal/command/jsonformat/plan.go:59 +0x9a
github.com/hashicorp/terraform/internal/command/jsonformat.Renderer.RenderHumanPlan({0xc000194948?, 0xc000699200?, 0x0?}, {{0x3522922, 0x3}, 0xc0021b5a40, {0xc000374c08, 0x2, 0x2}, {0x0, ...}, ...}, ...)
        github.com/hashicorp/terraform/internal/command/jsonformat/renderer.go:118 +0x1ef
github.com/hashicorp/terraform/internal/command/views.(*OperationHuman).Plan(0xc000920ff0, 0xc0016dfa40, 0xc0021ccd30)
        github.com/hashicorp/terraform/internal/command/views/operation.go:130 +0x305
github.com/hashicorp/terraform/internal/backend/local.(*Local).opPlan(0xc000942000, {0x3e0fc90, 0xc0007140f0}, {0x3e0fc90, 0xc000714140}, 0xc00090ef00, 0xc000923980)
        github.com/hashicorp/terraform/internal/backend/local/backend_plan.go:202 +0xe95
github.com/hashicorp/terraform/internal/backend/local.(*Local).Operation.func1()
        github.com/hashicorp/terraform/internal/backend/local/backend.go:331 +0xbe
created by github.com/hashicorp/terraform/internal/backend/local.(*Local).Operation in goroutine 1
        github.com/hashicorp/terraform/internal/backend/local/backend.go:324 +0x3fa
jbardin commented 2 months ago

Thanks @jlenuffgsoi! That looks like it's specific to formatting a certain diff in the json output, so it would only happen with a particular combination of changes and likely disappear once they have been resolved.

jlenuffgsoi commented 2 months ago

Thanks @jlenuffgsoi! That looks like it's specific to formatting a certain diff in the json output, so it would only happen with a particular combination of changes and likely disappear once they have been resolved.

Yes, that's probably explains why after correcting my input settings in order to align with my env, the error disappeared.

Thank you. :-)

jbardin commented 2 months ago

reopening until we can track down the root cause

github-actions[bot] commented 2 weeks ago

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.