-
Notifications
You must be signed in to change notification settings - Fork 427
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Masking policy data source v1 (#3083)
<!-- Feel free to delete comments as you fill this in --> - adjust filtering options - move output to `*_output` fields - extract common code for easier reuse - link new issue to one of the resources <!-- summary of changes --> ## Test Plan <!-- detail ways in which this PR has been tested or needs to be tested --> * [x] acceptance tests <!-- add more below if you think they are relevant --> ## References <!-- issues documentation links, etc --> https://docs.snowflake.com/en/sql-reference/sql/show-masking-policies
- Loading branch information
1 parent
fa4ce56
commit 2553fbf
Showing
21 changed files
with
919 additions
and
140 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
85 changes: 81 additions & 4 deletions
85
examples/data-sources/snowflake_masking_policies/data-source.tf
This file contains 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,81 @@ | ||
data "snowflake_masking_policies" "current" { | ||
database = "MYDB" | ||
schema = "MYSCHEMA" | ||
} | ||
# Simple usage | ||
data "snowflake_masking_policies" "simple" { | ||
} | ||
|
||
output "simple_output" { | ||
value = data.snowflake_masking_policies.simple.masking_policies | ||
} | ||
|
||
# Filtering (like) | ||
data "snowflake_masking_policies" "like" { | ||
like = "masking-policy-name" | ||
} | ||
|
||
output "like_output" { | ||
value = data.snowflake_masking_policies.like.masking_policies | ||
} | ||
|
||
# Filtering by prefix (like) | ||
data "snowflake_masking_policies" "like_prefix" { | ||
like = "prefix%" | ||
} | ||
|
||
output "like_prefix_output" { | ||
value = data.snowflake_masking_policies.like_prefix.masking_policies | ||
} | ||
|
||
# Filtering (limit) | ||
data "snowflake_masking_policies" "limit" { | ||
limit { | ||
rows = 10 | ||
from = "prefix-" | ||
} | ||
} | ||
|
||
output "limit_output" { | ||
value = data.snowflake_masking_policies.limit.masking_policies | ||
} | ||
|
||
# Filtering (in) | ||
data "snowflake_masking_policies" "in" { | ||
in { | ||
database = "database" | ||
} | ||
} | ||
|
||
output "in_output" { | ||
value = data.snowflake_masking_policies.in.masking_policies | ||
} | ||
|
||
# Without additional data (to limit the number of calls make for every found masking policy) | ||
data "snowflake_masking_policies" "only_show" { | ||
# with_describe is turned on by default and it calls DESCRIBE MASKING POLICY for every masking policy found and attaches its output to masking_policies.*.describe_output field | ||
with_describe = false | ||
} | ||
|
||
output "only_show_output" { | ||
value = data.snowflake_masking_policies.only_show.masking_policies | ||
} | ||
|
||
# Ensure the number of masking policies is equal to at least one element (with the use of postcondition) | ||
data "snowflake_masking_policies" "assert_with_postcondition" { | ||
like = "masking-policy-name%" | ||
lifecycle { | ||
postcondition { | ||
condition = length(self.masking_policies) > 0 | ||
error_message = "there should be at least one masking policy" | ||
} | ||
} | ||
} | ||
|
||
# Ensure the number of masking policies is equal to at exactly one element (with the use of check block) | ||
check "masking_policy_check" { | ||
data "snowflake_masking_policies" "assert_with_check_block" { | ||
like = "masking-policy-name" | ||
} | ||
|
||
assert { | ||
condition = length(data.snowflake_masking_policies.assert_with_check_block.masking_policies) == 1 | ||
error_message = "masking policies filtered by '${data.snowflake_masking_policies.assert_with_check_block.like}' returned ${length(data.snowflake_masking_policies.assert_with_check_block.masking_policies)} masking policies where one was expected" | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...ceptance/bettertestspoc/assert/resourceshowoutputassert/masking_policy_show_output_ext.go
This file contains 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,10 +1,23 @@ | ||
package resourceshowoutputassert | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert" | ||
) | ||
|
||
func (p *MaskingPolicyShowOutputAssert) HasCreatedOnNotEmpty() *MaskingPolicyShowOutputAssert { | ||
p.AddAssertion(assert.ResourceShowOutputValuePresent("created_on")) | ||
return p | ||
} | ||
|
||
// MaskingPoliciesDatasourceShowOutput is a temporary workaround to have better show output assertions in data source acceptance tests. | ||
func MaskingPoliciesDatasourceShowOutput(t *testing.T, name string) *MaskingPolicyShowOutputAssert { | ||
t.Helper() | ||
|
||
m := MaskingPolicyShowOutputAssert{ | ||
ResourceAssert: assert.NewDatasourceAssert("data."+name, "show_output", "masking_policies.0."), | ||
} | ||
m.AddAssertion(assert.ValueSet("show_output.#", "1")) | ||
return &m | ||
} |
Oops, something went wrong.