-
Notifications
You must be signed in to change notification settings - Fork 10.3k
terraform test Consistently Crashing #34584
Copy link
Copy link
Closed as not planned
Labels
bugnewnew issue not yet triagednew issue not yet triagedterraform testwaiting-responseAn issue/pull request is waiting for a response from the communityAn issue/pull request is waiting for a response from the community
Description
Terraform Version
Terraform v1.7.0
on darwin_arm64
+ provider registry.terraform.io/hashicorp/aws v5.34.0
+ provider registry.terraform.io/hashicorp/random v3.6.0Terraform Configuration Files
main.tftest.hcl
# Instructions: Create basic tests
# Configure the AWS
provider "aws" {
region = "us-east-1"
}
# Global Testing Variables - Define variables to be used in all tests here. You can overwrite these varibles by definig an additional variables block within the 'run' block for your tests
variables {
# - Test CodeCommit Repos -
codecommit_repos = {
# Test Module 1
test_module_1 : {
repository_name = local.tf_test_test_module_1_repository_name
description = "Test Module 1."
default_branch = "main"
tags = {
"ContentType" = "Test Module",
}
},
# Test Module 2
test_module_2 : {
repository_name = local.tf_test_test_module_2_repository_name
description = "Test Module 2."
default_branch = "main"
tags = {
"ContentType" = "Test Module",
}
},
# Test Workload 1
test_workload_1 : {
repository_name = local.tf_test_test_workload_1_repository_name
description = "Test Workload 1."
default_branch = "main"
tags = {
"ContentType" = "Test Workload",
}
},
# Test Workload 2
test_workload_2 : {
repository_name = local.tf_test_test_workload_2_repository_name
description = "Test Workload 2."
default_branch = "main"
tags = {
"ContentType" = "Test Workload",
}
},
}
# - Test CodeBuild Projects -
codebuild_projects = {
# Test Module 1
tf_test_test_module_1 : {
name = local.tf_test_test_module_1_codebuild_project_name
description = "Test Module 1 - Terraform Test"
path_to_build_spec = local.tf_test_path_to_buildspec
},
chevkov_test_module_1 : {
name = local.chevkov_test_module_1_codebuild_project_name
description = "Test Module 1 - Checkov"
path_to_build_spec = local.checkov_path_to_buildspec
},
# Test Module 2
tf_test_test_module_2 : {
name = local.tf_test_test_module_2_codebuild_project_name
description = "Test Module 2 - Terraform Test"
path_to_build_spec = local.tf_test_path_to_buildspec
},
chevkov_test_module_2 : {
name = local.chevkov_test_module_2_codebuild_project_name
description = "Test Module 2 - Checkov"
path_to_build_spec = local.checkov_path_to_buildspec
},
# Test Workload 1
tf_test_test_workload_1 : {
name = local.tf_test_test_workload_1_codebuild_project_name
description = "Test Workload 1"
path_to_build_spec = local.tf_test_path_to_buildspec
},
chevkov_test_workload_1 : {
name = local.chevkov_test_workload_1_codebuild_project_name
description = "Test Workload 1"
path_to_build_spec = local.checkov_path_to_buildspec
},
# Test Workload 2
tf_test_test_workload_2 : {
name = local.tf_test_test_workload_2_codebuild_project_name
description = "Test Workload 2"
path_to_build_spec = local.tf_test_path_to_buildspec
},
chevkov_test_workload_2 : {
name = local.chevkov_test_workload_2_codebuild_project_name
description = "Test Workload 2"
path_to_build_spec = local.checkov_path_to_buildspec
},
tf_apply_test_workload_1 : {
name = local.tf_apply_test_workload_1_codebuild_project_name
description = "Test Workload 1"
path_to_build_spec = local.tf_apply_path_to_buildspec
},
tf_apply_test_workload_2 : {
name = local.tf_apply_test_workload_2_codebuild_project_name
description = "Test Workload 2"
path_to_build_spec = local.tf_apply_path_to_buildspec
},
}
# - Test CodePipeline pipelines -
codepipeline_pipelines = {
# Terraform Module Validation Pipeline for 'test-module-1' Terraform Module
tf_module_validation_test_module_1 : {
name = local.tf_module_validation_test_module_1_codepipeline_pipeline_name
tags = {
"Description" = "Test Module 1.",
}
stages = [
# Clone from CodeCommit, store contents in artifacts S3 Bucket
{
name = "Source"
action = [
{
name = "PullFromCodeCommit"
category = "Source"
owner = "AWS"
provider = "CodeCommit"
version = "1"
configuration = {
BranchName = "main"
RepositoryName = local.test_module_1_repository_name
}
input_artifacts = []
# Store the output of this stage as 'source_output_artifacts' in connected the Artifacts S3 Bucket
output_artifacts = ["source_output_artifacts"]
run_order = 1
},
]
},
# Run Terraform Test Framework
{
name = "Build_TF_Test"
action = [
{
name = "TerraformTest"
category = "Build"
owner = "AWS"
provider = "CodeBuild"
version = "1"
configuration = {
# Reference existing CodeBuild Project
ProjectName = local.tf_test_test_module_1_codebuild_project_name
}
# Use the 'source_output_artifacts' contents from the Artifacts S3 Bucket
input_artifacts = ["source_output_artifacts"]
# Store the output of this stage as 'build_tf_test_output_artifacts' in the connected Artifacts S3 Bucket
output_artifacts = ["build_tf_test_output_artifacts"]
run_order = 1
},
]
},
# Run Checkov
{
name = "Build_Checkov"
action = [
{
name = "Checkov"
category = "Build"
owner = "AWS"
provider = "CodeBuild"
version = "1"
configuration = {
# Reference existing CodeBuild Project
ProjectName = local.chevkov_test_module_1_codebuild_project_name
}
# Use the 'source_output_artifacts' contents from the Artifacts S3 Bucket
input_artifacts = ["source_output_artifacts"]
# Store the output of this stage as 'build_checkov_output_artifacts' in the connected Artifacts S3 Bucket
output_artifacts = ["build_checkov_output_artifacts"]
run_order = 1
},
]
},
]
},
# Terraform Module Validation Pipeline for 'test-module-2' Terraform Module
tf_module_validation_test_module_2 : {
name = local.tf_module_validation_test_module_2_codepipeline_pipeline_name
tags = {
"Description" = "Test Module 2.",
}
stages = [
# Clone from CodeCommit, store contents in artifacts S3 Bucket
{
name = "Source"
action = [
{
name = "PullFromCodeCommit"
category = "Source"
owner = "AWS"
provider = "CodeCommit"
version = "1"
configuration = {
BranchName = "main"
RepositoryName = local.test_module_2_repository_name
}
input_artifacts = []
# Store the output of this stage as 'source_output_artifacts' in connected the Artifacts S3 Bucket
output_artifacts = ["source_output_artifacts"]
run_order = 1
},
]
},
# Run Terraform Test Framework
{
name = "Build_TF_Test"
action = [
{
name = "TerraformTest"
category = "Build"
owner = "AWS"
provider = "CodeBuild"
version = "1"
configuration = {
# Reference existing CodeBuild Project
ProjectName = local.tf_test_test_module_2_codebuild_project_name
}
# Use the 'source_output_artifacts' contents from the Artifacts S3 Bucket
input_artifacts = ["source_output_artifacts"]
# Store the output of this stage as 'build_tf_test_output_artifacts' in the connected Artifacts S3 Bucket
output_artifacts = ["build_tf_test_output_artifacts"]
run_order = 1
},
]
},
# Run Checkov
{
name = "Build_Checkov"
action = [
{
name = "Checkov"
category = "Build"
owner = "AWS"
provider = "CodeBuild"
version = "1"
configuration = {
# Reference existing CodeBuild Project
ProjectName = local.chevkov_test_module_2_codebuild_project_name
}
# Use the 'source_output_artifacts' contents from the Artifacts S3 Bucket
input_artifacts = ["source_output_artifacts"]
# Store the output of this stage as 'build_checkov_output_artifacts' in the connected Artifacts S3 Bucket
output_artifacts = ["build_checkov_output_artifacts"]
run_order = 1
},
]
},
]
},
# Terraform Deployment Pipeline for 'test-workload-1'
tf_deployment_test_workload_1 : {
name = local.tf_deployment_test_workload_1_codepipeline_pipeline_name
tags = {
"Description" = "Test workload 1.",
}
stages = [
# Clone from CodeCommit, store contents in artifacts S3 Bucket
{
name = "Source"
action = [
{
name = "PullFromCodeCommit"
category = "Source"
owner = "AWS"
provider = "CodeCommit"
version = "1"
configuration = {
BranchName = "main"
RepositoryName = local.test_workload_1_repository_name
}
input_artifacts = []
# Store the output of this stage as 'source_output_artifacts' in connected the Artifacts S3 Bucket
output_artifacts = ["source_output_artifacts"]
run_order = 1
},
]
},
# Run Terraform Test Framework
{
name = "Build_TF_Test"
action = [
{
name = "TerraformTest"
category = "Build"
owner = "AWS"
provider = "CodeBuild"
version = "1"
configuration = {
# Reference existing CodeBuild Project
ProjectName = local.tf_test_test_workload_1_codebuild_project_name
}
# Use the 'source_output_artifacts' contents from the Artifacts S3 Bucket
input_artifacts = ["source_output_artifacts"]
# Store the output of this stage as 'build_tf_test_output_artifacts' in the connected Artifacts S3 Bucket
output_artifacts = ["build_tf_test_output_artifacts"]
run_order = 1
},
]
},
# Run Checkov
{
name = "Build_Checkov"
action = [
{
name = "Checkov"
category = "Build"
owner = "AWS"
provider = "CodeBuild"
version = "1"
configuration = {
# Reference existing CodeBuild Project
ProjectName = local.chevkov_test_workload_1_codebuild_project_name
}
# Use the 'source_output_artifacts' contents from the Artifacts S3 Bucket
input_artifacts = ["source_output_artifacts"]
# Store the output of this stage as 'build_checkov_output_artifacts' in the connected Artifacts S3 Bucket
output_artifacts = ["build_checkov_output_artifacts"]
run_order = 1
},
]
},
# Apply Terraform
{
name = "Apply"
action = [
{
name = "TerraformApply"
category = "Build"
owner = "AWS"
provider = "CodeBuild"
version = "1"
configuration = {
# Reference existing CodeBuild Project
ProjectName = local.tf_apply_test_workload_1_codebuild_project_name
}
# Use the 'source_output_artifacts' contents from the Artifacts S3 Bucket
input_artifacts = ["source_output_artifacts"]
# Store the output of this stage as 'build_checkov_output_artifacts' in the connected Artifacts S3 Bucket
output_artifacts = ["build_checkov_output_artifacts"]
run_order = 1
},
]
},
]
},
# Terraform Deployment Pipeline for 'test-workload-2'
tf_deployment_test_workload_2 : {
name = local.tf_deployment_test_workload_2_codepipeline_pipeline_name
tags = {
"Description" = "Test workload 2.",
}
stages = [
# Clone from CodeCommit, store contents in artifacts S3 Bucket
{
name = "Source"
action = [
{
name = "PullFromCodeCommit"
category = "Source"
owner = "AWS"
provider = "CodeCommit"
version = "1"
configuration = {
BranchName = "main"
RepositoryName = local.test_workload_2_repository_name
}
input_artifacts = []
# Store the output of this stage as 'source_output_artifacts' in connected the Artifacts S3 Bucket
output_artifacts = ["source_output_artifacts"]
run_order = 1
},
]
},
# Run Terraform Test Framework
{
name = "Build_TF_Test"
action = [
{
name = "TerraformTest"
category = "Build"
owner = "AWS"
provider = "CodeBuild"
version = "1"
configuration = {
# Reference existing CodeBuild Project
ProjectName = local.tf_test_test_workload_2_codebuild_project_name
}
# Use the 'source_output_artifacts' contents from the Artifacts S3 Bucket
input_artifacts = ["source_output_artifacts"]
# Store the output of this stage as 'build_tf_test_output_artifacts' in the connected Artifacts S3 Bucket
output_artifacts = ["build_tf_test_output_artifacts"]
run_order = 1
},
]
},
# Run Checkov
{
name = "Build_Checkov"
action = [
{
name = "Checkov"
category = "Build"
owner = "AWS"
provider = "CodeBuild"
version = "1"
configuration = {
# Reference existing CodeBuild Project
ProjectName = local.chevkov_test_workload_2_codebuild_project_name
}
# Use the 'source_output_artifacts' contents from the Artifacts S3 Bucket
input_artifacts = ["source_output_artifacts"]
# Store the output of this stage as 'build_checkov_output_artifacts' in the connected Artifacts S3 Bucket
output_artifacts = ["build_checkov_output_artifacts"]
run_order = 1
},
]
},
# Apply Terraform
{
name = "Apply"
action = [
{
name = "TerraformApply"
category = "Build"
owner = "AWS"
provider = "CodeBuild"
version = "1"
configuration = {
# Reference existing CodeBuild Project
ProjectName = local.tf_apply_test_workload_2_codebuild_project_name
}
# Use the 'source_output_artifacts' contents from the Artifacts S3 Bucket
input_artifacts = ["source_output_artifacts"]
# Store the output of this stage as 'build_checkov_output_artifacts' in the connected Artifacts S3 Bucket
output_artifacts = ["build_checkov_output_artifacts"]
run_order = 1
},
]
},
]
},
}
}
# - Unit Tests -
run "input_validation" {
command = plan
# Intentional invalid values to test functionality. These variables overwrite the above variables (helpful for testing).
variables {
# Intentional project_prefix that is longer than max of 40 characters (overwrite of above global variable)
project_prefix = "this_is_a_project_prefix_and_it_is_over_40_characters_and_will_cause_a_failure"
# CodeCommit - Intentional repository name that is longer than max of 40 characters
codecommit_repos = {
# Custom Terraform Module Repo
test_module_1 : {
repository_name = "this_is_a_repository_name_loger_than_100_characters"
description = "Test Module 1."
default_branch = "main"
tags = {
"ContentType" = "Test Module 1",
},
}
}
# CodeBuild - Intentional project name that is longer than max of 40 characters
codebuild_projects = {
# Test Module 1
tf_test_test_module_1 : {
name = "this_is_a_project_name_and_it_is_longer_than_40_characters"
description = "Test Module 1 - Terraform Test"
path_to_build_spec = local.tf_test_path_to_buildspec
},
}
# CodePipeline - Intentional pipeline name that is longer than max of 40 characters
codepipeline_pipelines = {
# Terraform Module Validation Pipeline for 'test-module-1' Terraform Module
tf_module_validation_test_module_1 : {
name = "this_is_a_pipeline_name_and_it_is_longer_than_40_characters_and_will_fail"
tags = {
"Description" = "Test Module 1.",
}
stages = [
# Clone from CodeCommit, store contents in artifacts S3 Bucket
{
name = "Source"
action = [
{
name = "PullFromCodeCommit"
category = "Source"
owner = "AWS"
provider = "CodeCommit"
version = "1"
configuration = {
BranchName = "main"
RepositoryName = local.test_module_1_repository_name
}
input_artifacts = []
# Store the output of this stage as 'source_output_artifacts' in connected the Artifacts S3 Bucket
output_artifacts = ["source_output_artifacts"]
run_order = 1
},
]
},
# Run Terraform Test Framework
{
name = "Build_TF_Test"
action = [
{
name = "TerraformTest"
category = "Build"
owner = "AWS"
provider = "CodeBuild"
version = "1"
configuration = {
# Reference existing CodeBuild Project
ProjectName = local.tf_test_test_module_1_codebuild_project_name
}
# Use the 'source_output_artifacts' contents from the Artifacts S3 Bucket
input_artifacts = ["source_output_artifacts"]
# Store the output of this stage as 'build_tf_test_output_artifacts' in the connected Artifacts S3 Bucket
output_artifacts = ["build_tf_test_output_artifacts"]
run_order = 1
},
]
},
# Run Checkov
{
name = "Build_Checkov"
action = [
{
name = "Checkov"
category = "Build"
owner = "AWS"
provider = "CodeBuild"
version = "1"
configuration = {
# Reference existing CodeBuild Project
ProjectName = local.chevkov_test_module_1_codebuild_project_name
}
# Use the 'source_output_artifacts' contents from the Artifacts S3 Bucket
input_artifacts = ["source_output_artifacts"]
# Store the output of this stage as 'build_checkov_output_artifacts' in the connected Artifacts S3 Bucket
output_artifacts = ["build_checkov_output_artifacts"]
run_order = 1
},
]
},
]
},
}
}
# Check for intentional failure of variables defined above. We expect these to fail since we intentionally provided values that do not conform to the validation rules defined in the module's variable.tf file.
expect_failures = [
var.project_prefix,
var.codecommit_repos,
var.codebuild_projects,
var.codepipeline_pipelines,
]
}
# - End-to-end Tests -
run "e2e_test" {
command = apply
# Using global variables defined above since additional variables block is not defined here
# Assertions
# CodeCommit - Ensure repositories have correct names after creation
assert {
condition = aws_codecommit_repository.codecommit[0].name == "test-module-1"
error_message = "Test CodeCommit Repo 1 name didn't match the expected value."
}
assert {
condition = aws_codecommit_repository.codecommit[1].name == "test-repo-2"
error_message = "Test CodeCommit Repo 2 name didn't match the expected value."
}
assert {
condition = aws_codecommit_repository.codecommit[2].name == "test-workload-1"
error_message = "Test CodeCommit Repo 2 name didn't match the expected value."
}
assert {
condition = aws_codecommit_repository.codecommit[2].name == "test-workload-2"
error_message = "Test CodeCommit Repo 2 name didn't match the expected value."
}
# CodeBuild - Ensure projects have correct names after creation
assert {
condition = aws_codebuild_project.codebuild[0].name == "TerraformTest-test-module-1"
error_message = "The CodeBuild Project name (${aws_codebuild_project.codebuild[0].name}) didn't match the expected value (TerraformTest-test-module-1)."
}
assert {
condition = aws_codebuild_project.codebuild[1].name == "Checkov-test-module-1"
error_message = "The CodeBuild Project name (${aws_codebuild_project.codebuild[1].name}) didn't match the expected value (Checkov-test-module-1)."
}
assert {
condition = aws_codebuild_project.codebuild[2].name == "TerraformTest-test-module-2"
error_message = "The CodeBuild Project name (${aws_codebuild_project.codebuild[2].name}) didn't match the expected value (TerraformTest-test-module-2)."
}
assert {
condition = aws_codebuild_project.codebuild[3].name == "Checkov-test-module-2"
error_message = "The CodeBuild Project name (${aws_codebuild_project.codebuild[3].name}) didn't match the expected value (Checkov-test-module-2)."
}
assert {
condition = aws_codebuild_project.codebuild[4].name == "TerraformTest-test-workload-1"
error_message = "The CodeBuild Project name (${aws_codebuild_project.codebuild[4].name}) didn't match the expected value (TerraformTest-test-workload-1)."
}
assert {
condition = aws_codebuild_project.codebuild[5].name == "Checkov-test-workload-1"
error_message = "The CodeBuild Project name (${aws_codebuild_project.codebuild[5].name}) didn't match the expected value (Checkov-test-workload-1)."
}
assert {
condition = aws_codebuild_project.codebuild[6].name == "TerraformTest-test-workload-2"
error_message = "The CodeBuild Project name (${aws_codebuild_project.codebuild[6].name}) didn't match the expected value (TerraformTest-test-workload-2)."
}
assert {
condition = aws_codebuild_project.codebuild[7].name == "Checkov-test-workload-2"
error_message = "The CodeBuild Project name (${aws_codebuild_project.codebuild[7].name}) didn't match the expected value (Checkov-test-workload-2)."
}
assert {
condition = aws_codebuild_project.codebuild[8].name == "TFApply-test-workload-1"
error_message = "The CodeBuild Project name (${aws_codebuild_project.codebuild[8].name}) didn't match the expected value (TFApply-test-workload-1)."
}
assert {
condition = aws_codebuild_project.codebuild[9].name == "TFApply-test-workload-2"
error_message = "The CodeBuild Project name (${aws_codebuild_project.codebuild[9].name}) didn't match the expected value (TFApply-test-workload-2)."
}
# CodePipeline - Ensure pipelines have correct names after creation
assert {
condition = aws_codepipeline.codepipeline[0].name == "tf-module-validation-test-module-1"
error_message = "The CodeBuild Project name (${aws_codepipeline.codepipeline[0].name}) didn't match the expected value (tf-module-validation-test-module-1)."
}
assert {
condition = aws_codepipeline.codepipeline[1].name == "tf-module-validation-test-module-2"
error_message = "The CodeBuild Project name (${aws_codepipeline.codepipeline[1].name}) didn't match the expected value (tf-module-validation-test-module-2)."
}
assert {
condition = aws_codepipeline.codepipeline[2].name == "tf-deploy-test-workload-1"
error_message = "The CodeBuild Project name (${aws_codepipeline.codepipeline[2].name}) didn't match the expected value (tf-deploy-test-workload-1)."
}
assert {
condition = aws_codepipeline.codepipeline[3].name == "tf-deploy-test-workload-2"
error_message = "The CodeBuild Project name (${aws_codepipeline.codepipeline[3].name}) didn't match the expected value (tf-deploy-test-workload-2)."
}
}
Debug Output
❯ terraform test
tests/main.tftest.hcl... in progress
!!!!!!!!!!!!!!!!!!!!!!!!!!! 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 25 [running]:
runtime/debug.Stack()
/Users/runner/hostedtoolcache/go/1.21.5/x64/src/runtime/debug/stack.go:24 +0x64
runtime/debug.PrintStack()
/Users/runner/hostedtoolcache/go/1.21.5/x64/src/runtime/debug/stack.go:16 +0x1c
github.com/hashicorp/terraform/internal/logging.PanicHandler()
/Users/runner/work/terraform/terraform/internal/logging/panic.go:58 +0x164
panic({0x1057bb600?, 0x1075d7c30?})
/Users/runner/hostedtoolcache/go/1.21.5/x64/src/runtime/panic.go:914 +0x218
github.com/hashicorp/terraform/internal/backend/local.(*TestFileRunner).GetVariables(0x1400188bef8, 0x1400094c540, 0x14000951220, {0x0, 0x0, 0x1400050e000?})
/Users/runner/work/terraform/terraform/internal/backend/local/test.go:1063 +0x530
github.com/hashicorp/terraform/internal/backend/local.(*TestFileRunner).run(0x1400188bef8, 0x14000951220, 0x140009512c0, 0x140009a3d70, 0x1400094c540)
/Users/runner/work/terraform/terraform/internal/backend/local/test.go:405 +0x708
github.com/hashicorp/terraform/internal/backend/local.(*TestFileRunner).Test(0x1400188bef8, 0x140009512c0)
/Users/runner/work/terraform/terraform/internal/backend/local/test.go:336 +0x48c
github.com/hashicorp/terraform/internal/backend/local.(*TestSuiteRunner).Test(0x14000237dd0)
/Users/runner/work/terraform/terraform/internal/backend/local/test.go:140 +0x2bc
github.com/hashicorp/terraform/internal/command.(*TestCommand).Run.func1()
/Users/runner/work/terraform/terraform/internal/command/test.go:230 +0x9c
created by github.com/hashicorp/terraform/internal/command.(*TestCommand).Run in goroutine 1
/Users/runner/work/terraform/terraform/internal/command/test.go:224 +0xab4
Expected Behavior
Not crash
Actual Behavior
Crashing every single time
Steps to Reproduce
terraform initterraform test
Additional Context
This appears to be the same issue that was identified in this GitHub Issue - #33780 that was closed.
References
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugnewnew issue not yet triagednew issue not yet triagedterraform testwaiting-responseAn issue/pull request is waiting for a response from the communityAn issue/pull request is waiting for a response from the community