From efde48db07a9eb47c34a5febf1b4de6e4f0671f9 Mon Sep 17 00:00:00 2001 From: Jakub Michalak Date: Tue, 7 May 2024 10:08:40 +0200 Subject: [PATCH] fix: Update failover group allowed integration types (#2776) - Add missing types in SDK - Update resource docs - Update tests ## Test Plan * [x] acceptance tests -- tested locally with Business Critical Edition * [x] integration tests ## References https://docs.snowflake.com/en/sql-reference/sql/create-failover-group Based on https://github.com/Snowflake-Labs/terraform-provider-snowflake/pull/2518 --- docs/resources/failover_group.md | 2 +- pkg/resources/failover_group.go | 2 +- pkg/resources/failover_group_acceptance_test.go | 8 ++++++-- pkg/sdk/failover_groups.go | 10 ++++++---- pkg/sdk/testint/failover_groups_integration_test.go | 4 ++++ 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/docs/resources/failover_group.md b/docs/resources/failover_group.md index 0eaffe0d1c..ee4fc6537b 100644 --- a/docs/resources/failover_group.md +++ b/docs/resources/failover_group.md @@ -59,7 +59,7 @@ resource "snowflake_failover_group" "target_failover_group" { - `allowed_accounts` (Set of String) Specifies the target account or list of target accounts to which replication and failover of specified objects from the source account is enabled. Secondary failover groups in the target accounts in this list can be promoted to serve as the primary failover group in case of failover. Expected in the form . - `allowed_databases` (Set of String) Specifies the database or list of databases for which you are enabling replication and failover from the source account to the target account. The OBJECT_TYPES list must include DATABASES to set this parameter. -- `allowed_integration_types` (Set of String) Type(s) of integrations for which you are enabling replication and failover from the source account to the target account. This property requires that the OBJECT_TYPES list include INTEGRATIONS to set this parameter. The following integration types are supported: "SECURITY INTEGRATIONS", "API INTEGRATIONS" +- `allowed_integration_types` (Set of String) Type(s) of integrations for which you are enabling replication and failover from the source account to the target account. This property requires that the OBJECT_TYPES list include INTEGRATIONS to set this parameter. The following integration types are supported: "SECURITY INTEGRATIONS", "API INTEGRATIONS", "STORAGE INTEGRATIONS", "EXTERNAL ACCESS INTEGRATIONS", "NOTIFICATION INTEGRATIONS" - `allowed_shares` (Set of String) Specifies the share or list of shares for which you are enabling replication and failover from the source account to the target account. The OBJECT_TYPES list must include SHARES to set this parameter. - `from_replica` (Block List, Max: 1) Specifies the name of the replica to use as the source for the failover group. (see [below for nested schema](#nestedblock--from_replica)) - `ignore_edition_check` (Boolean) Allows replicating objects to accounts on lower editions. diff --git a/pkg/resources/failover_group.go b/pkg/resources/failover_group.go index be045fdb1a..eb2eb76bda 100644 --- a/pkg/resources/failover_group.go +++ b/pkg/resources/failover_group.go @@ -50,7 +50,7 @@ var failoverGroupSchema = map[string]*schema.Schema{ Elem: &schema.Schema{Type: schema.TypeString}, Optional: true, ConflictsWith: []string{"from_replica"}, - Description: "Type(s) of integrations for which you are enabling replication and failover from the source account to the target account. This property requires that the OBJECT_TYPES list include INTEGRATIONS to set this parameter. The following integration types are supported: \"SECURITY INTEGRATIONS\", \"API INTEGRATIONS\"", + Description: "Type(s) of integrations for which you are enabling replication and failover from the source account to the target account. This property requires that the OBJECT_TYPES list include INTEGRATIONS to set this parameter. The following integration types are supported: \"SECURITY INTEGRATIONS\", \"API INTEGRATIONS\", \"STORAGE INTEGRATIONS\", \"EXTERNAL ACCESS INTEGRATIONS\", \"NOTIFICATION INTEGRATIONS\"", }, "allowed_accounts": { Type: schema.TypeSet, diff --git a/pkg/resources/failover_group_acceptance_test.go b/pkg/resources/failover_group_acceptance_test.go index 79e4c012b2..4d5efad688 100644 --- a/pkg/resources/failover_group_acceptance_test.go +++ b/pkg/resources/failover_group_acceptance_test.go @@ -34,7 +34,11 @@ func TestAcc_FailoverGroupBasic(t *testing.T) { resource.TestCheckResourceAttr("snowflake_failover_group.fg", "object_types.#", "4"), resource.TestCheckResourceAttr("snowflake_failover_group.fg", "allowed_accounts.#", "1"), resource.TestCheckResourceAttr("snowflake_failover_group.fg", "allowed_databases.#", "1"), - resource.TestCheckResourceAttr("snowflake_failover_group.fg", "allowed_integration_types.#", "1"), + resource.TestCheckTypeSetElemAttr("snowflake_failover_group.fg", "allowed_integration_types.*", "SECURITY INTEGRATIONS"), + resource.TestCheckTypeSetElemAttr("snowflake_failover_group.fg", "allowed_integration_types.*", "API INTEGRATIONS"), + resource.TestCheckTypeSetElemAttr("snowflake_failover_group.fg", "allowed_integration_types.*", "STORAGE INTEGRATIONS"), + resource.TestCheckTypeSetElemAttr("snowflake_failover_group.fg", "allowed_integration_types.*", "EXTERNAL ACCESS INTEGRATIONS"), + resource.TestCheckTypeSetElemAttr("snowflake_failover_group.fg", "allowed_integration_types.*", "NOTIFICATION INTEGRATIONS"), resource.TestCheckResourceAttr("snowflake_failover_group.fg", "replication_schedule.0.cron.0.expression", "0 0 10-20 * TUE,THU"), resource.TestCheckResourceAttr("snowflake_failover_group.fg", "replication_schedule.0.cron.0.time_zone", "UTC"), ), @@ -259,7 +263,7 @@ resource "snowflake_failover_group" "fg" { object_types = ["WAREHOUSES", "DATABASES", "INTEGRATIONS", "ROLES"] allowed_accounts= ["%s"] allowed_databases = ["%s"] - allowed_integration_types = ["SECURITY INTEGRATIONS"] + allowed_integration_types = ["SECURITY INTEGRATIONS", "API INTEGRATIONS", "STORAGE INTEGRATIONS", "EXTERNAL ACCESS INTEGRATIONS", "NOTIFICATION INTEGRATIONS"] replication_schedule { cron { expression = "0 0 10-20 * TUE,THU" diff --git a/pkg/sdk/failover_groups.go b/pkg/sdk/failover_groups.go index 3ee16460b5..094ae6bf36 100644 --- a/pkg/sdk/failover_groups.go +++ b/pkg/sdk/failover_groups.go @@ -45,9 +45,11 @@ type failoverGroups struct { type IntegrationType string const ( - IntegrationTypeSecurityIntegrations IntegrationType = "SECURITY INTEGRATIONS" - IntegrationTypeAPIIntegrations IntegrationType = "API INTEGRATIONS" - IntegrationTypeNotificationIntegrations IntegrationType = "NOTIFICATION INTEGRATIONS" + IntegrationTypeSecurityIntegrations IntegrationType = "SECURITY INTEGRATIONS" + IntegrationTypeAPIIntegrations IntegrationType = "API INTEGRATIONS" + IntegrationTypeStorageIntegrations IntegrationType = "STORAGE INTEGRATIONS" + IntegrationTypeExternalAccessIntegrations IntegrationType = "EXTERNAL ACCESS INTEGRATIONS" + IntegrationTypeNotificationIntegrations IntegrationType = "NOTIFICATION INTEGRATIONS" ) // CreateFailoverGroupOptions is based on https://docs.snowflake.com/en/sql-reference/sql/create-failover-group. @@ -423,7 +425,7 @@ func (row failoverGroupDBRow) convert() *FailoverGroup { if it == "" { continue } - allowedIntegrationTypes = append(allowedIntegrationTypes, IntegrationType(strings.TrimSpace(it)+" INTEGRATIONS")) + allowedIntegrationTypes = append(allowedIntegrationTypes, IntegrationType(strings.ReplaceAll(strings.TrimSpace(it), "_", " ")+" INTEGRATIONS")) } aas := strings.Split(row.AllowedAccounts, ",") allowedAccounts := make([]AccountIdentifier, 0, len(aas)) diff --git a/pkg/sdk/testint/failover_groups_integration_test.go b/pkg/sdk/testint/failover_groups_integration_test.go index 3af87d2e66..c9571a153b 100644 --- a/pkg/sdk/testint/failover_groups_integration_test.go +++ b/pkg/sdk/testint/failover_groups_integration_test.go @@ -113,12 +113,16 @@ func TestInt_FailoverGroupsCreate(t *testing.T) { id := testClientHelper().Ids.RandomAccountObjectIdentifier() objectTypes := []sdk.PluralObjectType{ sdk.PluralObjectTypeIntegrations, + sdk.PluralObjectTypeRoles, } allowedAccounts := []sdk.AccountIdentifier{ businessCriticalAccountId, } allowedIntegrationTypes := []sdk.IntegrationType{ + sdk.IntegrationTypeSecurityIntegrations, sdk.IntegrationTypeAPIIntegrations, + sdk.IntegrationTypeStorageIntegrations, + sdk.IntegrationTypeExternalAccessIntegrations, sdk.IntegrationTypeNotificationIntegrations, } err := client.FailoverGroups.Create(ctx, id, objectTypes, allowedAccounts, &sdk.CreateFailoverGroupOptions{