Skip to content

Commit

Permalink
fix: Update failover group allowed integration types (#2776)
Browse files Browse the repository at this point in the history
- Add missing types in SDK
- Update resource docs
- Update tests

<!-- Feel free to delete comments as you fill this in -->

<!-- summary of changes -->

## Test Plan
<!-- detail ways in which this PR has been tested or needs to be tested
-->
* [x] acceptance tests -- tested locally with Business Critical Edition
<!-- add more below if you think they are relevant -->
* [x] integration tests

## References
<!-- issues documentation links, etc  -->
https://docs.snowflake.com/en/sql-reference/sql/create-failover-group

Based on
#2518
  • Loading branch information
sfc-gh-jmichalak committed May 7, 2024
1 parent 02f467e commit efde48d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docs/resources/failover_group.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <org_name>.<target_account_name>
- `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.
Expand Down
2 changes: 1 addition & 1 deletion pkg/resources/failover_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 6 additions & 2 deletions pkg/resources/failover_group_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
Expand Down Expand Up @@ -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"
Expand Down
10 changes: 6 additions & 4 deletions pkg/sdk/failover_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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))
Expand Down
4 changes: 4 additions & 0 deletions pkg/sdk/testint/failover_groups_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit efde48d

Please sign in to comment.