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

✨ add terraform.plan.variables #5113

Merged
merged 4 commits into from
Jan 22, 2025
Merged

Conversation

afiune
Copy link
Contributor

@afiune afiune commented Jan 22, 2025

This change adds terraform.plan.variables to our terraform provider for a plan connection.

Using the test data added, when running cnquery shell, we now get:

➜  cnquery git:(afiune/terraform/plan-variables) ✗ ./cnquery shell terraform plan providers/terraform/connection/testdata/dynamic_block/tfplan.json -c terraform.plan.variables
! detected Schrödinger's path, cannot detect if it is usable path=/Library/Mondoo/providers/.providers-unpack2980851121/.providers-unpack2980851121.json
! using builtin provider for terraform
→ user requested to ignore .terraform
! using builtin provider for terraform
→ loaded configuration from /Users/afiune/.config/mondoo/mondoo.yml using source default
! using builtin provider for terraform
→ connected to Terraform Plan
  ___ _ __   __ _ _   _  ___ _ __ _   _
 / __| '_ \ / _` | | | |/ _ \ '__| | | |
| (__| | | | (_| | |_| |  __/ |  | |_| |
 \___|_| |_|\__, |\__,_|\___|_|   \__, |
  mondoo™      |_|                |___/  interactive shell

terraform.plan.variables: [
  0: terraform.plan.variable name="environment" value="dev"
]
cnquery>

This allows us to write queries like:

cnquery> terraform.plan.variables.where(value == "dev") {*}
terraform.plan.variables.where: [
  0: {
    value: "dev"
    name: "environment"
  }
]

Signed-off-by: Salim Afiune Maya <afiune@mondoo.com>

This comment has been minimized.

Copy link
Contributor

Test Results

3 209 tests  +1   3 205 ✅ +1   1m 40s ⏱️ -18s
  379 suites ±0       4 💤 ±0 
   29 files   ±0       0 ❌ ±0 

Results for commit 242727b. ± Comparison against base commit 35e8551.

Signed-off-by: Salim Afiune Maya <afiune@mondoo.com>

This comment has been minimized.

@@ -167,6 +167,12 @@ terraform.plan {
terraformVersion string
// Resource changes
resourceChanges() []terraform.plan.resourceChange
// Variables used to generate the Terraform plan
variables []terraform.plan.variable
// Indicates if the plan is applyable or not
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Indicates if the plan is applyable or not
// Whether `apply` is valid for the plan

As much fun as it can be to make up words, how's this alternative? 😁

variables []terraform.plan.variable
// Indicates if the plan is applyable or not
applyable bool
// Indicates if the plan errored or not
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Indicates if the plan errored or not
// Whether the plan errored

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!! I was following patterns in other places within this file, maybe we need a massive update in a few other providers 😅

Signed-off-by: Salim Afiune Maya <afiune@mondoo.com>
@misterpantz
Copy link
Contributor

It's a work of art. I have just a couple language suggestions.
make-face-mona-lisa

This comment has been minimized.

// Variables used to generate the Terraform plan
variables []terraform.plan.variable
// Whether `apply` is valid for the plan
applyable bool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe canApply?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed and agreed that applyable is coming from Terraform plan output itself, so we will adopt the same name for consistency. cc @misterpantz

Signed-off-by: Salim Afiune Maya <afiune@mondoo.com>
@afiune afiune merged commit 54e3b3e into main Jan 22, 2025
7 checks passed
@afiune afiune deleted the afiune/terraform/plan-variables branch January 22, 2025 20:39
@github-actions github-actions bot locked and limited conversation to collaborators Jan 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants