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

feat: Secrets datasource #3131

Merged
merged 93 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
58d5794
initial secret_def file for sdk
sfc-gh-fbudzynski Sep 12, 2024
f1488ca
naming changes to secret create options
sfc-gh-fbudzynski Sep 12, 2024
752f924
create secrets and alter with two basic tests
sfc-gh-fbudzynski Sep 13, 2024
d7ae12f
unit tests for alter
sfc-gh-fbudzynski Sep 13, 2024
57ca19a
add tests for all four create types
sfc-gh-fbudzynski Sep 13, 2024
8d55a63
rename previous secret to secretReference in common_types.go due to n…
sfc-gh-fbudzynski Sep 16, 2024
9894799
secrets gen with drop, show and desc
sfc-gh-fbudzynski Sep 16, 2024
e4a0827
all unit tests
sfc-gh-fbudzynski Sep 16, 2024
3bb8c85
init for integration tests
sfc-gh-fbudzynski Sep 16, 2024
4130618
added secret to client.go and created secret_client
sfc-gh-fbudzynski Sep 17, 2024
fc85c66
added like and in to showByID for secret
sfc-gh-fbudzynski Sep 17, 2024
aa64511
init for integration tests
sfc-gh-fbudzynski Sep 17, 2024
ab8bee1
secret_def changes
sfc-gh-fbudzynski Sep 17, 2024
3541c70
tests for two methods of creating secret
sfc-gh-fbudzynski Sep 17, 2024
180a7ce
changed refresh token expiry time from string to time.Time
sfc-gh-fbudzynski Sep 18, 2024
7a9ad92
added remaining integration tests
sfc-gh-fbudzynski Sep 19, 2024
0e9cf94
linter
sfc-gh-fbudzynski Sep 19, 2024
deadc65
linting
sfc-gh-fbudzynski Sep 19, 2024
235fbe5
removing comment
sfc-gh-fbudzynski Sep 19, 2024
73eeb63
mid review commit before generating assertions
sfc-gh-fbudzynski Sep 20, 2024
bd0b64f
rebase conflict resolved
sfc-gh-fbudzynski Sep 23, 2024
2050b85
tests pass after changing to []string for oauthScopes
sfc-gh-fbudzynski Sep 23, 2024
59c7b14
readded unit tests
sfc-gh-fbudzynski Sep 23, 2024
df7a8ff
added CreateApiAuthenticationWithRequest to security integration client
sfc-gh-fbudzynski Sep 24, 2024
eed310a
changes to secret after review, all tests pass
sfc-gh-fbudzynski Sep 24, 2024
af2e030
added assert for details
sfc-gh-fbudzynski Sep 24, 2024
4ccc4e7
linter hints applied
sfc-gh-fbudzynski Sep 24, 2024
34983af
updated generator README with validation issue for ConflictingFields …
sfc-gh-fbudzynski Sep 24, 2024
bdf2585
updated after re-review
sfc-gh-fbudzynski Sep 24, 2024
7791f33
test changed to use errMoreThanOneOf
sfc-gh-fbudzynski Sep 25, 2024
1f1fb2b
init commit for secret resource
sfc-gh-fbudzynski Sep 26, 2024
366313f
adding secret common to avoid duplication
sfc-gh-fbudzynski Sep 26, 2024
a383ac4
acc tests pass with usage of secret_common
sfc-gh-fbudzynski Sep 26, 2024
40179ec
Secret with authorization code acceptance test, diff suppress
sfc-gh-fbudzynski Sep 27, 2024
04d3feb
helper function for snowflake datetime for secret
sfc-gh-fbudzynski Sep 27, 2024
fa408fd
check destroy and few cleanups
sfc-gh-fbudzynski Sep 27, 2024
d3e54db
Wrapped OAuth Scopes in separate queryStructField to allow empty list…
sfc-gh-fbudzynski Sep 30, 2024
0e18136
Linter adjustments
sfc-gh-fbudzynski Sep 30, 2024
f60985c
init commit for secret resource
sfc-gh-fbudzynski Sep 26, 2024
8348809
adding secret common to avoid duplication
sfc-gh-fbudzynski Sep 26, 2024
4753096
acc tests pass with usage of secret_common
sfc-gh-fbudzynski Sep 26, 2024
46e2181
Secret with authorization code acceptance test, diff suppress
sfc-gh-fbudzynski Sep 27, 2024
c3f3ea7
helper function for snowflake datetime for secret
sfc-gh-fbudzynski Sep 27, 2024
91269d6
check destroy and few cleanups
sfc-gh-fbudzynski Sep 27, 2024
b91b97c
adding secret with basic authentication flow
sfc-gh-fbudzynski Sep 30, 2024
8de6e84
checking secret with optional oauth_scopes
sfc-gh-fbudzynski Sep 30, 2024
c64a1ed
secret basic authentication flow acceptance tests and fix for parsing…
sfc-gh-fbudzynski Oct 1, 2024
ccdf9f8
Merge remote-tracking branch 'origin/secret-resource' into secret-res…
sfc-gh-fbudzynski Oct 1, 2024
fde6908
removed unwanted duplicats after merge
sfc-gh-fbudzynski Oct 1, 2024
a147b99
All secret flows with acceptance tests and change to handle different…
sfc-gh-fbudzynski Oct 2, 2024
356d98c
linter pre-push changes
sfc-gh-fbudzynski Oct 2, 2024
83ccafc
generated documentation for each secret flow
sfc-gh-fbudzynski Oct 2, 2024
07dc9e2
Merge branch 'main' into secret-resource
sfc-gh-fbudzynski Oct 2, 2024
de99b68
delete unused _ext assert
sfc-gh-fbudzynski Oct 3, 2024
5c6d9ee
self-review cleanup
sfc-gh-fbudzynski Oct 3, 2024
805c61e
docs regenerate
sfc-gh-fbudzynski Oct 3, 2024
044c484
example resource naming fix for secret with generic_string
sfc-gh-fbudzynski Oct 3, 2024
bc43a72
docs fixes
sfc-gh-fbudzynski Oct 3, 2024
4ae36a4
make docs-check error fix
sfc-gh-fbudzynski Oct 3, 2024
4ac851a
Merge branch 'main' into secret-resource
sfc-gh-fbudzynski Oct 4, 2024
4ee377b
initial commit for secrets datasource
sfc-gh-fbudzynski Oct 4, 2024
ac37669
Merge branch 'main' into secret-resource
sfc-gh-fbudzynski Oct 7, 2024
f3cd4b1
Jakub comments resolved
sfc-gh-fbudzynski Oct 8, 2024
e098f69
comments resolved
sfc-gh-fbudzynski Oct 9, 2024
39f3cdd
Merge branch 'main' into secret-resource
sfc-gh-fbudzynski Oct 9, 2024
d5b6db0
added tests to check for external changes to refresh_token_expiry_tim…
sfc-gh-fbudzynski Oct 9, 2024
54a5451
Merge branch 'main' into secrets-datasource
sfc-gh-fbudzynski Oct 9, 2024
e304793
resolved to Arturs comments
sfc-gh-fbudzynski Oct 10, 2024
c1115fa
linter suggestions
sfc-gh-fbudzynski Oct 10, 2024
9dea35c
Merge branch 'main' into secret-resource
sfc-gh-fbudzynski Oct 10, 2024
5638d83
Merge branch 'main' into secrets-datasource
sfc-gh-fbudzynski Oct 10, 2024
92c8d25
linter suggestions
sfc-gh-fbudzynski Oct 10, 2024
bdb7fff
refactor after Kuba re-review comments
sfc-gh-fbudzynski Oct 11, 2024
bd2e172
Merge remote-tracking branch 'origin/secret-resource' into secrets-da…
sfc-gh-fbudzynski Oct 11, 2024
81a8312
linter and pre-push corrections
sfc-gh-fbudzynski Oct 11, 2024
dba8478
changes not to abuse pointer on models
sfc-gh-fbudzynski Oct 14, 2024
40ecd49
linter adjustments
sfc-gh-fbudzynski Oct 14, 2024
1a9a6db
changed username to sensitive, adjusted docs and migration guide to p…
sfc-gh-fbudzynski Oct 14, 2024
7573935
Merge branch 'secret-resource' of github.com:Snowflake-Labs/terraform…
sfc-gh-fbudzynski Oct 14, 2024
57bd2ce
datasource changes after review
sfc-gh-fbudzynski Oct 15, 2024
18f0307
fill more example usage
sfc-gh-fbudzynski Oct 15, 2024
b202fdd
Merge branch 'main' into secret-resource
sfc-gh-fbudzynski Oct 15, 2024
11531cf
re-generated docs
sfc-gh-fbudzynski Oct 15, 2024
9012bb9
changes to secret datasource docs
sfc-gh-fbudzynski Oct 15, 2024
7724d57
linter hint
sfc-gh-fbudzynski Oct 15, 2024
734ec99
fixed naming in tests for usage of resource show_output asserts
sfc-gh-fbudzynski Oct 15, 2024
5e8afaf
removed tests for IN application and resolved comments for review
sfc-gh-fbudzynski Oct 16, 2024
cc04648
Linter checks
sfc-gh-fbudzynski Oct 16, 2024
3ac5fbd
Merge branch 'secret-resource' into secrets-datasource
sfc-gh-fbudzynski Oct 16, 2024
da6223f
Merge branch 'main' into secrets-datasource
sfc-gh-fbudzynski Oct 17, 2024
8276a20
changed schema fully qualified name to proper value in examples and u…
sfc-gh-fbudzynski Oct 17, 2024
b0aed22
Merge branch 'secrets-datasource' of github.com:Snowflake-Labs/terraf…
sfc-gh-fbudzynski Oct 17, 2024
429071a
changed schema fully qualified name to proper value after main merge
sfc-gh-fbudzynski Oct 17, 2024
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
2 changes: 1 addition & 1 deletion docs/data-sources/secrets.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ output "like_prefix_output" {
# Filtering (in)
data "snowflake_secrets" "in" {
in {
schema = "schema_fully_qualified_name"
schema = "snowflake_schema.test.fully_qualified_name"
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/data-sources/snowflake_secrets/data-source.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ output "like_prefix_output" {
# Filtering (in)
data "snowflake_secrets" "in" {
in {
schema = "schema_fully_qualified_name"
schema = "snowflake_schema.test.fully_qualified_name"
sfc-gh-jcieslak marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/datasources/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,15 @@ func Secrets() *schema.Resource {

func ReadSecrets(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
client := meta.(*provider.Context).Client
req := *sdk.NewShowSecretRequest()
req := sdk.NewShowSecretRequest()

handleLike(d, &req.Like)
err := handleExtendedIn(d, &req.In)
if err != nil {
return diag.FromErr(err)
}

secrets, err := client.Secrets.Show(ctx, &req)
secrets, err := client.Secrets.Show(ctx, req)
if err != nil {
return diag.FromErr(err)
}
Expand Down
54 changes: 19 additions & 35 deletions pkg/datasources/secrets_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,15 +240,6 @@ func TestAcc_Secrets_Filtering(t *testing.T) {
)
t.Cleanup(apiIntegrationCleanup)

// ERROR Insufficient privileges to operate on account ... for role BASIC_PRIVILEGES
/*
appPkg, appPkgCleanup := acc.TestClient().ApplicationPackage.CreateApplicationPackage(t)
t.Cleanup(appPkgCleanup)

_, appCleanup := acc.TestClient().Application.CreateApplication(t, appPkg.ID(), "1")
t.Cleanup(appCleanup)
*/

schema, schemaCleanup := acc.TestClient().Schema.CreateSchemaInDatabase(t, acc.TestClient().Ids.DatabaseId())
t.Cleanup(schemaCleanup)

Expand Down Expand Up @@ -307,32 +298,13 @@ func TestAcc_Secrets_Filtering(t *testing.T) {
resource.TestCheckResourceAttr("data.snowflake_secrets.test", "secrets.#", "5"),
),
},
/*
// In Application Package
// ERROR Insufficient privileges to operate on account ... for role BASIC_PRIVILEGES
{
Config: multipleSecretModels + secretDatasourceWithIn("application_package", idFive.DatabaseId().FullyQualifiedName()),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("data.snowflake_secrets.test", "secrets.#", "5"),
),
},
// In Application
// ERROR Insufficient privileges to operate on account ... for role BASIC_PRIVILEGES
{
Config: multipleSecretModels + secretDatasourceWithIn("application", idFive.DatabaseId().FullyQualifiedName()),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("data.snowflake_secrets.test", "secrets.#", "5"),
),
},
// In Account
// ERROR Insufficient privileges to operate on 'SYSTEM' for role BASIC_PRIVILEGES
{
Config: multipleSecretModels + secretDatasourceWithIn("account", acc.TestClient().Account.GetAccountIdentifier(t).FullyQualifiedName()),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("data.snowflake_secrets.test", "secrets.#", "5"),
),
},
*/
// In Account
{
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: adjust the comment to highlight the filter is account + prefix - or remove prefix from this test, leaving only account param.

Config: multipleSecretModels + secretDatasourceInAccountWithLike(prefix+"%"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("data.snowflake_secrets.test", "secrets.#", "3"),
),
},
},
})
}
Expand All @@ -356,6 +328,18 @@ func secretDatasourceWithIn(objectName, objectFullyQualifiedName string) string
`, objectName, strings.ReplaceAll(objectFullyQualifiedName, `"`, ""))
}

func secretDatasourceInAccountWithLike(prefix string) string {
return fmt.Sprintf(`
data "snowflake_secrets" "test" {
depends_on = [snowflake_secret_with_basic_authentication.s, snowflake_secret_with_generic_string.s2, snowflake_secret_with_client_credentials.s3, snowflake_secret_with_authorization_code_grant.s4]
in {
account = true
}
like = "%s"
}
`, prefix)
}

func TestAcc_Secrets_EmptyIn(t *testing.T) {
resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories,
Expand Down
Loading