Skip to content

Commit

Permalink
feat: Use API integration from SDK (#2429)
Browse files Browse the repository at this point in the history
- Removed old api integration implementation from resource.
- Migrated tests and added more.
- Added not listed in docs ALTER options (`SET AZURE_TENANT_ID` and `SET
GOOGLE_AUDIENCE`) to the SDK. Added tests.
  • Loading branch information
sfc-gh-asawicki authored Jan 30, 2024
1 parent 119af5e commit 1ccc864
Show file tree
Hide file tree
Showing 23 changed files with 793 additions and 383 deletions.
267 changes: 150 additions & 117 deletions pkg/resources/api_integration.go

Large diffs are not rendered by default.

410 changes: 353 additions & 57 deletions pkg/resources/api_integration_acceptance_test.go

Large diffs are not rendered by default.

128 changes: 0 additions & 128 deletions pkg/resources/api_integration_test.go

This file was deleted.

10 changes: 10 additions & 0 deletions pkg/resources/testdata/TestAcc_ApiIntegration_aws/1/test.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
resource "snowflake_api_integration" "test_aws_int" {
name = var.name
api_provider = var.api_provider
api_aws_role_arn = var.api_aws_role_arn
api_allowed_prefixes = var.api_allowed_prefixes
api_blocked_prefixes = var.api_blocked_prefixes
api_key = var.api_key
comment = var.comment
enabled = var.enabled
}
32 changes: 32 additions & 0 deletions pkg/resources/testdata/TestAcc_ApiIntegration_aws/1/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
variable "name" {
type = string
}

variable "api_provider" {
type = string
}

variable "api_aws_role_arn" {
type = string
}

variable "api_allowed_prefixes" {
type = list(string)
}

variable "api_blocked_prefixes" {
type = list(string)
}

variable "api_key" {
type = string
}

variable "comment" {
type = string
}

variable "enabled" {
type = bool
}

11 changes: 11 additions & 0 deletions pkg/resources/testdata/TestAcc_ApiIntegration_azure/1/test.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
resource "snowflake_api_integration" "test_azure_int" {
name = var.name
api_provider = "azure_api_management"
azure_tenant_id = var.azure_tenant_id
azure_ad_application_id = var.azure_ad_application_id
api_allowed_prefixes = var.api_allowed_prefixes
api_blocked_prefixes = var.api_blocked_prefixes
api_key = var.api_key
comment = var.comment
enabled = var.enabled
}
31 changes: 31 additions & 0 deletions pkg/resources/testdata/TestAcc_ApiIntegration_azure/1/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
variable "name" {
type = string
}

variable "azure_tenant_id" {
type = string
}

variable "azure_ad_application_id" {
type = string
}

variable "api_allowed_prefixes" {
type = list(string)
}

variable "api_blocked_prefixes" {
type = list(string)
}

variable "api_key" {
type = string
}

variable "comment" {
type = string
}

variable "enabled" {
type = bool
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
resource "snowflake_api_integration" "test_change" {
name = var.name
api_provider = var.api_provider
api_aws_role_arn = var.api_aws_role_arn
api_allowed_prefixes = var.api_allowed_prefixes
api_blocked_prefixes = var.api_blocked_prefixes
api_key = var.api_key
comment = var.comment
enabled = var.enabled
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
variable "name" {
type = string
}

variable "api_provider" {
type = string
}

variable "api_aws_role_arn" {
type = string
}

variable "api_allowed_prefixes" {
type = list(string)
}

variable "api_blocked_prefixes" {
type = list(string)
}

variable "api_key" {
type = string
}

variable "comment" {
type = string
}

variable "enabled" {
type = bool
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
resource "snowflake_api_integration" "test_change" {
name = var.name
api_provider = "azure_api_management"
azure_tenant_id = var.azure_tenant_id
azure_ad_application_id = var.azure_ad_application_id
api_allowed_prefixes = var.api_allowed_prefixes
api_blocked_prefixes = var.api_blocked_prefixes
api_key = var.api_key
comment = var.comment
enabled = var.enabled
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
variable "name" {
type = string
}

variable "azure_tenant_id" {
type = string
}

variable "azure_ad_application_id" {
type = string
}

variable "api_allowed_prefixes" {
type = list(string)
}

variable "api_blocked_prefixes" {
type = list(string)
}

variable "api_key" {
type = string
}

variable "comment" {
type = string
}

variable "enabled" {
type = bool
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
resource "snowflake_api_integration" "test_gcp_int" {
name = var.name
api_provider = "google_api_gateway"
google_audience = var.google_audience
api_allowed_prefixes = var.api_allowed_prefixes
api_blocked_prefixes = var.api_blocked_prefixes
comment = var.comment
enabled = var.enabled
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
variable "name" {
type = string
}

variable "google_audience" {
type = string
}

variable "api_allowed_prefixes" {
type = list(string)
}

variable "api_blocked_prefixes" {
type = list(string)
}

variable "comment" {
type = string
}

variable "enabled" {
type = bool
}

14 changes: 11 additions & 3 deletions pkg/sdk/api_integrations_def.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,25 @@ var ApiIntegrationsDef = g.NewInterface(
OptionalQueryStructField(
"AzureParams",
g.NewQueryStruct("SetAzureApiParams").
OptionalTextAssignment("AZURE_TENANT_ID", g.ParameterOptions().SingleQuotes()).
OptionalTextAssignment("AZURE_AD_APPLICATION_ID", g.ParameterOptions().SingleQuotes()).
OptionalTextAssignment("API_KEY", g.ParameterOptions().SingleQuotes()).
WithValidation(g.AtLeastOneValueSet, "AzureAdApplicationId", "ApiKey"),
WithValidation(g.AtLeastOneValueSet, "AzureTenantId", "AzureAdApplicationId", "ApiKey"),
g.KeywordOptions(),
).
OptionalQueryStructField(
"GoogleParams",
g.NewQueryStruct("SetGoogleApiParams").
TextAssignment("GOOGLE_AUDIENCE", g.ParameterOptions().SingleQuotes().Required()),
g.KeywordOptions(),
).
OptionalBooleanAssignment("ENABLED", g.ParameterOptions()).
ListAssignment("API_ALLOWED_PREFIXES", "ApiIntegrationEndpointPrefix", g.ParameterOptions().Parentheses()).
ListAssignment("API_BLOCKED_PREFIXES", "ApiIntegrationEndpointPrefix", g.ParameterOptions().Parentheses()).
OptionalComment().
WithValidation(g.ConflictingFields, "AwsParams", "AzureParams").
WithValidation(g.AtLeastOneValueSet, "AwsParams", "AzureParams", "Enabled", "ApiAllowedPrefixes", "ApiBlockedPrefixes", "Comment"),
// resulting validation changed to moreThanOneValueSet (not yet supported in the generator)
WithValidation(g.ConflictingFields, "AwsParams", "AzureParams", "GoogleParams").
WithValidation(g.AtLeastOneValueSet, "AwsParams", "AzureParams", "GoogleParams", "Enabled", "ApiAllowedPrefixes", "ApiBlockedPrefixes", "Comment"),
g.KeywordOptions().SQL("SET"),
).
OptionalQueryStructField(
Expand Down
Loading

0 comments on commit 1ccc864

Please sign in to comment.