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

Terraform crashed: interface {} is string, not float64 #33472

Closed
baeyear opened this issue Jul 4, 2023 · 4 comments · Fixed by #33475
Closed

Terraform crashed: interface {} is string, not float64 #33472

baeyear opened this issue Jul 4, 2023 · 4 comments · Fixed by #33475
Assignees
Labels
bug confirmed a Terraform Core team member has reproduced this issue

Comments

@baeyear
Copy link

baeyear commented Jul 4, 2023

Terraform Version

1.5.2

Terraform Configuration Files

...terraform config...

Debug Output

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


Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
interface conversion: interface {} is string, not float64
goroutine 37 [running]:
runtime/debug.Stack()
        /Users/runner/hostedtoolcache/go/1.20.0/x64/src/runtime/debug/stack.go:24 +0x65
runtime/debug.PrintStack()
        /Users/runner/hostedtoolcache/go/1.20.0/x64/src/runtime/debug/stack.go:16 +0x19
github.com/hashicorp/terraform/internal/logging.PanicHandler()
        /Users/runner/work/terraform/terraform/internal/logging/panic.go:58 +0x153
panic({0x304bf80, 0xc002452d80})
        /Users/runner/hostedtoolcache/go/1.20.0/x64/src/runtime/panic.go:884 +0x213
github.com/hashicorp/terraform/internal/command/jsonformat/structured/attribute_path.(*PathMatcher).GetChildWithIndex(0xc00013be60, 0x0)
        /Users/runner/work/terraform/terraform/internal/command/jsonformat/structured/attribute_path/matcher.go:176 +0x2cb
github.com/hashicorp/terraform/internal/command/jsonformat/structured.ChangeSlice.GetChild({{0xc002bd69e0, 0x1, 0x1}, {0xc002bd6da0, 0x1, 0x1}, {0x0, 0x0, 0x0}, {0xc002bd6f30, ...}, ...}, ...)
        /Users/runner/work/terraform/terraform/internal/command/jsonformat/structured/slice.go:75 +0x252
github.com/hashicorp/terraform/internal/command/jsonformat/differ.processNestedList({0x1, 0x1, {0x2ed0720, 0xc0019cb980}, {0x2ed0720, 0xc0019cbb60}, {0x0, 0x0}, {0x2ed0720, 0xc0019cbd58}, ...}, ...)
        /Users/runner/work/terraform/terraform/internal/command/jsonformat/differ/list.go:83 +0x13b
github.com/hashicorp/terraform/internal/command/jsonformat/differ.computeBlockDiffsAsList({0x1, 0x1, {0x2ed0720, 0xc0019cb980}, {0x2ed0720, 0xc0019cbb60}, {0x0, 0x0}, {0x2ed0720, 0xc0019cbd58}, ...}, ...)
        /Users/runner/work/terraform/terraform/internal/command/jsonformat/differ/list.go:72 +0x145
github.com/hashicorp/terraform/internal/command/jsonformat/differ.ComputeDiffForBlock({0x0, 0x0, {0x3007cc0, 0xc0022e2c90}, {0x3007cc0, 0xc0022e2f00}, {0x3007cc0, 0xc0022e3140}, {0x3007cc0, 0xc0022e3170}, ...}, ...)
        /Users/runner/work/terraform/terraform/internal/command/jsonformat/differ/block.go:92 +0xf98
github.com/hashicorp/terraform/internal/command/jsonformat.precomputeDiffs({{0x33dc6ed, 0x3}, 0xc001bf5fb0, {0xc0006cf000, 0x13, 0x22}, {0xc0012fc800, 0xa, 0x11}, {0xc0019fd680, ...}, ...}, ...)
        /Users/runner/work/terraform/terraform/internal/command/jsonformat/diff.go:52 +0x3b8
github.com/hashicorp/terraform/internal/command/jsonformat.Plan.renderHuman({{0x33dc6ed, 0x3}, 0xc001bf5fb0, {0xc0006cf000, 0x13, 0x22}, {0xc0012fc800, 0xa, 0x11}, {0xc0019fd680, ...}, ...}, ...)
        /Users/runner/work/terraform/terraform/internal/command/jsonformat/plan.go:64 +0xa5
