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: Secret resource #3110

Merged
merged 73 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
73 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
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
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
bdb7fff
refactor after Kuba re-review comments
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
b202fdd
Merge branch 'main' into secret-resource
sfc-gh-fbudzynski Oct 15, 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
24 changes: 14 additions & 10 deletions MIGRATION_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@ across different versions.
> [!TIP]
> We highly recommend upgrading the versions one by one instead of bulk upgrades.

## v0.97.0 ➞ v0.98.0

### *(new feature)* Secret resources
Added a new secrets resources for managing secrets.
We decided to split each secret flow into individual resources.
This segregation was based on the secret flows in CREATE SECRET. i.e.:
- `snowflake_secret_with_client_credentials`
- `snowflake_secret_with_authorization_code_grant`
- `snowflake_secret_with_basic_authentication`
- `snowflake_secret_with_generic_string`


See reference [docs](https://docs.snowflake.com/en/sql-reference/sql/create-secret).

## v0.96.0 ➞ v0.97.0

### *(new feature)* snowflake_stream_on_table, snowflake_stream_on_external_table resource
Expand Down Expand Up @@ -50,16 +64,6 @@ resource "snowflake_stream_on_table" "stream" {

Then, follow our [Resource migration guide](https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/docs/technical-documentation/resource_migration.md).

### *(new feature)* Secret resources
Added a new secrets resources for managing secrets.
We decided to split each secret flow into individual resources, i.e.:
- `snowflake_secret_with_client_credentials`
- `snowflake_secret_with_authorization_code_grant`
- `snowflake_secret_with_basic_authentication`
- `snowflake_secret_with_generic_string`

See reference [docs](https://docs.snowflake.com/en/sql-reference/sql/create-secret).

### *(new feature)* new snowflake_service_user and snowflake_legacy_service_user resources

Release v0.95.0 introduced reworked `snowflake_user` resource. As [noted](#note-user-types), the new `SERVICE` and `LEGACY_SERVICE` user types were not supported.
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/secret_with_authorization_code_grant.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: |-
Resource used to manage secret objects with OAuth Authorization Code Grant. For more information, check secret documentation https://docs.snowflake.com/en/sql-reference/sql/create-secret.
---

sfc-gh-jcieslak marked this conversation as resolved.
Show resolved Hide resolved
!> **V1 release candidate** This resource is a release candidate for the V1. It is on the list of remaining GA objects for V1. We do not expect significant changes in it before the V1. We will welcome any feedback and adjust the resource if needed. Any errors reported will be resolved with a higher priority. We encourage checking this resource out before the V1 release. Please follow the [migration guide](https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/MIGRATION_GUIDE.md#v0960--v0970) to use it.
!> **V1 release candidate** This resource is a release candidate for the V1. It is on the list of remaining GA objects for V1. We do not expect significant changes in it before the V1. We will welcome any feedback and adjust the resource if needed. Any errors reported will be resolved with a higher priority. We encourage checking this resource out before the V1 release. Please follow the [migration guide](https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/MIGRATION_GUIDE.md#v0970--v0980) to use it.

# snowflake_secret_with_authorization_code_grant (Resource)

Expand Down
4 changes: 2 additions & 2 deletions docs/resources/secret_with_basic_authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: |-
Resource used to manage secret objects with Basic Authentication. For more information, check secret documentation https://docs.snowflake.com/en/sql-reference/sql/create-secret.
---

!> **V1 release candidate** This resource is a release candidate for the V1. It is on the list of remaining GA objects for V1. We do not expect significant changes in it before the V1. We will welcome any feedback and adjust the resource if needed. Any errors reported will be resolved with a higher priority. We encourage checking this resource out before the V1 release. Please follow the [migration guide](https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/MIGRATION_GUIDE.md#v0960--v0970) to use it.
!> **V1 release candidate** This resource is a release candidate for the V1. It is on the list of remaining GA objects for V1. We do not expect significant changes in it before the V1. We will welcome any feedback and adjust the resource if needed. Any errors reported will be resolved with a higher priority. We encourage checking this resource out before the V1 release. Please follow the [migration guide](https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/MIGRATION_GUIDE.md#v0970--v0980) to use it.

# snowflake_secret_with_basic_authentication (Resource)

Expand Down Expand Up @@ -45,7 +45,7 @@ resource "snowflake_secret_with_basic_authentication" "test" {
- `name` (String) String that specifies the identifier (i.e. name) for the secret, must be unique in your schema. Due to technical limitations (read more [here](https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/docs/technical-documentation/identifiers_rework_design_decisions.md#known-limitations-and-identifier-recommendations)), avoid using the following characters: `|`, `.`, `(`, `)`, `"`
- `password` (String, Sensitive) Specifies the password value to store in the secret. External changes for this field won't be detected. In case you want to apply external changes, you can re-create the resource manually using "terraform taint".
- `schema` (String) The schema in which to create the secret. Due to technical limitations (read more [here](https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/docs/technical-documentation/identifiers_rework_design_decisions.md#known-limitations-and-identifier-recommendations)), avoid using the following characters: `|`, `.`, `(`, `)`, `"`
- `username` (String) Specifies the username value to store in the secret.
- `username` (String, Sensitive) Specifies the username value to store in the secret.

### Optional

Expand Down
2 changes: 1 addition & 1 deletion docs/resources/secret_with_client_credentials.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: |-
Resource used to manage secret objects with OAuth Client Credentials. For more information, check secret documentation https://docs.snowflake.com/en/sql-reference/sql/create-secret.
---

!> **V1 release candidate** This resource is a release candidate for the V1. It is on the list of remaining GA objects for V1. We do not expect significant changes in it before the V1. We will welcome any feedback and adjust the resource if needed. Any errors reported will be resolved with a higher priority. We encourage checking this resource out before the V1 release. Please follow the [migration guide](https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/MIGRATION_GUIDE.md#v0960--v0970) to use it.
!> **V1 release candidate** This resource is a release candidate for the V1. It is on the list of remaining GA objects for V1. We do not expect significant changes in it before the V1. We will welcome any feedback and adjust the resource if needed. Any errors reported will be resolved with a higher priority. We encourage checking this resource out before the V1 release. Please follow the [migration guide](https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/MIGRATION_GUIDE.md#v0970--v0980) to use it.

# snowflake_secret_with_client_credentials (Resource)

Expand Down
2 changes: 1 addition & 1 deletion docs/resources/secret_with_generic_string.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: |-
Resource used to manage secret objects with Generic String. For more information, check secret documentation https://docs.snowflake.com/en/sql-reference/sql/create-secret.
---

!> **V1 release candidate** This resource is a release candidate for the V1. It is on the list of remaining GA objects for V1. We do not expect significant changes in it before the V1. We will welcome any feedback and adjust the resource if needed. Any errors reported will be resolved with a higher priority. We encourage checking this resource out before the V1 release. Please follow the [migration guide](https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/MIGRATION_GUIDE.md#v0960--v0970) to use it.
!> **V1 release candidate** This resource is a release candidate for the V1. It is on the list of remaining GA objects for V1. We do not expect significant changes in it before the V1. We will welcome any feedback and adjust the resource if needed. Any errors reported will be resolved with a higher priority. We encourage checking this resource out before the V1 release. Please follow the [migration guide](https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/MIGRATION_GUIDE.md#v0970--v0980) to use it.

# snowflake_secret_with_generic_string (Resource)

Expand Down
1 change: 1 addition & 0 deletions pkg/acceptance/bettertestspoc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ it will result in:
- Add support for datasource tests (assertions and config builders).
- Consider overriding the assertions when invoking same check multiple times with different params (e.g. `Warehouse(...).HasType(X).HasType(Y)`; it could use the last-check-wins approach, to more easily reuse complex checks between the test steps).
- Consider not adding the check for `show_output` presence on creation (same with `parameters`). The majority of the use cases need it to be present but there are a few others (like conditional presence in the datasources). Currently, it seems that they should be always present in the resources, so no change is made. Later, with adding the support for the datasource tests, consider simple destructive implementation like:
- Add support for `set` so that assertions like e.g. `oauth_scopes.*` could be done.
```go
func (w *WarehouseDatasourceShowOutputAssert) IsEmpty() {
w.assertions = make([]resourceAssertion, 0)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 18 additions & 9 deletions pkg/resources/secret_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import (
"context"
"errors"

"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/provider"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/schemas"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

Expand Down Expand Up @@ -62,21 +64,13 @@ func handleSecretImport(d *schema.ResourceData) error {
return nil
}

func handleSecretCreate(d *schema.ResourceData) (database, schema, name string) {
return d.Get("database").(string), d.Get("schema").(string), d.Get("name").(string)
}

func handleSecretRead(d *schema.ResourceData, id sdk.SchemaObjectIdentifier, secret *sdk.Secret, secretDescription *sdk.SecretDetails) error {
err := errors.Join(
return errors.Join(
d.Set(FullyQualifiedNameAttributeName, id.FullyQualifiedName()),
d.Set("comment", secret.Comment),
d.Set(ShowOutputAttributeName, []map[string]any{schemas.SecretToSchema(secret)}),
d.Set(DescribeOutputAttributeName, []map[string]any{schemas.SecretDescriptionToSchema(*secretDescription)}),
)
if err != nil {
return err
}
return nil
}

func handleSecretUpdate(d *schema.ResourceData, set *sdk.SecretSetRequest, unset *sdk.SecretUnsetRequest) {
Expand All @@ -88,3 +82,18 @@ func handleSecretUpdate(d *schema.ResourceData, set *sdk.SecretSetRequest, unset
}
}
}

func DeleteContextSecret(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
client := meta.(*provider.Context).Client
id, err := sdk.ParseSchemaObjectIdentifier(d.Id())
if err != nil {
return diag.FromErr(err)
}

if err := client.Secrets.Drop(ctx, sdk.NewDropSecretRequest(id).WithIfExists(true)); err != nil {
return diag.FromErr(err)
}

d.SetId("")
return nil
}
41 changes: 17 additions & 24 deletions pkg/resources/secret_with_basic_authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/provider"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

Expand All @@ -19,6 +20,7 @@ var secretBasicAuthenticationSchema = func() map[string]*schema.Schema {
"username": {
Type: schema.TypeString,
Required: true,
Sensitive: true,
Description: "Specifies the username value to store in the secret.",
},
"password": {
Expand All @@ -36,9 +38,15 @@ func SecretWithBasicAuthentication() *schema.Resource {
CreateContext: CreateContextSecretWithBasicAuthentication,
ReadContext: ReadContextSecretWithBasicAuthentication,
UpdateContext: UpdateContextSecretWithBasicAuthentication,
DeleteContext: DeleteContextSecretWithBasicAuthentication,
DeleteContext: DeleteContextSecret,
Description: "Resource used to manage secret objects with Basic Authentication. For more information, check [secret documentation](https://docs.snowflake.com/en/sql-reference/sql/create-secret).",

CustomizeDiff: customdiff.All(
ComputedIfAnyAttributeChanged(secretBasicAuthenticationSchema, ShowOutputAttributeName, "name", "comment"),
ComputedIfAnyAttributeChanged(secretBasicAuthenticationSchema, DescribeOutputAttributeName, "name", "username"),
ComputedIfAnyAttributeChanged(secretBasicAuthenticationSchema, FullyQualifiedNameAttributeName, "name"),
),

Schema: secretBasicAuthenticationSchema,
sfc-gh-jmichalak marked this conversation as resolved.
Show resolved Hide resolved
Importer: &schema.ResourceImporter{
StateContext: ImportSecretWithBasicAuthentication,
Expand Down Expand Up @@ -72,7 +80,7 @@ func ImportSecretWithBasicAuthentication(ctx context.Context, d *schema.Resource

func CreateContextSecretWithBasicAuthentication(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
client := meta.(*provider.Context).Client
databaseName, schemaName, name := handleSecretCreate(d)
databaseName, schemaName, name := d.Get("database").(string), d.Get("schema").(string), d.Get("name").(string)
id := sdk.NewSchemaObjectIdentifier(databaseName, schemaName, name)

usernameString := d.Get("username").(string)
Expand Down Expand Up @@ -143,20 +151,20 @@ func UpdateContextSecretWithBasicAuthentication(ctx context.Context, d *schema.R
set := &sdk.SecretSetRequest{}
unset := &sdk.SecretUnsetRequest{}
handleSecretUpdate(d, set, unset)
setForFlow := &sdk.SetForFlowRequest{
SetForBasicAuthentication: &sdk.SetForBasicAuthenticationRequest{},
}
setForBasicAuthentication := &sdk.SetForBasicAuthenticationRequest{}

if d.HasChange("username") {
username := d.Get("username").(string)
setForFlow.SetForBasicAuthentication.WithUsername(username)
set.WithSetForFlow(*setForFlow)
setForBasicAuthentication.WithUsername(username)
}

if d.HasChange("password") {
password := d.Get("password").(string)
setForFlow.SetForBasicAuthentication.WithPassword(password)
set.WithSetForFlow(*setForFlow)
setForBasicAuthentication.WithPassword(password)
}

if !reflect.DeepEqual(*setForBasicAuthentication, sdk.SetForBasicAuthenticationRequest{}) {
sfc-gh-asawicki marked this conversation as resolved.
Show resolved Hide resolved
set.WithSetForFlow(sdk.SetForFlowRequest{SetForBasicAuthentication: setForBasicAuthentication})
}

if !reflect.DeepEqual(*set, sdk.SecretSetRequest{}) {
Expand All @@ -173,18 +181,3 @@ func UpdateContextSecretWithBasicAuthentication(ctx context.Context, d *schema.R

return ReadContextSecretWithBasicAuthentication(ctx, d, meta)
}

func DeleteContextSecretWithBasicAuthentication(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
client := meta.(*provider.Context).Client
id, err := sdk.ParseSchemaObjectIdentifier(d.Id())
if err != nil {
return diag.FromErr(err)
}

if err := client.Secrets.Drop(ctx, sdk.NewDropSecretRequest(id).WithIfExists(true)); err != nil {
return diag.FromErr(err)
}

d.SetId("")
return nil
}
47 changes: 32 additions & 15 deletions pkg/resources/secret_with_basic_authentication_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestAcc_SecretWithBasicAuthentication_BasicFlow(t *testing.T) {
resourceshowoutputassert.SecretShowOutput(t, secretName).
HasName(name).
HasDatabaseName(id.DatabaseName()).
HasSecretType("PASSWORD").
HasSecretType(sdk.SecretTypePassword).
HasSchemaName(id.SchemaName()).
HasComment(""),
),
Expand All @@ -67,8 +67,9 @@ func TestAcc_SecretWithBasicAuthentication_BasicFlow(t *testing.T) {
resource.TestCheckResourceAttr(secretName, "describe_output.0.name", name),
resource.TestCheckResourceAttr(secretName, "describe_output.0.database_name", id.DatabaseName()),
resource.TestCheckResourceAttr(secretName, "describe_output.0.schema_name", id.SchemaName()),
resource.TestCheckResourceAttr(secretName, "describe_output.0.secret_type", "PASSWORD"),
resource.TestCheckResourceAttr(secretName, "describe_output.0.secret_type", sdk.SecretTypePassword),
Copy link
Collaborator

Choose a reason for hiding this comment

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

with the separate type change you will have to do sdk.SecretTypePassword -> string(sdk.SecretTypePassword) in multiple tests

Copy link
Collaborator Author

@sfc-gh-fbudzynski sfc-gh-fbudzynski Oct 16, 2024

Choose a reason for hiding this comment

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

It will be changed in a PR with the secret type change

Copy link
Collaborator

Choose a reason for hiding this comment

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

okay, I will keep this open then

resource.TestCheckResourceAttr(secretName, "describe_output.0.username", "foo"),
resource.TestCheckResourceAttr(secretName, "describe_output.0.comment", ""),
resource.TestCheckResourceAttr(secretName, "describe_output.0.oauth_access_token_expiry_time", ""),
resource.TestCheckResourceAttr(secretName, "describe_output.0.oauth_refresh_token_expiry_time", ""),
resource.TestCheckResourceAttr(secretName, "describe_output.0.integration_name", ""),
Expand All @@ -78,23 +79,39 @@ func TestAcc_SecretWithBasicAuthentication_BasicFlow(t *testing.T) {
// set username, password and comment
{
Config: config.FromModel(t, secretModelDifferentCredentialsWithComment),
Check: assert.AssertThat(t,
resourceassert.SecretWithBasicAuthenticationResource(t, secretName).
HasNameString(name).
HasDatabaseString(id.DatabaseName()).
HasSchemaString(id.SchemaName()).
HasUsernameString("bar").
HasPasswordString("bar").
HasCommentString(comment),
Check: resource.ComposeTestCheckFunc(
assert.AssertThat(t,

resourceassert.SecretWithBasicAuthenticationResource(t, secretName).
HasNameString(name).
HasDatabaseString(id.DatabaseName()).
HasSchemaString(id.SchemaName()).
HasUsernameString("bar").
HasPasswordString("bar").
HasCommentString(comment),

resourceshowoutputassert.SecretShowOutput(t, secretName).
HasSecretType(sdk.SecretTypePassword).
HasComment(comment),
),

resource.TestCheckResourceAttr(secretName, "describe_output.0.username", "bar"),
resource.TestCheckResourceAttr(secretName, "describe_output.0.comment", comment),
),
},
// set username and comment externally
{
PreConfig: func() {
acc.TestClient().Secret.Alter(t, sdk.NewAlterSecretRequest(id).WithSet(*sdk.NewSecretSetRequest().
WithComment("test_comment").
WithSetForFlow(*sdk.NewSetForFlowRequest().WithSetForBasicAuthentication(*sdk.NewSetForBasicAuthenticationRequest().WithUsername("test_username"))),
))
acc.TestClient().Secret.Alter(t, sdk.NewAlterSecretRequest(id).
WithSet(*sdk.NewSecretSetRequest().
WithComment("test_comment").
WithSetForFlow(*sdk.NewSetForFlowRequest().
WithSetForBasicAuthentication(*sdk.NewSetForBasicAuthenticationRequest().
WithUsername("test_username"),
),
),
),
)
},
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
Expand Down Expand Up @@ -159,7 +176,7 @@ func TestAcc_SecretWithBasicAuthentication_BasicFlow(t *testing.T) {
importchecks.TestCheckResourceAttrInstanceState(helpers.EncodeResourceIdentifier(id), "comment", ""),
),
},
// create with empty username and password
// set empty username and password
{
Config: config.FromModel(t, secretModelEmptyCredentials),
Check: resource.ComposeTestCheckFunc(
sfc-gh-jmichalak marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Loading
Loading