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: Add support for GCP notification integration #603

Merged
merged 6 commits into from
Jul 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions docs/resources/notification_integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ description: |-
- **comment** (String)
- **direction** (String) Direction of the cloud messaging with respect to Snowflake (required only for error notifications)
- **enabled** (Boolean)
- **gcp_pubsub_subscription_name** (String) The subscription id that Snowflake will listen to when using the GCP_PUBSUB provider.
- **id** (String) The ID of this resource.
- **notification_provider** (String) The third-party cloud message queuing service (e.g. AZURE_STORAGE_QUEUE, AWS_SQS)
- **type** (String) A type of integration
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1008,8 +1008,6 @@ golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc
golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
golang.org/x/tools v0.0.0-20200904185747-39188db58858/go.mod h1:Cj7w3i3Rnn0Xh82ur9kSqwfTHTeVxaDqrfMjpcNT6bE=
golang.org/x/tools v0.1.3 h1:L69ShwSZEyCsLKoAxDKeMvLDZkumEe8gXUZAjab0tX8=
golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.4 h1:cVngSRcfgyZCzys3KYOpCFa+4dqX/Oub9tAq00ttGVs=
golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
19 changes: 18 additions & 1 deletion pkg/resources/notification_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var notificationIntegrationSchema = map[string]*schema.Schema{
"notification_provider": &schema.Schema{
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"AZURE_STORAGE_QUEUE", "AWS_SQS"}, true),
ValidateFunc: validation.StringInSlice([]string{"AZURE_STORAGE_QUEUE", "AWS_SQS", "GCP_PUBSUB"}, true),
Description: "The third-party cloud message queuing service (e.g. AZURE_STORAGE_QUEUE, AWS_SQS)",
},
"azure_storage_queue_primary_uri": &schema.Schema{
Expand Down Expand Up @@ -78,6 +78,11 @@ var notificationIntegrationSchema = map[string]*schema.Schema{
Computed: true,
Description: "Date and time when the notification integration was created.",
},
"gcp_pubsub_subscription_name": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Description: "The subscription id that Snowflake will listen to when using the GCP_PUBSUB provider.",
},
}

// NotificationIntegration returns a pointer to the resource representing a notification integration
Expand Down Expand Up @@ -132,6 +137,9 @@ func CreateNotificationIntegration(data *schema.ResourceData, meta interface{})
if v, ok := data.GetOk("aws_sqs_role_arn"); ok {
stmt.SetString(`AWS_SQS_ROLE_ARN`, v.(string))
}
if v, ok := data.GetOk("gcp_pubsub_subscription_name"); ok {
stmt.SetString(`GCP_PUBSUB_SUBSCRIPTION_NAME`, v.(string))
}

err := snowflake.Exec(db, stmt.Statement())
if err != nil {
Expand Down Expand Up @@ -228,6 +236,10 @@ func ReadNotificationIntegration(data *schema.ResourceData, meta interface{}) er
if err = data.Set("aws_sqs_external_id", v.(string)); err != nil {
return err
}
case "GCP_PUBSUB_SUBSCRIPTION_NAME":
if err = data.Set("gcp_pubsub_subscription_name", v.(string)); err != nil {
return err
}
default:
log.Printf("[WARN] unexpected property %v returned from Snowflake", k)
}
Expand Down Expand Up @@ -292,6 +304,11 @@ func UpdateNotificationIntegration(data *schema.ResourceData, meta interface{})
stmt.SetString("AWS_SQS_ROLE_ARN", data.Get("aws_sqs_role_arn").(string))
}

if data.HasChange("gcp_pubsub_subscription_name") {
runSetStatement = true
stmt.SetString("GCP_PUBSUB_SUBSCRIPTION_NAME", data.Get("gcp_pubsub_subscription_name").(string))
}

