-
Notifications
You must be signed in to change notification settings - Fork 399
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Previously, if both `URL` and `STORAGE_INTEGRATION` had been updated the provider would generate separate ALTER STAGE commands - one for `URL`, and another for `STORAGE` integration. This can create an invalid change because: - When changing `URL`: the new `URL` could be invalid with the existing storage integration `STORAGE_ALLOWED_LOCATIONS` - When changing STORAGE_INTEGRATION: existing `URL` not present in the new storage integration `STORAGE_ALLOWED_LOCATIONS` This MR now checks if both `URL` and `STORAGE_INTEGRATION` have changed and issues a single `ALTER` statement with both changes in one go. Before: ALTER STAGE the_stage SET URL = 's3://the_new_url' ALTER STAGE the_stage SET STORAGE_INTEGRATION = "new_storage_integration" Now: ALTER STAGE the_stage SET STORAGE_INTEGRATION = "new_storage_integration" URL = 's3://the_new_url' ## Test Plan * We have added tests for `ChangeStorageIntegrationAndUrl` (newly added function) * We have added acceptance tests that replicate the bug (and prove this PR fixes it) * We have added tests for `Stage` resource update to ensure: * The combined `ALTER STAGE` is only issued when both `URL` and `STORAGE_INTEGRATION` change * Existing behavior remains unchanged when only one of `URL` and `STORAGE_INTEGRATION` change ## References * Fixes #1982 * https://docs.snowflake.com/en/sql-reference/sql/alter-stage Co-authored-by: Miguel Duarte <miguel.duarte@johnlewis.co.uk>
- Loading branch information
Showing
5 changed files
with
163 additions
and
10 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,68 @@ | ||
package resources_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestAccAlterStageWhenBothURLAndStorageIntegrationChange(t *testing.T) { | ||
name := acctest.RandStringFromCharSet(10, acctest.CharSetAlpha) | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
Providers: providers(), | ||
CheckDestroy: nil, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: stageIntegrationConfig(name, "si1", "s3://foo/"), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("snowflake_stage.test", "name", name), | ||
resource.TestCheckResourceAttr("snowflake_stage.test", "url", "s3://foo/"), | ||
), | ||
Destroy: false, | ||
}, | ||
{ | ||
Config: stageIntegrationConfig(name, "changed", "s3://changed/"), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("snowflake_stage.test", "name", name), | ||
resource.TestCheckResourceAttr("snowflake_stage.test", "url", "s3://changed/"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func stageIntegrationConfig(name string, siNameSuffix string, url string) string { | ||
resources := ` | ||
resource "snowflake_database" "test" { | ||
name = "%s" | ||
comment = "Terraform acceptance test" | ||
} | ||
resource "snowflake_schema" "test" { | ||
name = "%s" | ||
database = snowflake_database.test.name | ||
comment = "Terraform acceptance test" | ||
} | ||
resource "snowflake_storage_integration" "test" { | ||
name = "%s%s" | ||
storage_allowed_locations = ["%s"] | ||
storage_provider = "S3" | ||
storage_aws_role_arn = "arn:aws:iam::000000000001:/role/test" | ||
} | ||
resource "snowflake_stage" "test" { | ||
name = "%s" | ||
url = "%s" | ||
storage_integration = snowflake_storage_integration.test.name | ||
schema = snowflake_schema.test.name | ||
database = snowflake_database.test.name | ||
} | ||
` | ||
|
||
return fmt.Sprintf(resources, name, name, name, siNameSuffix, url, name, url) | ||
} |
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
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