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

Fix issue where steampipe.spvars was not respected in a mod #236

Merged
merged 3 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions internal/cmdconfig/app_specific.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func SetAppSpecificConstants() {
app_specific.DefaultConfigPath = strings.Join([]string{".", globalConfigPath}, ":")

app_specific.DefaultVarsFileName = "powerpipe.ppvars"
app_specific.LegacyDefaultVarsFileName = "steampipe.spvars"
// default to local steampipe service
app_specific.DefaultDatabase = "postgres://[email protected]:9193/steampipe"

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# test_workspace_mod_var_precedence_set_from_steampipe_spvars

### Description

This mod is used to test variable resolution precedence in a mod by passing a steampipe.spvars file. The mod also has a default value of variable 'version' set.

### Usage

This mod is used in the tests in `mod_vars.bats` to simulate a scenario where the version defined in the mod is picked from the steampipe.spvars over the default value of variable 'version' set in the mod, because steampipe.spvars have higher precendence.

Steampipe loads variables in the following order, with later sources taking precedence over earlier ones:

1. Environment variables
2. The steampipe.spvars file, if present.
3. Any *.auto.spvars files, in alphabetical order by filename.
4. Any --var and --var-file options on the command line, in the order they are provided.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
mod "test_vars_workspace_mod" {
title = "test_vars_workspace_mod"
}

query "version" {
sql = "select $1::text as reason, $1::text as resource, 'ok' as status"
param "p1"{
description = "p1"
default = var.version
}
}

variable "version"{
type = string
default = "v2.0.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version = "v7.0.0"
15 changes: 15 additions & 0 deletions tests/acceptance/test_files/sp_files.bats
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@ load "$LIB_BATS_SUPPORT/load.bash"

### spvars file tests ###

@test "test variable resolution in workspace mod set from steampipe.spvars file" {
cd $FILE_PATH/test_data/mods/test_workspace_mod_var_precedence_set_from_steampipe_spvars

run powerpipe query run query.version --output csv
# check the output - query should use the value of variable set from the steampipe.spvars
# file ("v7.0.0") which will give the output:
# +--------+----------+--------+
# | reason | resource | status |
# +--------+----------+--------+
# | v7.0.0 | v7.0.0 | ok |
# +--------+----------+--------+
assert_output 'reason,resource,status
v7.0.0,v7.0.0,ok'
}

@test "test variable resolution in workspace mod set from explicit spvars file" {
cd $FILE_PATH/test_data/mods/test_workspace_mod_var_set_from_explicit_spvars

Expand Down
Loading