-
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.
feat: Add SDK for External Volumes (#3033)
This PR adds the SDK for External Volumes. This is part of a series of PRs aimed at adding provider support for Iceberg tables. ## References - #2980 - #2249
- Loading branch information
Showing
10 changed files
with
1,952 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,162 @@ | ||
package sdk | ||
|
||
import g "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/poc/generator" | ||
|
||
//go:generate go run ./poc/main.go | ||
|
||
type ( | ||
S3EncryptionType string | ||
S3StorageProvider string | ||
GCSEncryptionType string | ||
) | ||
|
||
var ( | ||
S3EncryptionTypeSseS3 S3EncryptionType = "AWS_SSE_S3" | ||
S3EncryptionTypeSseKms S3EncryptionType = "AWS_SSE_KMS" | ||
S3EncryptionNone S3EncryptionType = "NONE" | ||
GCSEncryptionTypeSseKms GCSEncryptionType = "GCS_SSE_KMS" | ||
GCSEncryptionTypeNone GCSEncryptionType = "NONE" | ||
S3StorageProviderS3 S3StorageProvider = "S3" | ||
S3StorageProviderS3GOV S3StorageProvider = "S3GOV" | ||
) | ||
|
||
var externalS3StorageLocationDef = g.NewQueryStruct("S3StorageLocationParams"). | ||
TextAssignment("NAME", g.ParameterOptions().SingleQuotes().Required()). | ||
Assignment("STORAGE_PROVIDER", g.KindOfT[S3StorageProvider](), g.ParameterOptions().SingleQuotes().Required()). | ||
TextAssignment("STORAGE_AWS_ROLE_ARN", g.ParameterOptions().SingleQuotes().Required()). | ||
TextAssignment("STORAGE_BASE_URL", g.ParameterOptions().SingleQuotes().Required()). | ||
OptionalTextAssignment("STORAGE_AWS_EXTERNAL_ID", g.ParameterOptions().SingleQuotes()). | ||
OptionalQueryStructField( | ||
"Encryption", | ||
g.NewQueryStruct("ExternalVolumeS3Encryption"). | ||
Assignment("TYPE", g.KindOfT[S3EncryptionType](), g.ParameterOptions().SingleQuotes().Required()). | ||
OptionalTextAssignment("KMS_KEY_ID", g.ParameterOptions().SingleQuotes()), | ||
g.ListOptions().Parentheses().NoComma().SQL("ENCRYPTION ="), | ||
) | ||
|
||
var externalGCSStorageLocationDef = g.NewQueryStruct("GCSStorageLocationParams"). | ||
TextAssignment("NAME", g.ParameterOptions().SingleQuotes().Required()). | ||
PredefinedQueryStructField("StorageProviderGcs", "string", g.StaticOptions().SQL("STORAGE_PROVIDER = 'GCS'")). | ||
TextAssignment("STORAGE_BASE_URL", g.ParameterOptions().SingleQuotes().Required()). | ||
OptionalQueryStructField( | ||
"Encryption", | ||
g.NewQueryStruct("ExternalVolumeGCSEncryption"). | ||
Assignment("TYPE", g.KindOfT[GCSEncryptionType](), g.ParameterOptions().SingleQuotes().Required()). | ||
OptionalTextAssignment("KMS_KEY_ID", g.ParameterOptions().SingleQuotes()), | ||
g.ListOptions().Parentheses().NoComma().SQL("ENCRYPTION ="), | ||
) | ||
|
||
var externalAzureStorageLocationDef = g.NewQueryStruct("AzureStorageLocationParams"). | ||
TextAssignment("NAME", g.ParameterOptions().SingleQuotes().Required()). | ||
PredefinedQueryStructField("StorageProviderAzure", "string", g.StaticOptions().SQL("STORAGE_PROVIDER = 'AZURE'")). | ||
TextAssignment("AZURE_TENANT_ID", g.ParameterOptions().SingleQuotes().Required()). | ||
TextAssignment("STORAGE_BASE_URL", g.ParameterOptions().SingleQuotes().Required()) | ||
|
||
// Can't name StorageLocation due to naming clash with type in storage integration | ||
var storageLocationDef = g.NewQueryStruct("ExternalVolumeStorageLocation"). | ||
OptionalQueryStructField( | ||
"S3StorageLocationParams", | ||
externalS3StorageLocationDef, | ||
g.ListOptions().Parentheses().NoComma(), | ||
). | ||
OptionalQueryStructField( | ||
"GCSStorageLocationParams", | ||
externalGCSStorageLocationDef, | ||
g.ListOptions().Parentheses().NoComma(), | ||
). | ||
OptionalQueryStructField( | ||
"AzureStorageLocationParams", | ||
externalAzureStorageLocationDef, | ||
g.ListOptions().Parentheses().NoComma(), | ||
). | ||
WithValidation(g.ExactlyOneValueSet, "S3StorageLocationParams", "GCSStorageLocationParams", "AzureStorageLocationParams") | ||
|
||
var ExternalVolumesDef = g.NewInterface( | ||
"ExternalVolumes", | ||
"ExternalVolume", | ||
g.KindOfT[AccountObjectIdentifier](), | ||
). | ||
CreateOperation( | ||
"https://docs.snowflake.com/en/sql-reference/sql/create-external-volume", | ||
g.NewQueryStruct("CreateExternalVolume"). | ||
Create(). | ||
OrReplace(). | ||
SQL("EXTERNAL VOLUME"). | ||
IfNotExists(). | ||
Name(). | ||
ListAssignment("STORAGE_LOCATIONS", "ExternalVolumeStorageLocation", g.ParameterOptions().Parentheses().Required()). | ||
OptionalBooleanAssignment("ALLOW_WRITES", nil). | ||
OptionalComment(). | ||
WithValidation(g.ConflictingFields, "OrReplace", "IfNotExists"). | ||
WithValidation(g.ValidIdentifier, "name"), | ||
storageLocationDef, | ||
). | ||
AlterOperation( | ||
"https://docs.snowflake.com/en/sql-reference/sql/alter-external-volume", | ||
g.NewQueryStruct("AlterExternalVolume"). | ||
Alter(). | ||
SQL("EXTERNAL VOLUME"). | ||
IfExists(). | ||
Name(). | ||
OptionalTextAssignment("REMOVE STORAGE_LOCATION", g.ParameterOptions().SingleQuotes().NoEquals()). | ||
OptionalQueryStructField( | ||
"Set", | ||
g.NewQueryStruct("AlterExternalVolumeSet"). | ||
OptionalBooleanAssignment("ALLOW_WRITES", g.ParameterOptions()). | ||
OptionalComment(), | ||
g.KeywordOptions().SQL("SET"), | ||
). | ||
OptionalQueryStructField( | ||
"AddStorageLocation", | ||
storageLocationDef, | ||
g.ParameterOptions().SQL("ADD STORAGE_LOCATION"), | ||
). | ||
WithValidation(g.ExactlyOneValueSet, "RemoveStorageLocation", "Set", "AddStorageLocation"). | ||
WithValidation(g.ValidIdentifier, "name"), | ||
). | ||
DropOperation( | ||
"https://docs.snowflake.com/en/sql-reference/sql/drop-external-volume", | ||
g.NewQueryStruct("DropExternalVolume"). | ||
Drop(). | ||
SQL("EXTERNAL VOLUME"). | ||
IfExists(). | ||
Name(). | ||
WithValidation(g.ValidIdentifier, "name"), | ||
). | ||
DescribeOperation( | ||
g.DescriptionMappingKindSlice, | ||
"https://docs.snowflake.com/en/sql-reference/sql/desc-external-volume", | ||
g.DbStruct("externalVolumeDescRow"). | ||
Text("parent_property"). | ||
Text("property"). | ||
Text("property_type"). | ||
Text("property_value"). | ||
Text("property_default"), | ||
g.PlainStruct("ExternalVolumeProperty"). | ||
Text("Parent"). | ||
Text("Name"). | ||
Text("Type"). | ||
Text("Value"). | ||
Text("Default"), | ||
g.NewQueryStruct("DescExternalVolume"). | ||
Describe(). | ||
SQL("EXTERNAL VOLUME"). | ||
Name(). | ||
WithValidation(g.ValidIdentifier, "name"), | ||
). | ||
ShowOperation( | ||
"https://docs.snowflake.com/en/sql-reference/sql/show-external-volumes", | ||
g.DbStruct("externalVolumeShowRow"). | ||
Text("name"). | ||
Text("allow_writes"). | ||
Text("comment"), | ||
g.PlainStruct("ExternalVolume"). | ||
Text("Name"). | ||
Text("AllowWrites"). | ||
Text("Comment"), | ||
g.NewQueryStruct("ShowExternalVolumes"). | ||
Show(). | ||
SQL("EXTERNAL VOLUMES"). | ||
OptionalLike(), | ||
). | ||
ShowByIdOperation() |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.