generated from cloudposse/terraform-example-module
-
Notifications
You must be signed in to change notification settings - Fork 0
feat(outputs)!: breaking change, add sensitive true to outputs + add tests #17
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
cce52c6
feat: add some basic tests for this repo
westonplatter befbd3d
breaking change: add sensitive true to outputs
westonplatter 1c1b891
fix: used 1 test to get to the core logic
westonplatter 4d9b127
compact some more tests
westonplatter f4cdf25
try to compact more, but found worthwhile diffs
westonplatter e9a285c
fix: remove the main tests. the data isn't core
westonplatter 0f8e19f
fix: remove redundant tests
westonplatter 9d62e6c
feat: add tests for outputs
westonplatter 132c151
Merge branch 'main' into feat/add-tests
gberenice 1180dbf
Merge branch 'main' into feat/add-tests
Gowiem File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
output "all" { | ||
value = local.secrets | ||
description = "The final secrets pulled from various sources." | ||
sensitive = true | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
mock_provider "sops" { | ||
mock_data "sops_file" { | ||
defaults = { | ||
raw = "db_password: supersecret123\napi_key: test-api-key-456" | ||
} | ||
} | ||
} | ||
|
||
run "test_empty_secret_mapping" { | ||
command = plan | ||
|
||
variables { | ||
secret_mapping = [] | ||
} | ||
|
||
assert { | ||
condition = length(local.secrets) == 0 | ||
error_message = "Empty input should result in empty final secrets" | ||
} | ||
} | ||
|
||
run "test_multiple_files_and_secrets" { | ||
command = plan | ||
|
||
variables { | ||
secret_mapping = [ | ||
{ | ||
name = "db_password" | ||
type = "sops" | ||
file = "database.yaml" | ||
}, | ||
{ | ||
name = "api_key" | ||
type = "sops" | ||
file = "api.yaml" | ||
}, | ||
{ | ||
name = "redis_password" | ||
type = "sops" | ||
file = "database.yaml" | ||
} | ||
] | ||
} | ||
|
||
assert { | ||
condition = length(local.sops_secret_mapping) == 3 | ||
error_message = "Should have 3 sops secret mappings" | ||
} | ||
|
||
assert { | ||
condition = ( | ||
length(local.sops_files) == 2 | ||
&& contains(local.sops_files, "database.yaml") | ||
&& contains(local.sops_files, "api.yaml") | ||
) | ||
error_message = "Should have 2 unique sops files (database.yaml and api.yaml)" | ||
} | ||
|
||
assert { | ||
condition = length(local.sops_yamls) == 2 | ||
error_message = "Should have 2 YAML files loaded in sops_yamls" | ||
} | ||
|
||
assert { | ||
condition = length(local.sops_secrets) == 3 | ||
error_message = "Should have 3 secrets in sops_secrets map" | ||
} | ||
|
||
assert { | ||
condition = alltrue([ | ||
for mapping in local.sops_secret_mapping : | ||
contains(keys(local.sops_secrets), mapping.name) | ||
]) | ||
error_message = "All secret mappings should result in corresponding secret names" | ||
} | ||
|
||
assert { | ||
condition = length(distinct(keys(local.sops_secrets))) == length(keys(local.sops_secrets)) | ||
error_message = "All secret keys should be unique" | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
mock_provider "sops" { | ||
mock_data "sops_file" { | ||
defaults = { | ||
raw = "db_password: supersecret123\napi_key: test-api-key-456\nredis_password: redis-secret-789" | ||
} | ||
} | ||
} | ||
|
||
run "test_output_structure_and_content" { | ||
command = plan | ||
|
||
variables { | ||
secret_mapping = [ | ||
{ | ||
name = "db_password" | ||
type = "sops" | ||
file = "database.yaml" | ||
}, | ||
{ | ||
name = "api_key" | ||
type = "sops" | ||
file = "api.yaml" | ||
} | ||
] | ||
} | ||
|
||
assert { | ||
condition = output.all["db_password"] == "supersecret123" | ||
error_message = "db_password should have the expected value from mocked SOPS data" | ||
} | ||
|
||
assert { | ||
condition = output.all["api_key"] == "test-api-key-456" | ||
error_message = "api_key should have the expected value from mocked SOPS data" | ||
} | ||
|
||
assert { | ||
condition = !contains(keys(output.all), "redis_password") | ||
error_message = "redis_password should not be in the output" | ||
} | ||
|
||
assert { | ||
condition = length(output.all) == 2 | ||
error_message = "Output should contain exactly 2 secrets" | ||
} | ||
} | ||
|
||
run "test_output_empty_secrets" { | ||
command = plan | ||
|
||
variables { | ||
secret_mapping = [] | ||
} | ||
|
||
assert { | ||
condition = length(output.all) == 0 | ||
error_message = "Output should be empty when no secrets are configured" | ||
} | ||
|
||
assert { | ||
condition = output.all == {} | ||
error_message = "Output should be an empty map when no secrets are configured" | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You call this out as a breaking change in the PR title, but I'm not sure it is. Mind sharing why you're considering this a breaking change? It changes the output of this module, but I would just call that a feature enhancement, not a breaking change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am expecting that adding
sensitive = true
requires downstream child or root modules then also mark the output as sensitive. My practical concern is that users would need to make a code change on their end in order to get terraform plan/applies to run.For example, https://developer.hashicorp.com/terraform/tutorials/configuration-language/sensitive-variables#reference-sensitive-variables

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, this is interesting. I wasn't aware of this behaviour, but we have to treat this as a breaking change indeed.

@westonplatter could you please rename a PR title to reflect this:
feat(outputs)!: add sensitive true to outputs + add tests)
, so release-please correctly generates the release.Also, we should ensure that this is described in the release notes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@westonplatter good thinking in terms of this breaking downstream outputs, you're obviously right that this is a breaking change 💯 👍