-
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.
<!-- Feel free to delete comments as you fill this in --> <!-- summary of changes --> ## Changes * Connections Datasource * Generated Documentation for datasource ## Test Plan <!-- detail ways in which this PR has been tested or needs to be tested --> * [x] acceptance tests ## References <!-- issues documentation links, etc --> https://docs.snowflake.com/en/sql-reference/sql/create-connection ## TODO * SNOW-1788041
- Loading branch information
1 parent
34bbbc1
commit 4127b3f
Showing
8 changed files
with
432 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
--- | ||
page_title: "snowflake_connections Data Source - terraform-provider-snowflake" | ||
subcategory: "" | ||
description: |- | ||
Datasource used to get details of filtered connections. Filtering is aligned with the current possibilities for SHOW CONNECTIONS https://docs.snowflake.com/en/sql-reference/sql/show-connections query. The results of SHOW is encapsulated in one output collection connections. | ||
--- | ||
|
||
!> **V1 release candidate** This data source is a release candidate for the V1. We do not expect significant changes in it before the V1. We will welcome any feedback and adjust the data source if needed. Any errors reported will be resolved with a higher priority. We encourage checking this data source 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_connections (Data Source) | ||
|
||
Datasource used to get details of filtered connections. Filtering is aligned with the current possibilities for [SHOW CONNECTIONS](https://docs.snowflake.com/en/sql-reference/sql/show-connections) query. The results of SHOW is encapsulated in one output collection `connections`. | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
# Simple usage | ||
data "snowflake_connections" "simple" { | ||
} | ||
output "simple_output" { | ||
value = data.snowflake_connections.simple.connections | ||
} | ||
# Filtering (like) | ||
data "snowflake_connections" "like" { | ||
like = "connection-name" | ||
} | ||
output "like_output" { | ||
value = data.snowflake_connections.like.connections | ||
} | ||
# Filtering by prefix (like) | ||
data "snowflake_connections" "like_prefix" { | ||
like = "prefix%" | ||
} | ||
output "like_prefix_output" { | ||
value = data.snowflake_connections.like_prefix.connections | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Optional | ||
|
||
- `like` (String) Filters the output with **case-insensitive** pattern, with support for SQL wildcard characters (`%` and `_`). | ||
|
||
### Read-Only | ||
|
||
- `connections` (List of Object) Holds the aggregated output of all connections details queries. (see [below for nested schema](#nestedatt--connections)) | ||
- `id` (String) The ID of this resource. | ||
|
||
<a id="nestedatt--connections"></a> | ||
### Nested Schema for `connections` | ||
|
||
Read-Only: | ||
|
||
- `show_output` (List of Object) (see [below for nested schema](#nestedobjatt--connections--show_output)) | ||
|
||
<a id="nestedobjatt--connections--show_output"></a> | ||
### Nested Schema for `connections.show_output` | ||
|
||
Read-Only: | ||
|
||
- `account_locator` (String) | ||
- `account_name` (String) | ||
- `comment` (String) | ||
- `connection_url` (String) | ||
- `created_on` (String) | ||
- `failover_allowed_to_accounts` (List of String) | ||
- `is_primary` (Boolean) | ||
- `name` (String) | ||
- `organization_name` (String) | ||
- `primary` (String) | ||
- `region_group` (String) | ||
- `snowflake_region` (String) |
25 changes: 25 additions & 0 deletions
25
examples/data-sources/snowflake_connections/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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Simple usage | ||
data "snowflake_connections" "simple" { | ||
} | ||
|
||
output "simple_output" { | ||
value = data.snowflake_connections.simple.connections | ||
} | ||
|
||
# Filtering (like) | ||
data "snowflake_connections" "like" { | ||
like = "connection-name" | ||
} | ||
|
||
output "like_output" { | ||
value = data.snowflake_connections.like.connections | ||
} | ||
|
||
# Filtering by prefix (like) | ||
data "snowflake_connections" "like_prefix" { | ||
like = "prefix%" | ||
} | ||
|
||
output "like_prefix_output" { | ||
value = data.snowflake_connections.like_prefix.connections | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package datasources | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/provider" | ||
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/resources" | ||
"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" | ||
) | ||
|
||
var connectionsSchema = map[string]*schema.Schema{ | ||
"like": likeSchema, | ||
"connections": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Description: "Holds the aggregated output of all connections details queries.", | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
resources.ShowOutputAttributeName: { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Description: "Holds the output of SHOW CONNECTIONS.", | ||
Elem: &schema.Resource{ | ||
Schema: schemas.ShowConnectionSchema, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
func Connections() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadContext: ReadConnections, | ||
Schema: connectionsSchema, | ||
Description: "Datasource used to get details of filtered connections. Filtering is aligned with the current possibilities for [SHOW CONNECTIONS](https://docs.snowflake.com/en/sql-reference/sql/show-connections) query. The results of SHOW is encapsulated in one output collection `connections`.", | ||
} | ||
} | ||
|
||
func ReadConnections(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { | ||
client := meta.(*provider.Context).Client | ||
req := sdk.ShowConnectionRequest{} | ||
|
||
handleLike(d, &req.Like) | ||
|
||
connections, err := client.Connections.Show(ctx, &req) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
d.SetId("connections_read") | ||
|
||
flattenedConnections := make([]map[string]any, len(connections)) | ||
for i, connection := range connections { | ||
connection := connection | ||
flattenedConnections[i] = map[string]any{ | ||
resources.ShowOutputAttributeName: []map[string]any{schemas.ConnectionToSchema(&connection)}, | ||
} | ||
} | ||
if err := d.Set("connections", flattenedConnections); err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.