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

Include PassedProviderConfig information in JSON output format. #30480

Closed
nozaq opened this issue Feb 5, 2022 · 2 comments
Closed

Include PassedProviderConfig information in JSON output format. #30480

nozaq opened this issue Feb 5, 2022 · 2 comments
Labels
enhancement new new issue not yet triaged

Comments

@nozaq
Copy link
Contributor

nozaq commented Feb 5, 2022

Current Terraform Version

Terraform v1.1.5
on linux_amd64

Use-cases

I'm working on a tool to visualize the resource structure by analyzing the JSON output produced from terraform show -json command, and would like to identify which provider to be used for each resource.

Suppose we have the following tf file.

provider "null" {
  alias = "provider_1"
}

provider "null" {
  alias = "provider_2"
}

module "a" {
  providers = {
    null = null.provider_1
  }

  source = "./modules/foo"
}

module "b" {
  providers = {
    null = null.provider_2
  }

  source = "./modules/foo"
}

Running terraform plan -out plan.out and terraform show -json plan.out will produce the JSON output. The resulting JSON contains the following provider configurations in configuration.provider_config.

  • null
  • null.provider_1
  • null.provider_2
  • module.a:null
  • module.b:null

The issue is that the result does not contain the relations between these providers, so we can't identify that null.provider_1 is assigned to module.a:null as well as null.provider_2 is assigned to module.b:null.

For example, when using AWS provider multiple providers could be defined in one project and each work for a different AWS region. In such case, currently we can not identify in which region the specific resource in a child module would be created from analyzing the JSON output.

Attempted Solutions

I've created a repo containing all sample code and the actual JSON output file.

Proposal

Include PassedProviderConfig defined in ModuleCall struct into configuration.module_calls block of the JSON output so that tools can infer which provider is actually passed to child modules.

{
  ...
  "configuration": {
    ...
    "module_calls": {
      "child": {
        ...
        "passed_provider_config": {
          "in_child": {
            "name": <provider-name-in-child>,
            "alias": <provider-alias-in-child>
          },
          "in_parent": {
            "name": <provider-name-in-parent>.
            "alias": <provider-alias-in-parent>
          }
        }
      }
    }
  }
}

References

@nozaq nozaq added enhancement new new issue not yet triaged labels Feb 5, 2022
@apparentlymart
Copy link
Member

Hi @nozaq! Thanks for reporting this.

I think you've reported the same underlying problem as #30113 here, and so I'm going to close this to consolidate the discussion over there. There's already a pending PR to address this issue (albeit in a slightly different way than you proposed) and I believe it's only now pending some coordinated updates in other parts of the Terraform product which consume this JSON output.

Thanks again!

@github-actions
Copy link

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 Mar 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement new new issue not yet triaged
Projects
None yet
Development

No branches or pull requests

2 participants