turbot / steampipe

Zero-ETL, infinite possibilities. Live query APIs, code & more with SQL. No DB required.
https://steampipe.io
GNU Affero General Public License v3.0
6.84k stars 264 forks source link

input mod resource behavior #3755

Closed bimlendupg closed 1 year ago

bimlendupg commented 1 year ago

Describe the bug I am trying to use input, specifically the base argument. It works mostly but I have found this issue.

If the base named input has static values using the option argument, using this named input as base for another input inside a dashboard results in the following error.

input does not define a query or SQL

Steampipe version (steampipe -v) ➜ ~ steampipe -v Steampipe v0.20.10

To reproduce Steps to reproduce the behavior (please include relevant code and/or commands).

Use the following code to reproduce.

locals {
  ec2_details = <<SQL
    SELECT
      title as identifier,
      region,
      account_id,
      tags ->> 'Name' AS name
    FROM
      aws_ec2_instance
    ORDER BY
      title
  SQL
}

input "base_input" {
  title = "Select resource compliance state"
  width = 4
  type  = "select"

  option "compliant" {
    label = "Compliant"
  }

  option "non-compliant" {
    label = "Non-Compliant"
  }
}

dashboard "resource_details_ec2_instances" {
  title = "Resource Details - EC2 Instances"

  input "resource_compliance_state" {
    base = input.base_input
  }

  #   input "resource_compliance_state" {
  #     title = "Select resource compliance state"
  #     width = 4
  #     type  = "select"

  #     option "compliant" {
  #       label = "Compliant"
  #     }

  #     option "non-compliant" {
  #       label = "Non-Compliant"
  #     }
  #   }

  table {
    width = 12
    sql   = local.ec2_details
  }
}

And run steampipe mod init and steampipe dashboard.

You will see the following error.

[ Error   ] Failed to decode all mod hcl files:
local.input.resource_compliance_state does not define a query or SQL

Expected behavior input inheritance should work as documented. If both sql and query are optional arguments, why does the error message hints that either one of them is required ?

Additional context Add any other context about the problem here.

pskrbasu commented 1 year ago

Hey @bimlendupg, thank you for reporting this. I have reproduced this and yes it seems like a bug. We will get it fixed soon.

The workaround for this to make it work right now would be:

locals {
  ec2_details = <<SQL
    SELECT
      title as identifier,
      region,
      account_id,
      tags ->> 'Name' AS name
    FROM
      aws_ec2_instance
    ORDER BY
      title
  SQL
}

dashboard "resource_details_ec2_instances" {
  title = "Resource Details - EC2 Instances"

  input "resource_compliance_state" {
    title = "Select resource compliance state"
    width = 4
    type  = "select"

    option "compliant" {
    label = "Compliant"
    }

    option "non-compliant" {
    label = "Non-Compliant"
    }

    table {
      width = 12
      sql   = local.ec2_details
    }
  }
}