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 test: Modules with no resources aren't saving their output values #34476

Closed
liamcervante opened this issue Jan 4, 2024 · 3 comments
Assignees
Labels
bug confirmed a Terraform Core team member has reproduced this issue explained a Terraform Core team member has described the root cause of this issue in code terraform test v1.6 Issues (primarily bugs) reported against v1.6 releases v1.7 Issues (primarily bugs) reported against v1.7 releases

Comments

@liamcervante
Copy link
Member

Terraform Version

1.7.0-rc1
1.6.6

Terraform Configuration Files

# main.tf

module "first" {
  source = "./first"
}
# first/main.tf

module "second" {
    source = "../second"
}

output "id" {
    value = module.second.id
}
# second/main.tf

resource "tfcoremock_simple_resource" "resource" {}

output "id" {
  value = tfcoremock_simple_resource.resource.id
}
# main.tftest.hcl

run "run1" {
  command = apply

  assert {
    condition     = module.first.id != 0
    error_message = "Fail"
  }
}

Debug Output

N/A

Expected Behavior

test should pass

Actual Behavior

test fails

Steps to Reproduce

terraform init
terraform test

Additional Context

No response

References

@liamcervante liamcervante added bug confirmed a Terraform Core team member has reproduced this issue terraform test labels Jan 4, 2024
@liamcervante liamcervante self-assigned this Jan 4, 2024
@liamcervante
Copy link
Member Author

Specifically, our definition of an empty module here: https://github.com/hashicorp/terraform/blob/main/internal/terraform/node_module_expand.go#L220 is causing the middle module in the configuration to be removed, and then the test assertion doesn't have access to the output from that module and so it returns unknown.

Interestingly, this is already fixed in main I think by this PR: #34343, which wasn't backported to v1.7.

@liamcervante liamcervante added the explained a Terraform Core team member has described the root cause of this issue in code label Jan 4, 2024
@apparentlymart apparentlymart added v1.6 Issues (primarily bugs) reported against v1.6 releases v1.7 Issues (primarily bugs) reported against v1.7 releases labels Jan 5, 2024
liamcervante added a commit that referenced this issue Jan 5, 2024
…ernal references (#34482)

* Add test verifying issue #34476 has been fixed

* Keep modules in state if they are required by the external references

* tweak logic so it doesn't delete twice
@liamcervante
Copy link
Member Author

This should be fixed in the next release of the v1.7 series.

Copy link
Contributor

github-actions bot commented Feb 5, 2024

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 Feb 5, 2024
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 explained a Terraform Core team member has described the root cause of this issue in code terraform test v1.6 Issues (primarily bugs) reported against v1.6 releases v1.7 Issues (primarily bugs) reported against v1.7 releases
Projects
None yet
Development

No branches or pull requests

2 participants