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: Connection resource #3162

Merged
merged 46 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
c321654
initial commit for connections sdk
sfc-gh-fbudzynski Oct 18, 2024
6b989e3
added show and drop
sfc-gh-fbudzynski Oct 21, 2024
fb8d018
connection assert generated
sfc-gh-fbudzynski Oct 21, 2024
6db06d8
assertions generated
sfc-gh-fbudzynski Oct 22, 2024
24a2c80
integration test
sfc-gh-fbudzynski Oct 23, 2024
5c8f84f
before self-review
sfc-gh-fbudzynski Oct 24, 2024
a5d59b6
integration tests
sfc-gh-fbudzynski Oct 24, 2024
f831c02
simplified disable connection failover struct
sfc-gh-fbudzynski Oct 24, 2024
fa3db2b
Merge branch 'main' of github.com:Snowflake-Labs/terraform-provider-s…
sfc-gh-fbudzynski Oct 24, 2024
e140406
init resource for connections
sfc-gh-fbudzynski Oct 25, 2024
fc4cd95
Merge branch 'main' of github.com:Snowflake-Labs/terraform-provider-s…
sfc-gh-fbudzynski Oct 25, 2024
1dee95b
adjusted to comments from review
sfc-gh-fbudzynski Oct 25, 2024
f0915c4
Merge branch 'connection-sdk' into connection-resource
sfc-gh-fbudzynski Oct 25, 2024
5291ab3
create for connection resource
sfc-gh-fbudzynski Oct 25, 2024
a6668d9
merge conflict with main resolved
sfc-gh-fbudzynski Oct 28, 2024
f8c64f7
linter adjustemnts
sfc-gh-fbudzynski Oct 28, 2024
68fce3d
pre-push adjustment
sfc-gh-fbudzynski Oct 28, 2024
661a8a4
Merge branch 'main' of github.com:Snowflake-Labs/terraform-provider-s…
sfc-gh-fbudzynski Oct 28, 2024
993da0d
resource CRUD functions
sfc-gh-fbudzynski Oct 28, 2024
7197faa
Merge branch 'main' of github.com:Snowflake-Labs/terraform-provider-s…
sfc-gh-fbudzynski Oct 28, 2024
fd52498
added drop with if exists and HasPrimaryIdentifier extended function
sfc-gh-fbudzynski Oct 28, 2024
b739e99
pre-push adjustments
sfc-gh-fbudzynski Oct 28, 2024
d7b13de
added skips for tests
sfc-gh-fbudzynski Oct 28, 2024
147f85a
acceptance tests for connection
sfc-gh-fbudzynski Oct 28, 2024
5394364
Merge branch 'main' of github.com:Snowflake-Labs/terraform-provider-s…
sfc-gh-fbudzynski Oct 28, 2024
fb3d563
with exists to connection resource delete
sfc-gh-fbudzynski Oct 29, 2024
f9c4f6a
resolved comments
sfc-gh-fbudzynski Oct 29, 2024
e665b38
Merge branch 'connection-sdk' into connection-resource
sfc-gh-fbudzynski Oct 29, 2024
44c1c05
connection resource with docs and migration guide
sfc-gh-fbudzynski Oct 29, 2024
215d6af
pre-push adjustments
sfc-gh-fbudzynski Oct 29, 2024
d0fb45c
self review small changes
sfc-gh-fbudzynski Oct 29, 2024
ba98db7
Merge branch 'main' of github.com:Snowflake-Labs/terraform-provider-s…
sfc-gh-fbudzynski Oct 30, 2024
9becdb9
changed naming for Set and Unset for connection
sfc-gh-fbudzynski Oct 30, 2024
ffe98a1
before discussing whether to split resource
sfc-gh-fbudzynski Oct 30, 2024
958a596
rename unset and set to unsetConnection and setConnection
sfc-gh-fbudzynski Oct 30, 2024
284e920
rename unset and set in tests
sfc-gh-fbudzynski Oct 30, 2024
8ced116
seperate connection resource to primary and secondary
sfc-gh-fbudzynski Oct 31, 2024
dc08d74
linter adjustemnts
sfc-gh-fbudzynski Oct 31, 2024
ca44fcb
secondary connection custom diff
sfc-gh-fbudzynski Oct 31, 2024
47edb32
pre-push adjustments
sfc-gh-fbudzynski Oct 31, 2024
9ed9076
merge request resolved
sfc-gh-fbudzynski Oct 31, 2024
4efce94
changed naming of primary connection, and adjusted to comments in pr
sfc-gh-fbudzynski Nov 4, 2024
f86d26e
added docs
sfc-gh-fbudzynski Nov 4, 2024
dcc24e0
Merge branch 'main' of github.com:Snowflake-Labs/terraform-provider-s…
sfc-gh-fbudzynski Nov 5, 2024
e779da4
custom diff for secondary_connection
sfc-gh-fbudzynski Nov 5, 2024
1263a91
Merge branch 'main' of github.com:Snowflake-Labs/terraform-provider-s…
sfc-gh-fbudzynski Nov 5, 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
4 changes: 4 additions & 0 deletions MIGRATION_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ across different versions.

## v0.97.0 ➞ v0.98.0

### *(new feature)* connection resource
sfc-gh-jcieslak marked this conversation as resolved.
Show resolved Hide resolved
Added a new resource for managing connections.
See reference [docs](https://docs.snowflake.com/en/sql-reference/sql/create-connection).

### *(behavior change)* handling copy_grants
Currently, resources like `snowflake_view`, `snowflake_stream_on_table`, `snowflake_stream_on_external_table` and `snowflake_stream_on_directory_table` support `copy_grants` field corresponding with `COPY GRANTS` during `CREATE`. The current behavior is that, when a change leading for recreation is detected (meaning a change that can not be handled by ALTER, but only by `CREATE OR REPLACE`), `COPY GRANTS` are used during recreation when `copy_grants` is set to `true`. Changing this field without changes in other field results in a noop because in this case there is no need to recreate a resource.

Expand Down
102 changes: 102 additions & 0 deletions docs/resources/connection.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
---
page_title: "snowflake_connection Resource - terraform-provider-snowflake"
subcategory: ""
description: |-
Resource used to manage connections. For more information, check connection documentation https://docs.snowflake.com/en/sql-reference/sql/create-connection.html.
---

!> **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_connection (Resource)

Resource used to manage connections. For more information, check [connection documentation](https://docs.snowflake.com/en/sql-reference/sql/create-connection.html).

## Example Usage

```terraform
## Minimal
resource "snowflake_connection" "basic" {
name = "connection_name"
}

## Enable failover to accounts
resource "snowflake_connection" "with_enable_failover_list" {
name = "connection_name"
enable_failover_to_accounts = [
"<secondary_account_organization_name>.<secondary_account_name>"
]
}

## As replica
resource "snowflake_connection" "replica" {
name = "connection_name"
as_replica_of = "<organization_name>.<account_name>.<connection_name>"
is_primary = false
}

# As replica with promotion to primary
resource "snowflake_connection" "replica_with_promotion" {
name = "connection_name"
as_replica_of = "<organization_name>.<account_name>.<connection_name>"
is_primary = true
sfc-gh-jcieslak marked this conversation as resolved.
Show resolved Hide resolved
}

## Complete (with every optional set)
resource "snowflake_connection" "complete" {
name = "connection_name"
as_replica_of = "<organization_name>.<account_name>.<connection_name>"
is_primary = true
enable_failover_to_accounts = [
"<secondary_account_organization_name>.<secondary_account_name>"
]
comment = "my complete connection"
}
```
-> **Note** Instead of using fully_qualified_name, you can reference objects managed outside Terraform by constructing a correct ID, consult [identifiers guide](https://registry.terraform.io/providers/Snowflake-Labs/snowflake/latest/docs/guides/identifiers#new-computed-fully-qualified-name-field-in-resources).
<!-- TODO(SNOW-1634854): include an example showing both methods-->

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `name` (String) String that specifies the identifier (i.e. name) for the connection. Must start with an alphabetic character and may only contain letters, decimal digits (0-9), and underscores (_). For a primary connection, the name must be unique across connection names and account names in the organization. For a secondary connection, the name must match the name of its primary connection. 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: `|`, `.`, `(`, `)`, `"`

### Optional

- `as_replica_of` (String) Specifies the identifier for a primary connection from which to create a replica (i.e. a secondary connection).
- `comment` (String) Specifies a comment for the connection.
- `enable_failover_to_accounts` (List of String) Enables failover for given connection to provided accounts. Specifies a list of accounts in your organization where a secondary connection for this primary connection can be promoted to serve as the primary connection. Include your organization name for each account in the list.
- `is_primary` (Boolean)

### Read-Only

- `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 CONNECTIONS` for the given secret. (see [below for nested schema](#nestedatt--show_output))

<a id="nestedatt--show_output"></a>
### Nested Schema for `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)

## Import

Import is supported using the following syntax:

```shell
terraform import snowflake_connection.example 'connection_name'
```
1 change: 1 addition & 0 deletions examples/resources/snowflake_connection/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terraform import snowflake_connection.example 'connection_name'
37 changes: 37 additions & 0 deletions examples/resources/snowflake_connection/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
## Minimal
resource "snowflake_connection" "basic" {
name = "connection_name"
}

## Enable failover to accounts
resource "snowflake_connection" "with_enable_failover_list" {
sfc-gh-jmichalak marked this conversation as resolved.
Show resolved Hide resolved
name = "connection_name"
enable_failover_to_accounts = [
"<secondary_account_organization_name>.<secondary_account_name>"
]
}

## As replica
resource "snowflake_connection" "replica" {
name = "connection_name"
as_replica_of = "<organization_name>.<account_name>.<connection_name>"
is_primary = false
}

# As replica with promotion to primary
resource "snowflake_connection" "replica_with_promotion" {
name = "connection_name"
as_replica_of = "<organization_name>.<account_name>.<connection_name>"
is_primary = true
}

## Complete (with every optional set)
resource "snowflake_connection" "complete" {
name = "connection_name"
as_replica_of = "<organization_name>.<account_name>.<connection_name>"
is_primary = true
enable_failover_to_accounts = [
"<secondary_account_organization_name>.<secondary_account_name>"
]
comment = "my complete connection"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package resourceassert

import (
"fmt"
"strings"

"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk"
)

func (c *ConnectionResourceAssert) HasAsReplicaOfIdentifier(expected sdk.ExternalObjectIdentifier) *ConnectionResourceAssert {
sfc-gh-jcieslak marked this conversation as resolved.
Show resolved Hide resolved
expectedString := strings.ReplaceAll(expected.FullyQualifiedName(), `"`, "")
c.AddAssertion(assert.ValueSet("as_replica_of", expectedString))
return c
}

func (c *ConnectionResourceAssert) HasEnableFailoverToAccounts(expected ...sdk.AccountIdentifier) *ConnectionResourceAssert {
sfc-gh-jmichalak marked this conversation as resolved.
Show resolved Hide resolved
for i, v := range expected {
c.AddAssertion(assert.ValueSet(fmt.Sprintf("enable_failover_to_accounts.%d", i), v.Name()))
sfc-gh-jcieslak marked this conversation as resolved.
Show resolved Hide resolved
}
return c
}

func (c *ConnectionResourceAssert) HasNoEnableFailoverToAccounts() *ConnectionResourceAssert {
c.AddAssertion(assert.ValueSet("enable_failover_to_accounts.#", "0"))
return c
}

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

Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,8 @@ var allResourceSchemaDefs = []ResourceSchemaDef{
name: "StreamOnView",
schema: resources.StreamOnView().Schema,
},
{
name: "Connection",
schema: resources.Connection().Schema,
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package resourceshowoutputassert

import (
"fmt"
"strings"

"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk"
)

func (c *ConnectionShowOutputAssert) HasPrimaryIdentifier(expected sdk.ExternalObjectIdentifier) *ConnectionShowOutputAssert {
expectedString := strings.ReplaceAll(expected.FullyQualifiedName(), `"`, "")
sfc-gh-jcieslak marked this conversation as resolved.
Show resolved Hide resolved
c.AddAssertion(assert.ResourceShowOutputValueSet("primary", expectedString))
return c
}

func (c *ConnectionShowOutputAssert) HasFailoverAllowedToAccounts(expected ...sdk.AccountIdentifier) *ConnectionShowOutputAssert {
for i, v := range expected {
c.AddAssertion(assert.ResourceShowOutputValueSet(fmt.Sprintf("failover_allowed_to_accounts.%d", i), v.Name()))
}
return c
}
Loading
Loading