github.com/hashicorp/terraform/internal/command/jsonformat.Renderer.RenderHumanPlan({0xc000120d68?, 0xc0002a6cc0?, 0x17?}, {{0x33dc6ed, 0x3}, 0xc001bf5fb0, {0xc0006cf000, 0x13, 0x22}, {0xc0012fc800, ...}, ...}, ...)
        /Users/runner/work/terraform/terraform/internal/command/jsonformat/renderer.go:92 +0x1ef
github.com/hashicorp/terraform/internal/command/views.(*OperationHuman).Plan(0xc000ac0790, 0xc0010983c0, 0x0?)
        /Users/runner/work/terraform/terraform/internal/command/views/operation.go:126 +0x31c
github.com/hashicorp/terraform/internal/backend/local.(*Local).opApply(0x0?, {0x39deb38, 0xc0008343c0}, {0x39deb38, 0xc000834410}, 0xc000aba5a0, 0xc000aaed00)
        /Users/runner/work/terraform/terraform/internal/backend/local/backend_apply.go:117 +0x996
github.com/hashicorp/terraform/internal/backend/local.(*Local).Operation.func1()
        /Users/runner/work/terraform/terraform/internal/backend/local/backend.go:326 +0xc3
created by github.com/hashicorp/terraform/internal/backend/local.(*Local).Operation
        /Users/runner/work/terraform/terraform/internal/backend/local/backend.go:319 +0x44a
make: *** [apply] Error 11

Expected Behavior

I expected terraform apply successfully

Actual Behavior

terraform crashed

Steps to Reproduce

  1. terraform init
  2. terraform apply

Additional Context

No response

References

No response

@baeyear baeyear added bug new new issue not yet triaged labels Jul 4, 2023
@liamcervante
Copy link
Member

Hi @baeyear, thanks for filing this!

Are you able to share your configuration, so I can debug and reproduce locally?

Alternatively, if you run the following:

  • terraform plan -out planfile
  • terraform show -json planfile

That should print out a JSONified version of the plan, which I can also use to reproduce locally.

Thanks!

@liamcervante liamcervante added waiting-response An issue/pull request is waiting for a response from the community waiting for reproduction unable to reproduce issue without further information labels Jul 4, 2023
@baeyear
Copy link
Author

baeyear commented Jul 5, 2023

Hi, @liamcervante .

Hello, thank you for your response.

I apologize, but I am unable to execute the above command since I have closed the billing account and destroyed the project on GCP.

Instead, I will detail the part of the code where the issue was reproduced.

I encountered a terraform crash when I specified the google_datastream_connection_profile.postgresql_profile.hostname as follows:

resource "google_datastream_connection_profile" "alloydb" {
  display_name          = "AlloyDB Connection profile"
  location              = var.default_region
  connection_profile_id = "alloydb-connection-profile"
  project               = var.project_id

  postgresql_profile {
    hostname = google_compute_instance.main.network_interface["0"].network_ip
    port     = "5432"
    username = sensitive(var.alloydb_datastream.username)
    password = sensitive(var.alloydb_datastream.password)
    database = "postgres"
  }

  private_connectivity {
    private_connection = google_datastream_private_connection.main.id
  }
}

However, when I changed the syntax to the following, the crash did not occur.

resource "google_datastream_connection_profile" "alloydb" {
  display_name          = "AlloyDB Connection profile"
  location              = var.default_region
  connection_profile_id = "alloydb-connection-profile"
  project               = var.project_id

  postgresql_profile {
    hostname = google_compute_instance.main.network_interface.0.network_ip
    port     = "5432"
    username = sensitive(var.alloydb_datastream.username)
    password = sensitive(var.alloydb_datastream.password)
    database = "postgres"
  }

  private_connectivity {
    private_connection = google_datastream_private_connection.main.id
  }
}

I hope this information is useful. Thank you for your understanding.

@liamcervante
Copy link
Member

Thanks for that, it's very helpful.

So I think the crash is being caused by this line: google_compute_instance.main.network_interface["0"].network_ip

The renderer is expecting that 0 to be an int not a string, as you spotted in your updated config. But Terraform definitely shouldn't crash in this case, so I will put together a fix so it interprets the string as a number where possible and handles the error properly otherwise.

Thnaks!

@liamcervante liamcervante added confirmed a Terraform Core team member has reproduced this issue and removed waiting-response An issue/pull request is waiting for a response from the community new new issue not yet triaged waiting for reproduction unable to reproduce issue without further information labels Jul 5, 2023
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 Dec 14, 2023
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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants