Skip to content

Crash when planning with an invalid module source in a parent module #31056

@Octogonapus

Description

@Octogonapus

Terraform Version

Terraform v1.1.9
on linux_amd64
+ provider registry.terraform.io/hashicorp/aws v4.13.0
+ provider registry.terraform.io/hashicorp/external v2.2.2
+ provider registry.terraform.io/hashicorp/local v2.2.2
+ provider registry.terraform.io/hashicorp/null v3.1.1
+ provider registry.terraform.io/hashicorp/random v3.1.3

Terraform Configuration Files

I have a shell script instead of configuration files because the order in which the environments are created, and the order in which the configuration files are edited, is important to reproducing this.

mkdir terraformbug && cd terraformbug
echo 'resource "null_resource" "foo" {}\nmodule "foo" { source = "./submod2" }' > main.tf
mkdir submod1
echo 'module "foo" { source = "../" }' > submod1/main.tf
mkdir submod2
touch submod2/main.tf
terraform init
cd submod1
terraform init
echo 'resource "null_resource" "foo" {}\nmodule "foo" { source = "${path.module}/submod2" }' > ../main.tf
terraform plan

Debug Output

Expected Behavior

I would expect an error like Variables may not be used here. instead of a crash.

Actual Behavior

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

runtime error: invalid memory address or nil pointer dereference
goroutine 54 [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 +0x154
panic({0x2328bc0, 0x418c6d0})
	/usr/local/go/src/runtime/panic.go:1038 +0x215
github.com/hashicorp/terraform/internal/configs/configload.(*Loader).moduleWalkerLoad(0xc00066c460, 0xc0001f7c20)
	/home/circleci/project/project/internal/configs/configload/loader_load.go:64 +0x16c
github.com/hashicorp/terraform/internal/configs/configload.(*Loader).makeModuleWalkerSnapshot.func1(0xc0001f7c20)
	/home/circleci/project/project/internal/configs/configload/loader_snapshot.go:134 +0x54
github.com/hashicorp/terraform/internal/configs.ModuleWalkerFunc.LoadModule(0x2301e80, 0xc00094dba0)
	/home/circleci/project/project/internal/configs/config_build.go:131 +0x1f
github.com/hashicorp/terraform/internal/configs.buildChildModules(0xc00032e8c0, {0x2c05840, 0xc000a80d80})
	/home/circleci/project/project/internal/configs/config_build.go:69 +0x4bd
github.com/hashicorp/terraform/internal/configs.buildChildModules(0xc00032e700, {0x2c05840, 0xc000a80d80})
	/home/circleci/project/project/internal/configs/config_build.go:89 +0x77a
github.com/hashicorp/terraform/internal/configs.BuildConfig(0xc000b7c370, {0x2c05840, 0xc000a80d80})
	/home/circleci/project/project/internal/configs/config_build.go:24 +0x85
github.com/hashicorp/terraform/internal/configs/configload.(*Loader).LoadConfigWithSnapshot(0xc00066c460, {0x26bcd4b, 0x1})
	/home/circleci/project/project/internal/configs/configload/loader_snapshot.go:31 +0xbc
github.com/hashicorp/terraform/internal/backend/local.(*Local).localRunDirect(0x27905f8, 0xc000528b40, 0xc000a952f0, 0x278b954, {0x2c6e728, 0xc00079b080})
	/home/circleci/project/project/internal/backend/local/backend_local.go:135 +0x73
github.com/hashicorp/terraform/internal/backend/local.(*Local).localRun(0xc000325cc0, 0xc000528b40)
	/home/circleci/project/project/internal/backend/local/backend_local.go:98 +0x8d4
github.com/hashicorp/terraform/internal/backend/local.(*Local).opPlan(0xc000325cc0, {0x2c4f078, 0xc000b7a200}, {0x2c4f078, 0xc000b7a240}, 0xc000528b40, 0xc000b7a1c0)
	/home/circleci/project/project/internal/backend/local/backend_plan.go:58 +0x12b
github.com/hashicorp/terraform/internal/backend/local.(*Local).Operation.func1()
	/home/circleci/project/project/internal/backend/local/backend.go:323 +0xc3
created by github.com/hashicorp/terraform/internal/backend/local.(*Local).Operation
	/home/circleci/project/project/internal/backend/local/backend.go:316 +0x445

Steps to Reproduce

Additional Context

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugconfirmeda Terraform Core team member has reproduced this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions