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
Changes from 1 commit
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
Next Next commit
initial commit for connections sdk
  • Loading branch information
sfc-gh-fbudzynski committed Oct 18, 2024
commit c32165467103eb83ef10d34ba219eaaa74878ecc
92 changes: 92 additions & 0 deletions pkg/sdk/connections_def.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package sdk

//go:generate go run ./poc/main.go
import (
g "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/poc/generator"
)

var enabledFailoverAccounts = g.NewQueryStruct("EnabledFailoverAccounts").
Text("Account", g.KeywordOptions().NoQuotes())

var ConnectionDef = g.NewInterface(
"Conntections",
"Connection",
g.KindOfT[AccountObjectIdentifier](),
).CustomOperation(
"CreateConnection",
"https://docs.snowflake.com/en/sql-reference/sql/create-connection",
g.NewQueryStruct("CreateConnection").
Create().
SQL("CONNECTION").
IfNotExists().
Name().
OptionalComment().
WithValidation(g.ValidIdentifier, "name"),
).CustomOperation(
"CreateReplicatedConnection",
"https://docs.snowflake.com/en/sql-reference/sql/create-connection",
g.NewQueryStruct("CreateReplicatedConnection").
Create().
SQL("CONNECTION").
IfNotExists().
Name().
SQL("AS REPLICA OF").
// external reference to connection: <orgnization_name>.<account_name>.<name>
Identifier("ReplicaOf", g.KindOfT[ExternalObjectIdentifier](), g.IdentifierOptions().Required()).
OptionalComment().
WithValidation(g.ValidIdentifier, "name").
WithValidation(g.ValidIdentifier, "ReplicaOf"),
).CustomOperation(
"AlterConnectionFailover",
"https://docs.snowflake.com/en/sql-reference/sql/alter-connection",
g.NewQueryStruct("AlterConnectionFailover").
Alter().
SQL("CONNECTION").
Name().
OptionalQueryStructField(
"EnableConnectionFailover",
g.NewQueryStruct("EnableConnectionFailover").
// ListQueryStructField("Accounts", enabledFailoverAccounts, g.ListOptions().NoParentheses()).
List("Accounts", "ExternalObjectIdentifier", g.ListOptions().NoParentheses()).
OptionalSQL("IGNORE EDITION CHECK"),
g.KeywordOptions().SQL("ENABLE FAILOVER TO ACCOUNTS"),
).
OptionalQueryStructField(
"DisableConnectionFailover",
g.NewQueryStruct("DisableConnectionFailover").
OptionalSQL("TO ACCOUNTS").
// ListQueryStructField("Accounts", enabledFailoverAccounts, g.ListOptions().NoParentheses()),
List("Accounts", "ExternalObjectIdentifier", g.ListOptions().NoParentheses()),
g.KeywordOptions().SQL("DISABLE FAILOVER"),
).
OptionalQueryStructField(
"Primary",
g.NewQueryStruct("Primary").
SQL("PRIMARY"),
g.KeywordOptions(),
).
WithValidation(g.ExactlyOneValueSet, "EnableConnectionFailover", "DisableConnectionFailover", "Primary"),
).CustomOperation(
"AlterConnection",
"https://docs.snowflake.com/en/sql-reference/sql/alter-connection",
g.NewQueryStruct("AlterConnection").
Alter().
SQL("CONNECTION").
IfExists().
Name().
OptionalQueryStructField(
"Set",
g.NewQueryStruct("Set").
OptionalComment().
WithValidation(g.AtLeastOneValueSet, "Comment"),
g.KeywordOptions().SQL("SET"),
).
OptionalQueryStructField(
"Unset",
g.NewQueryStruct("Unset").
OptionalSQL("COMMENT").
WithValidation(g.AtLeastOneValueSet, "Comment"),
g.KeywordOptions().SQL("UNSET"),
).
WithValidation(g.ExactlyOneValueSet, "Set", "Unset"),
)
139 changes: 139 additions & 0 deletions pkg/sdk/connections_dto_builders_gen.go

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

58 changes: 58 additions & 0 deletions pkg/sdk/connections_dto_gen.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package sdk

//go:generate go run ./dto-builder-generator/main.go

var (
_ optionsProvider[CreateConnectionConnectionOptions] = new(CreateConnectionConnectionRequest)
_ optionsProvider[CreateReplicatedConnectionConnectionOptions] = new(CreateReplicatedConnectionConnectionRequest)
_ optionsProvider[AlterConnectionFailoverConnectionOptions] = new(AlterConnectionFailoverConnectionRequest)
_ optionsProvider[AlterConnectionConnectionOptions] = new(AlterConnectionConnectionRequest)
)

type CreateConnectionConnectionRequest struct {
IfNotExists *bool
name AccountObjectIdentifier // required
Comment *string
}

type CreateReplicatedConnectionConnectionRequest struct {
IfNotExists *bool
name AccountObjectIdentifier // required
ReplicaOf ExternalObjectIdentifier // required
Comment *string
}

type AlterConnectionFailoverConnectionRequest struct {
name AccountObjectIdentifier // required
EnableConnectionFailover *EnableConnectionFailoverRequest
DisableConnectionFailover *DisableConnectionFailoverRequest
Primary *PrimaryRequest
}

type EnableConnectionFailoverRequest struct {
Accounts []ExternalObjectIdentifier
IgnoreEditionCheck *bool
}

type DisableConnectionFailoverRequest struct {
ToAccounts *bool
Accounts []ExternalObjectIdentifier
}

type PrimaryRequest struct {
}

type AlterConnectionConnectionRequest struct {
IfExists *bool
name AccountObjectIdentifier // required
Set *SetRequest
Unset *UnsetRequest
}

type SetRequest struct {
Comment *string
}

type UnsetRequest struct {
Comment *bool
}
67 changes: 67 additions & 0 deletions pkg/sdk/connections_gen.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package sdk

import "context"

type Conntections interface {
CreateConnection(ctx context.Context, request *CreateConnectionConnectionRequest) error
CreateReplicatedConnection(ctx context.Context, request *CreateReplicatedConnectionConnectionRequest) error
AlterConnectionFailover(ctx context.Context, request *AlterConnectionFailoverConnectionRequest) error
AlterConnection(ctx context.Context, request *AlterConnectionConnectionRequest) error
}

// CreateConnectionConnectionOptions is based on https://docs.snowflake.com/en/sql-reference/sql/create-connection.
type CreateConnectionConnectionOptions struct {
create bool `ddl:"static" sql:"CREATE"`
connection bool `ddl:"static" sql:"CONNECTION"`
IfNotExists *bool `ddl:"keyword" sql:"IF NOT EXISTS"`
name AccountObjectIdentifier `ddl:"identifier"`
Comment *string `ddl:"parameter,single_quotes" sql:"COMMENT"`
}

// CreateReplicatedConnectionConnectionOptions is based on https://docs.snowflake.com/en/sql-reference/sql/create-connection.
type CreateReplicatedConnectionConnectionOptions struct {
create bool `ddl:"static" sql:"CREATE"`
connection bool `ddl:"static" sql:"CONNECTION"`
IfNotExists *bool `ddl:"keyword" sql:"IF NOT EXISTS"`
name AccountObjectIdentifier `ddl:"identifier"`
asReplicaOf bool `ddl:"static" sql:"AS REPLICA OF"`
ReplicaOf ExternalObjectIdentifier `ddl:"identifier"`
Comment *string `ddl:"parameter,single_quotes" sql:"COMMENT"`
}

// AlterConnectionFailoverConnectionOptions is based on https://docs.snowflake.com/en/sql-reference/sql/alter-connection.
type AlterConnectionFailoverConnectionOptions struct {
alter bool `ddl:"static" sql:"ALTER"`
connection bool `ddl:"static" sql:"CONNECTION"`
name AccountObjectIdentifier `ddl:"identifier"`
EnableConnectionFailover *EnableConnectionFailover `ddl:"keyword" sql:"ENABLE FAILOVER TO ACCOUNTS"`
DisableConnectionFailover *DisableConnectionFailover `ddl:"keyword" sql:"DISABLE FAILOVER"`
Primary *Primary `ddl:"keyword"`
}
type EnableConnectionFailover struct {
Accounts []ExternalObjectIdentifier `ddl:"list,no_parentheses"`
IgnoreEditionCheck *bool `ddl:"keyword" sql:"IGNORE EDITION CHECK"`
}
type DisableConnectionFailover struct {
ToAccounts *bool `ddl:"keyword" sql:"TO ACCOUNTS"`
Accounts []ExternalObjectIdentifier `ddl:"list,no_parentheses"`
}
type Primary struct {
primary bool `ddl:"static" sql:"PRIMARY"`
}

// AlterConnectionConnectionOptions is based on https://docs.snowflake.com/en/sql-reference/sql/alter-connection.
type AlterConnectionConnectionOptions struct {
alter bool `ddl:"static" sql:"ALTER"`
connection bool `ddl:"static" sql:"CONNECTION"`
IfExists *bool `ddl:"keyword" sql:"IF EXISTS"`
name AccountObjectIdentifier `ddl:"identifier"`
Set *Set `ddl:"keyword" sql:"SET"`
Unset *Unset `ddl:"keyword" sql:"UNSET"`
}
type Set struct {
Comment *string `ddl:"parameter,single_quotes" sql:"COMMENT"`
}
type Unset struct {
Comment *bool `ddl:"keyword" sql:"COMMENT"`
}
23 changes: 23 additions & 0 deletions pkg/sdk/connections_gen_integration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package sdk

import "testing"

func TestInt_Conntections(t *testing.T) {
// TODO: prepare common resources

t.Run("CreateConnection", func(t *testing.T) {
// TODO: fill me
})

t.Run("CreateReplicatedConnection", func(t *testing.T) {
// TODO: fill me
})

t.Run("AlterConnectionFailover", func(t *testing.T) {
// TODO: fill me
})

t.Run("AlterConnection", func(t *testing.T) {
// TODO: fill me
})
}
Loading