Skip to content

Commit

Permalink
Add FQN to streamlits
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-jmichalak committed Aug 12, 2024
1 parent 00ae1c5 commit d92d1a3
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 2 deletions.
14 changes: 12 additions & 2 deletions MIGRATION_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,17 @@ across different versions.

## v0.94.x ➞ v0.95.0

### snowflake_warehouse resource changes
### New `fully_qualified_name` field in all resources.
We added a new `fully_qualified_name` to all resources. This should help with referencing other resources in fields that expect a fully qualified name. For example, instead of
writing

```object_name = “\”${snowflake_table.database}\”.\”${snowflake_table.schema}\”.\”${snowflake_table.name}\””```

now we can write

```object_name = snowflake_table.fully_qualified_name```

### snowflake_user resource changes

#### *(breaking change)* user parameters added to snowflake_user resource

Expand Down Expand Up @@ -461,7 +471,7 @@ resource "snowflake_database" "test" {
}
```

If you had `from_database` set, you should follow our [resource migration guide](https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/docs/technical-documentation/resource_migration.md) to remove
If you had `from_database` set, you should follow our [resource migration guide](https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/docs/technical-documentation/resource_migration.md) to remove
the database from state to later import it in the newer version of the provider.
Otherwise, it may cause issues when migrating to v0.93.0.
For now, we're dropping the possibility to create a clone database from other databases.
Expand Down
1 change: 1 addition & 0 deletions docs/resources/streamlit.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ resource "snowflake_streamlit" "streamlit" {
### Read-Only

- `describe_output` (List of Object) Outputs the result of `DESCRIBE STREAMLIT` for the given streamlit. (see [below for nested schema](#nestedatt--describe_output))
- `fully_qualified_name` (String) Fully qualified name of the resource. For more information, see [object name resolution](https://docs.snowflake.com/en/sql-reference/name-resolution).
- `id` (String) The ID of this resource.
- `show_output` (List of Object) Outputs the result of `SHOW STREAMLIT` for the given streamli. (see [below for nested schema](#nestedatt--show_output))

Expand Down
2 changes: 2 additions & 0 deletions pkg/resources/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

const FullyQualifiedNameAttributeName = "fully_qualified_name"

// DiffSuppressStatement will suppress diffs between statements if they differ in only case or in
// runs of whitespace (\s+ = \s). This is needed because the snowflake api does not faithfully
// round-trip queries, so we cannot do a simple character-wise comparison to detect changes.
Expand Down
5 changes: 5 additions & 0 deletions pkg/resources/streamlit.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ var streamlitSchema = map[string]*schema.Schema{
Schema: schemas.DescribeStreamlitSchema,
},
},
FullyQualifiedNameAttributeName: schemas.FullyQualifiedNameSchema,
}

func Streamlit() *schema.Resource {
Expand All @@ -113,6 +114,7 @@ func Streamlit() *schema.Resource {

CustomizeDiff: customdiff.All(
ComputedIfAnyAttributeChanged(ShowOutputAttributeName, "name", "title", "comment", "query_warehouse"),
ComputedIfAnyAttributeChanged(FullyQualifiedNameAttributeName, "name"),
ComputedIfAnyAttributeChanged(DescribeOutputAttributeName, "name", "title", "comment", "root_location", "main_file", "query_warehouse", "external_access_integrations"),
),
}
Expand Down Expand Up @@ -228,6 +230,9 @@ func ReadContextStreamlit(ctx context.Context, d *schema.ResourceData, meta any)
}
return diag.FromErr(err)
}
if err := d.Set(FullyQualifiedNameAttributeName, id.FullyQualifiedName()); err != nil {
return diag.FromErr(err)
}

streamlitDetails, err := client.Streamlits.Describe(ctx, id)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions pkg/resources/streamlit_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ func TestAcc_Streamlit_complete(t *testing.T) {
resource.TestCheckResourceAttr("snowflake_streamlit.test", "external_access_integrations.0", externalAccessIntegrationId.Name()),
resource.TestCheckResourceAttr("snowflake_streamlit.test", "title", "foo"),
resource.TestCheckResourceAttr("snowflake_streamlit.test", "comment", "foo"),
resource.TestCheckResourceAttr("snowflake_streamlit.test", "fully_qualified_name", id.FullyQualifiedName()),

resource.TestCheckResourceAttr("snowflake_streamlit.test", "show_output.#", "1"),
resource.TestCheckResourceAttrSet("snowflake_streamlit.test", "show_output.0.created_on"),
Expand Down Expand Up @@ -378,6 +379,7 @@ func TestAcc_Streamlit_Rename(t *testing.T) {
resource.TestCheckResourceAttr("snowflake_streamlit.test", "name", id.Name()),
resource.TestCheckResourceAttr("snowflake_streamlit.test", "show_output.0.name", id.Name()),
resource.TestCheckResourceAttr("snowflake_streamlit.test", "show_output.0.comment", "foo"),
resource.TestCheckResourceAttr("snowflake_streamlit.test", "fully_qualified_name", id.FullyQualifiedName()),
),
},
{
Expand All @@ -392,6 +394,7 @@ func TestAcc_Streamlit_Rename(t *testing.T) {
resource.TestCheckResourceAttr("snowflake_streamlit.test", "name", newId.Name()),
resource.TestCheckResourceAttr("snowflake_streamlit.test", "show_output.0.name", newId.Name()),
resource.TestCheckResourceAttr("snowflake_streamlit.test", "show_output.0.comment", "bar"),
resource.TestCheckResourceAttr("snowflake_streamlit.test", "fully_qualified_name", newId.FullyQualifiedName()),
),
},
},
Expand Down
6 changes: 6 additions & 0 deletions pkg/schemas/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,9 @@ var DescribePropertyListSchema = &schema.Schema{
Schema: ShowSecurityIntegrationPropertySchema,
},
}

var FullyQualifiedNameSchema = &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "Fully qualified name of the resource. For more information, see [object name resolution](https://docs.snowflake.com/en/sql-reference/name-resolution).",
}

0 comments on commit d92d1a3

Please sign in to comment.