if runSetStatement {
if err := snowflake.Exec(db, stmt.Statement()); err != nil {
return fmt.Errorf("error updating notification integration: %w", err)
Expand Down
26 changes: 26 additions & 0 deletions pkg/resources/notification_integration_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ func TestAcc_NotificationIntegration(t *testing.T) {
},
},
})

pubsubName := "projects/project-1234/subscriptions/sub2"
resource.Test(t, resource.TestCase{
Providers: providers(),
Steps: []resource.TestStep{
{
Config: gcpNotificationIntegrationConfig(accName, pubsubName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("snowflake_notification_integration.test", "name", accName),
resource.TestCheckResourceAttr("snowflake_notification_integration.test", "notification_provider", "GCP_PUBSUB"),
resource.TestCheckResourceAttr("snowflake_notification_integration.test", "gcp_pubsub_subscription_name", pubsubName),
),
},
},
})
}

func azureNotificationIntegrationConfig(name string, azureStorageQueuePrimaryUri string, azureTenantId string) string {
Expand All @@ -45,3 +60,14 @@ resource "snowflake_notification_integration" "test" {
`
return fmt.Sprintf(s, name, "AZURE_STORAGE_QUEUE", azureStorageQueuePrimaryUri, azureTenantId)
}

func gcpNotificationIntegrationConfig(name string, gcpPubsubSubscriptionName string) string {
s := `
resource "snowflake_notification_integration" "test" {
name = "%s"
notification_provider = "%s"
gcp_pubsub_subscription_name = "%s"
}
`
return fmt.Sprintf(s, name, "GCP_PUBSUB", gcpPubsubSubscriptionName)
}
18 changes: 17 additions & 1 deletion pkg/resources/notification_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ func TestNotificationIntegrationCreate(t *testing.T) {
},
expectSQL: `^CREATE NOTIFICATION INTEGRATION "test_notification_integration" AWS_SQS_ARN='some-sqs-arn' AWS_SQS_ROLE_ARN='some-iam-role-arn' COMMENT='great comment' DIRECTION='OUTBOUND' NOTIFICATION_PROVIDER='AWS_SQS' TYPE='QUEUE' ENABLED=true$`,
},
{
notificationProvider: "GCP_PUBSUB",
raw: map[string]interface{}{
"name": "test_notification_integration",
"comment": "great comment",
"notification_provider": "GCP_PUBSUB",
"gcp_pubsub_subscription_name": "some-gcp-sub-name",
},
expectSQL: `^CREATE NOTIFICATION INTEGRATION "test_notification_integration" COMMENT='great comment' GCP_PUBSUB_SUBSCRIPTION_NAME='some-gcp-sub-name' NOTIFICATION_PROVIDER='GCP_PUBSUB' TYPE='QUEUE' ENABLED=true$`,
},
}
for _, testCase := range testCases {
r := require.New(t)
Expand All @@ -73,6 +83,9 @@ func TestNotificationIntegrationRead(t *testing.T) {
{
notificationProvider: "AWS_SQS",
},
{
notificationProvider: "GCP_PUBSUB",
},
}
for _, testCase := range testCases {
r := require.New(t)
Expand Down Expand Up @@ -123,7 +136,10 @@ func expectReadNotificationIntegration(mock sqlmock.Sqlmock, notificationProvide
AddRow("AWS_SQS_ARN", "String", "some-sqs-arn", nil).
AddRow("AWS_SQS_ROLE_ARN", "String", "some-iam-role-arn", nil).
AddRow("AWS_SQS_EXTERNAL_ID", "String", "AGreatExternalID", nil)
case "GCP_PUBSUB":
descRows = descRows.
AddRow("NOTIFICATION_PROVIDER", "String", notificationProvider, nil).
AddRow("GCP_PUBSUB_SUBSCRIPTION_NAME", "String", "some-gcp-sub-name", nil)
}

mock.ExpectQuery(`DESCRIBE NOTIFICATION INTEGRATION "test_notification_integration"$`).WillReturnRows(descRows)
}