Skip to content

Conversation

@nicsnet
Copy link
Member

@nicsnet nicsnet commented Aug 21, 2025

This PR adds a new flag --stack to the CLI. It allows parsing a directory by providing a path which returns outputs, variables, components and providers either as markdown or by also adding --json flag as a json. It also adds diagnostics output in case of errors. Module parsing behaviour hasn't changed, it still works exactly as before.

For testing purposes, clone the learn-terraform-stacks-deploy repo, and provide its path as an argument to the CLI

go build .
./terraform-config-inspect --stack --json ../learn-terraform-stacks-deploy

Example output:

{
  "path": "../learn-terraform-stacks-deploy",
  "variables": {
    "default_tags": {
      "name": "default_tags",
      "type": "map(string)",
      "description": "A map of default tags to apply to all AWS resources",
      "default": {},
      "required": false,
      "pos": {
        "filename": "../learn-terraform-stacks-deploy/variables.tfstack.hcl",
        "line": 17
      }
    },
    "identity_token": {
      "name": "identity_token",
      "type": "string",
      "default": null,
      "required": true,
      "pos": {
        "filename": "../learn-terraform-stacks-deploy/variables.tfstack.hcl",
        "line": 8
      }
    },
    "regions": {
      "name": "regions",
      "type": "set(string)",
      "default": null,
      "required": true,
      "pos": {
        "filename": "../learn-terraform-stacks-deploy/variables.tfstack.hcl",
        "line": 4
      }
    },
    "role_arn": {
      "name": "role_arn",
      "type": "string",
      "default": null,
      "required": true,
      "pos": {
        "filename": "../learn-terraform-stacks-deploy/variables.tfstack.hcl",
        "line": 13
      }
    }
  },
  "outputs": {
    "lambda_urls": {
      "name": "lambda_urls",
      "description": "URLs to invoke lambda functions",
      "pos": {
        "filename": "../learn-terraform-stacks-deploy/outputs.tfstack.hcl",
        "line": 1
      },
      "type": "list(string)"
    }
  },
  "required_providers": {
    "archive": {
      "source": "hashicorp/archive"
    },
    "aws": {
      "source": "hashicorp/aws"
    },
    "local": {
      "source": "hashicorp/local"
    },
    "random": {
      "source": "hashicorp/random"
    }
  },
  "components": {
    "api_gateway": {
      "name": "api_gateway",
      "source": "./api-gateway",
      "pos": {
        "filename": "../learn-terraform-stacks-deploy/components.tfstack.hcl",
        "line": 37
      }
    },
    "lambda": {
      "name": "lambda",
      "source": "./lambda",
      "pos": {
        "filename": "../learn-terraform-stacks-deploy/components.tfstack.hcl",
        "line": 19
      }
    },
    "s3": {
      "name": "s3",
      "source": "./s3",
      "pos": {
        "filename": "../learn-terraform-stacks-deploy/components.tfstack.hcl",
        "line": 4
      }
    }
  },
  "diagnostics": [
    {
      "severity": "error",
      "summary": "Extraneous label for provider",
      "detail": "Only 1 labels (name) are expected for provider blocks.",
      "pos": {
        "filename": "../learn-terraform-stacks-deploy/providers.tfstack.hcl",
        "line": 26
      }
    },
    {
      "severity": "error",
      "summary": "Extraneous label for provider",
      "detail": "Only 1 labels (name) are expected for provider blocks.",
      "pos": {
        "filename": "../learn-terraform-stacks-deploy/providers.tfstack.hcl",
        "line": 43
      }
    },
    {
      "severity": "error",
      "summary": "Extraneous label for provider",
      "detail": "Only 1 labels (name) are expected for provider blocks.",
      "pos": {
        "filename": "../learn-terraform-stacks-deploy/providers.tfstack.hcl",
        "line": 44
      }
    },
    {
      "severity": "error",
      "summary": "Extraneous label for provider",
      "detail": "Only 1 labels (name) are expected for provider blocks.",
      "pos": {
        "filename": "../learn-terraform-stacks-deploy/providers.tfstack.hcl",
        "line": 45
      }
    }
  ]
}

PCI review checklist

  • If applicable, I’ve documented a plan to revert these changes if they require more than reverting the pull request.

  • If applicable, I’ve worked with GRC to document the impact of any changes to security controls.

    Examples of changes to controls include access controls, encryption, logging, etc.

  • If applicable, I’ve worked with GRC to ensure compliance due to a significant change to the cardholder data environment.

    Examples include changes to operating systems, ports, protocols, services, cryptography-related components, PII processing code, etc.

If you have any questions, please contact your direct supervisor, GRC (#team-grc), or the PCI working group (#proj-pci-core). You can also find more information at PCI Compliance.

@nicsnet nicsnet requested a review from a team as a code owner August 21, 2025 15:09
@nicsnet nicsnet changed the title Adds --stacks flag to terraform-config-inspect CLI Adds --stack flag to terraform-config-inspect CLI Aug 21, 2025
@nicsnet nicsnet merged commit d9a8f43 into master Aug 22, 2025
5 checks passed
rquadling added a commit to rquadling/terraform-config-inspect that referenced this pull request Oct 21, 2025
- Added `--version` flag (me!)
- Added simple Makefile.

Pulled from upstream.
- Introduce Pull Request template. Thank you [Phil Carvalho](hashicorp/terraform-config-inspect#133)
- Add Terraform Stack Configuration Support with Recognition of Stack Config Files. Thank you [Lion Chen](hashicorp/terraform-config-inspect#135)
- Extend Terraform Stack Support with Full Component, Output, and Provider Parsing. Thank you [Lion Chen](hashicorp/terraform-config-inspect#137)
- Adds `--stack` flag to terraform-config-inspect CLI. Thank you [Nicola Sheldrick](hashicorp/terraform-config-inspect#138)
- Switches to use terraform core's stack schema for config parsing, adds support for providers. Thank you [Nicola Sheldrick](hashicorp/terraform-config-inspect#139)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants