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 show doesn't properly output child_modules in certain circumstances - with ready fix #27351

Closed
cube2222 opened this issue Dec 21, 2020 · 4 comments
Labels
bug confirmed a Terraform Core team member has reproduced this issue v0.13 Issues (primarily bugs) reported against v0.13 releases v0.14 Issues (primarily bugs) reported against v0.14 releases

Comments

@cube2222
Copy link
Contributor

Hey, I'll try to keep it short.

Let's say you have 3 modules, in the examples that's the root module, the resourceless module, and the lost module.
The resourceless module is a child of the root module.
The lost module is a child of the resourceless module.

The caveat though is that the resourceless module doesn't create any resources itself, it only creates the lost module.

This will break the recurrence in jsonstate/state.go and will never print the contents of the resourceless and lost modules.

I have a simple fix ready, including a regression test, so will create a PR shortly.

Terraform Version

All 0.14.x versions and head of master, the problematic code hasn't been touched for a while though, so it should be reproducible in earlier versions too.

Terraform Configuration Files

# main.tf
module "resourceless-module" {
  source = "./resourceless"
}
# resourceless/main.tf
module "lost-module" {
  source = "./lost"
}
# resourceless/lost/main.tf
resource random_id "lost-id" {
  byte_length = 16
}

Expected Behavior

Running terraform show -json should properly print all the modules in a child_modules hierarchy. Like this (this is the output with my fix):

{
  "format_version": "0.1",
  "terraform_version": "0.15.0",
  "values": {
    "root_module": {
      "child_modules": [
        {
          "address": "module.resourceless-module",
          "child_modules": [
            {
              "address": "module.resourceless-module.module.lost-module",
              "resources": [
                {
                  "address": "module.resourceless-module.module.lost-module.random_id.lost-id",
                  "mode": "managed",
                  "name": "lost-id",
                  "provider_name": "registry.terraform.io/hashicorp/random",
                  "schema_version": 0,
                  "type": "random_id",
                  "values": {
                    "b64_std": "DI0iBocGJYcaeDpQrDYnlg==",
                    "b64_url": "DI0iBocGJYcaeDpQrDYnlg",
                    "byte_length": 16,
                    "dec": "16683539925555807513425851214500079510",
                    "hex": "0c8d2206870625871a783a50ac362796",
                    "id": "DI0iBocGJYcaeDpQrDYnlg",
                    "keepers": null,
                    "prefix": null
                  }
                }
              ]
            }
          ]
        }
      ]
    }
  }
}

Actual Behavior

{"format_version":"0.1","terraform_version":"0.15.0","values":{"root_module":{}}}

Steps to Reproduce

Just apply the above terraform files and run terraform show -json

@cube2222 cube2222 added bug new new issue not yet triaged labels Dec 21, 2020
@cube2222 cube2222 changed the title terraform show doesn't properly output child_modules in certain circumstances terraform show doesn't properly output child_modules in certain circumstances - with ready fix Dec 21, 2020
@danieldreier danieldreier added confirmed a Terraform Core team member has reproduced this issue v0.13 Issues (primarily bugs) reported against v0.13 releases v0.14 Issues (primarily bugs) reported against v0.14 releases and removed new new issue not yet triaged labels Dec 22, 2020
@danieldreier
Copy link
Contributor

@cube2222 thank you for the report and clear reproduction case! I've reproduced this on 0.14.2 and 0.13.5. Most of the team of off for the holidays, and this looks real but non-urgent to me, so be aware that it probably won't get much more attention until January. Please let me know if I've misunderstood the issue and and it's causing an urgent incident for you.

@cube2222
Copy link
Contributor Author

Hey, since the Christmas holiday season is over I suppose, could you please take a look at this?
Here's the Pull Request aiming to fix this: #27352

@cube2222
Copy link
Contributor Author

PR merged, thanks!

@ghost
Copy link

ghost commented Feb 11, 2021

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.

@ghost ghost locked as resolved and limited conversation to collaborators Feb 11, 2021
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 v0.13 Issues (primarily bugs) reported against v0.13 releases v0.14 Issues (primarily bugs) reported against v0.14 releases
Projects
None yet
Development

No branches or pull requests

2 participants