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.8k stars 9.56k forks source link

TERRAFORM CRASH #34162

Closed Bryce-L closed 1 year ago

Bryce-L commented 1 year ago

Terraform Version

Terraform v1.6.1
on windows_amd64
+ provider registry.terraform.io/sumologic/sumologic v2.27.0

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

Terraform Configuration Files

main.tf

terraform {
  backend "azurerm" {
    storage_account_name = "XXXXX5"
    container_name       = "XXXXX6"
    key                  = "XXXXX4"
    resource_group_name  = "XXXXX3"
  }
  required_providers {
    sumologic = {
      source  = "sumologic/sumologic"
      version = "~> 2.27"
    }
  }
  required_version = "~> 1.6"
}

provider "sumologic" {
  access_id   = var.sumologic_access_id
  access_key  = var.sumologic_access_key
  environment = "us1"
}

data "sumologic_collector" "collector" {
  name = "Ecom_Hosted_Collectors"
}

partitions.tf

import {
  to = sumologic_partition.Ecom_K8s_Non_Sensitive["Dev"]
  id = "XXXXX1"
}

import {
  to = sumologic_partition.Ecom_K8s_Non_Sensitive["Test"]
  id = "XXXXX2"
}

resource "sumologic_partition" "Ecom_K8s_Non_Sensitive" {
  for_each = toset(["Dev", "Test"])
  name = "Ecom_K8s_${each.key}_Non_Sensitive"
  # The route_expression is using the heredoc style for multiline strings. 
  # See https://developer.hashicorp.com/terraform/language/expressions/strings#heredoc-strings
  routing_expression = <<-EOT
  _sourceCategory=${lower(each.key)}/ecom/*/kubernetes* 
  AND NOT pod_labels_sensitive_logs=true
  EOT
  analytics_tier     = "infrequent"
  lifecycle {
    prevent_destroy = true
  }
}

# These moved blocks are what trigger the crash.
moved {
  from = Ecom_K8s_Dev_Non_Sensitive
  to   = Ecom_K8s_Non_Sensitive["Dev"]
}

moved {
  from = Ecom_K8s_Test_Non_Sensitive
  to   = Ecom_K8s_Non_Sensitive["Test"]
}

Debug Output

runtime error: invalid memory address or nil pointer dereference goroutine 1 [running]: runtime/debug.Stack() /opt/hostedtoolcache/go/1.21.1/x64/src/runtime/debug/stack.go:24 +0x5e runtime/debug.PrintStack() /opt/hostedtoolcache/go/1.21.1/x64/src/runtime/debug/stack.go:16 +0x13 github.com/hashicorp/terraform/internal/logging.PanicHandler() /home/runner/work/terraform/terraform/internal/logging/panic.go:58 +0x13b panic({0x32dcb60?, 0x56cd1d0?}) /opt/hostedtoolcache/go/1.21.1/x64/src/runtime/panic.go:920 +0x270 github.com/hashicorp/terraform/internal/addrs.(MoveEndpoint).String(...) /home/runner/work/terraform/terraform/internal/addrs/move_endpoint.go:54 github.com/hashicorp/terraform/internal/configs.(Module).appendFile(0xc0007fde10, 0xc000630c00) /home/runner/work/terraform/terraform/internal/configs/module.go:456 +0x3d75 github.com/hashicorp/terraform/internal/configs.NewModule({0xc0007c0e80, 0x3, 0x0?}, {0x0, 0x0, 0x1?}) /home/runner/work/terraform/terraform/internal/configs/module.go:167 +0x4d5 github.com/hashicorp/terraform/internal/configs.(Parser).LoadConfigDir(0xc0006fe380?, {0x3ecd758, 0x1}) /home/runner/work/terraform/terraform/internal/configs/parser_config_dir.go:50 +0x27f github.com/hashicorp/terraform/internal/command.(Meta).loadSingleModule(0x0?, {0x3ecd758?, 0x16?}) /home/runner/work/terraform/terraform/internal/command/meta_config.go:91 +0x90 github.com/hashicorp/terraform/internal/command.(Meta).loadBackendConfig(0x0?, {0x3ecd758?, 0x0?}) /home/runner/work/terraform/terraform/internal/command/meta_config.go:145 +0x1c github.com/hashicorp/terraform/internal/command.(PlanCommand).PrepareBackend(0xc0006fe380, 0x0?, 0x48) /home/runner/work/terraform/terraform/internal/command/plan.go:123 +0xe5 github.com/hashicorp/terraform/internal/command.(PlanCommand).Run(0xc0006fe380, {0xc00007e0a0, 0x1, 0x2}) /home/runner/work/terraform/terraform/internal/command/plan.go:70 +0x46e github.com/mitchellh/cli.(CLI).Run(0xc0007a2c80) /home/runner/go/pkg/mod/github.com/mitchellh/cli@v1.1.5/cli.go:262 +0x5b8 main.realMain() /home/runner/work/terraform/terraform/main.go:339 +0x1eab main.main() /home/runner/work/terraform/terraform/main.go:64 +0x13

Expected Behavior

Terraform plan should have told me the plan.

Actual Behavior

Terraform crashed, providing a stacktrace.

Steps to Reproduce

  1. Run "terraform plan -out=tfplan"

Additional Context

I had two sumologic_partitions created as two resources. I wanted to try merging them into one resource and leverage for_each. Terraform plan said it was going to destroy the two resource and create new ones, so I decided to try adding a couple of moved blocks. That's when my plan started failing. If I comment out the moved blocks, plan succeeds. If I put them back, it crashes every time I run plan.

References

No response

jbardin commented 1 year ago

Duplicate of #34041

github-actions[bot] commented 11 months 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.