From 31e7e9562f04b085ad9a0cd0c79eff83e36b78a1 Mon Sep 17 00:00:00 2001 From: James Doldissen Date: Sun, 29 Sep 2024 11:33:57 +0200 Subject: [PATCH] Fix typo, clean up acceptance tests and fix implementation of LongestCommonPrefix --- docs/resources/external_volume.md | 2 +- pkg/resources/external_volume.go | 2 +- .../external_volume_acceptance_test.go | 344 +++++++++++------- pkg/resources/helpers.go | 2 +- pkg/resources/helpers_test.go | 102 +++--- 5 files changed, 259 insertions(+), 193 deletions(-) diff --git a/docs/resources/external_volume.md b/docs/resources/external_volume.md index 2bfd4c4e012..3e9d24c8e9e 100644 --- a/docs/resources/external_volume.md +++ b/docs/resources/external_volume.md @@ -17,7 +17,7 @@ Resource used to manage external volume objects. For more information, check [ex ### Required - `name` (String) Identifier for the external volume; must be unique for your account. Due to technical limitations (read more [here](https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/docs/technical-documentation/identifiers_rework_design_decisions.md#known-limitations-and-identifier-recommendations)), avoid using the following characters: `|`, `.`, `(`, `)`, `"` -- `storage_location` (Block List, Min: 1) Set of named cloud storage locations in different regions and, optionally, cloud platforms. Minimum 1 required. Note that not all parameter combindations are valid as they depend on the given storage_provider. Consult [the docs](https://docs.snowflake.com/en/sql-reference/sql/create-external-volume#cloud-provider-parameters-cloudproviderparams) for more details on this. (see [below for nested schema](#nestedblock--storage_location)) +- `storage_location` (Block List, Min: 1) List of named cloud storage locations in different regions and, optionally, cloud platforms. Minimum 1 required. Note that not all parameter combinations are valid as they depend on the given storage_provider. Consult [the docs](https://docs.snowflake.com/en/sql-reference/sql/create-external-volume#cloud-provider-parameters-cloudproviderparams) for more details on this. (see [below for nested schema](#nestedblock--storage_location)) ### Optional diff --git a/pkg/resources/external_volume.go b/pkg/resources/external_volume.go index 3f11a614c7b..89c7e6e6d76 100644 --- a/pkg/resources/external_volume.go +++ b/pkg/resources/external_volume.go @@ -31,7 +31,7 @@ var externalVolumeSchema = map[string]*schema.Schema{ Type: schema.TypeList, Required: true, MinItems: 1, - Description: "Set of named cloud storage locations in different regions and, optionally, cloud platforms. Minimum 1 required. Note that not all parameter combindations are valid as they depend on the given storage_provider. Consult [the docs](https://docs.snowflake.com/en/sql-reference/sql/create-external-volume#cloud-provider-parameters-cloudproviderparams) for more details on this.", + Description: "List of named cloud storage locations in different regions and, optionally, cloud platforms. Minimum 1 required. Note that not all parameter combinations are valid as they depend on the given storage_provider. Consult [the docs](https://docs.snowflake.com/en/sql-reference/sql/create-external-volume#cloud-provider-parameters-cloudproviderparams) for more details on this.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "storage_location_name": { diff --git a/pkg/resources/external_volume_acceptance_test.go b/pkg/resources/external_volume_acceptance_test.go index 8fe746f3a35..e6a7e4cd799 100644 --- a/pkg/resources/external_volume_acceptance_test.go +++ b/pkg/resources/external_volume_acceptance_test.go @@ -45,13 +45,14 @@ var ( ) var ( - s3StorageLocation = getS3StorageLocation(s3StorageLocationName, s3StorageProvider, s3StorageBaseUrl, s3StorageAwsRoleArn, s3EncryptionTypeNone, "") - s3StorageLocationUpdatedBaseUrl = getS3StorageLocation(s3StorageLocationName, s3StorageProvider, s3StorageBaseUrl2, s3StorageAwsRoleArn, s3EncryptionTypeNone, "") - s3StorageLocationUpdatedRoleArn = getS3StorageLocation(s3StorageLocationName, s3StorageProvider, s3StorageBaseUrl, s3StorageAwsRoleArn2, s3EncryptionTypeNone, "") - s3StorageLocationUpdatedName = getS3StorageLocation(s3StorageLocationName2, s3StorageProvider, s3StorageBaseUrl, s3StorageAwsRoleArn, s3EncryptionTypeNone, "") - s3StorageLocationSseEncryption = getS3StorageLocation(s3StorageLocationName, s3StorageProvider, s3StorageBaseUrl, s3StorageAwsRoleArn, s3EncryptionTypeSseS3, "") - s3StorageLocationKmsEncryption = getS3StorageLocation(s3StorageLocationName, s3StorageProvider, s3StorageBaseUrl, s3StorageAwsRoleArn, s3EncryptionTypeSseKms, s3EncryptionKmsKeyId) - s3StorageLocationKmsEncryptionUpdatedKey = getS3StorageLocation(s3StorageLocationName, s3StorageProvider, s3StorageBaseUrl, s3StorageAwsRoleArn, s3EncryptionTypeSseKms, s3EncryptionKmsKeyId2) + s3StorageLocation = getS3StorageLocation(s3StorageLocationName, s3StorageProvider, s3StorageBaseUrl, s3StorageAwsRoleArn, s3EncryptionTypeNone, "") + s3StorageLocationUpdatedBaseUrl = getS3StorageLocation(s3StorageLocationName, s3StorageProvider, s3StorageBaseUrl2, s3StorageAwsRoleArn, s3EncryptionTypeNone, "") + s3StorageLocationUpdatedRoleArn = getS3StorageLocation(s3StorageLocationName, s3StorageProvider, s3StorageBaseUrl, s3StorageAwsRoleArn2, s3EncryptionTypeNone, "") + s3StorageLocationUpdatedName = getS3StorageLocation(s3StorageLocationName2, s3StorageProvider, s3StorageBaseUrl, s3StorageAwsRoleArn, s3EncryptionTypeNone, "") + s3StorageLocationSseEncryption = getS3StorageLocation(s3StorageLocationName, s3StorageProvider, s3StorageBaseUrl, s3StorageAwsRoleArn, s3EncryptionTypeSseS3, "") + s3StorageLocationKmsEncryption = getS3StorageLocation(s3StorageLocationName, s3StorageProvider, s3StorageBaseUrl, s3StorageAwsRoleArn, s3EncryptionTypeSseKms, s3EncryptionKmsKeyId) + s3StorageLocationKmsEncryptionUpdatedName = getS3StorageLocation(s3StorageLocationName2, s3StorageProvider, s3StorageBaseUrl, s3StorageAwsRoleArn, s3EncryptionTypeSseKms, s3EncryptionKmsKeyId) + s3StorageLocationKmsEncryptionUpdatedKey = getS3StorageLocation(s3StorageLocationName, s3StorageProvider, s3StorageBaseUrl, s3StorageAwsRoleArn, s3EncryptionTypeSseKms, s3EncryptionKmsKeyId2) ) var ( @@ -67,11 +68,12 @@ var ( ) var ( - gcsStorageLocation = getGcsStorageLocation(gcsStorageLocationName, gcsStorageBaseUrl, gcsEncryptionTypeNone, "") - gcsStorageLocationUpdatedName = getGcsStorageLocation(gcsStorageLocationName2, gcsStorageBaseUrl, gcsEncryptionTypeNone, "") - gcsStorageLocationUpdatedBaseUrl = getGcsStorageLocation(gcsStorageLocationName, gcsStorageBaseUrl2, gcsEncryptionTypeNone, "") - gcsStorageLocationKmsEncryption = getGcsStorageLocation(gcsStorageLocationName, gcsStorageBaseUrl, gcsEncryptionTypeSseKms, gcsEncryptionKmsKeyId) - gcsStorageLocationKmsEncryptionUpdatedKey = getGcsStorageLocation(gcsStorageLocationName, gcsStorageBaseUrl, gcsEncryptionTypeSseKms, gcsEncryptionKmsKeyId2) + gcsStorageLocation = getGcsStorageLocation(gcsStorageLocationName, gcsStorageBaseUrl, gcsEncryptionTypeNone, "") + gcsStorageLocationUpdatedName = getGcsStorageLocation(gcsStorageLocationName2, gcsStorageBaseUrl, gcsEncryptionTypeNone, "") + gcsStorageLocationUpdatedBaseUrl = getGcsStorageLocation(gcsStorageLocationName, gcsStorageBaseUrl2, gcsEncryptionTypeNone, "") + gcsStorageLocationKmsEncryption = getGcsStorageLocation(gcsStorageLocationName, gcsStorageBaseUrl, gcsEncryptionTypeSseKms, gcsEncryptionKmsKeyId) + gcsStorageLocationKmsEncryptionUpdatedName = getGcsStorageLocation(gcsStorageLocationName2, gcsStorageBaseUrl, gcsEncryptionTypeSseKms, gcsEncryptionKmsKeyId) + gcsStorageLocationKmsEncryptionUpdatedKey = getGcsStorageLocation(gcsStorageLocationName, gcsStorageBaseUrl, gcsEncryptionTypeSseKms, gcsEncryptionKmsKeyId2) ) var ( @@ -226,7 +228,7 @@ func TestAcc_External_Volume_S3(t *testing.T) { HasStorageLocationLength(1), ), }, - // set optionals + // set external volume optionals { ConfigDirectory: acc.ConfigurationDirectory("TestAcc_ExternalVolume/s3/complete"), ConfigVariables: externalVolume(config.ListVariable(s3StorageLocation), externalVolumeName, comment, allowWritesTrue), @@ -249,7 +251,7 @@ func TestAcc_External_Volume_S3(t *testing.T) { assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "describe_output.#", "4")), ), }, - // import - with optionals + // import - with external volume optionals { ConfigDirectory: acc.ConfigurationDirectory("TestAcc_ExternalVolume/s3/complete"), ConfigVariables: externalVolume(config.ListVariable(s3StorageLocation), externalVolumeName, comment, allowWritesTrue), @@ -257,7 +259,44 @@ func TestAcc_External_Volume_S3(t *testing.T) { ImportState: true, ImportStateVerify: true, }, - // update comment + // add second storage location without s3 optionals + { + ConfigDirectory: acc.ConfigurationDirectory("TestAcc_ExternalVolume/s3/complete"), + ConfigVariables: externalVolume(config.ListVariable(s3StorageLocation, s3StorageLocationUpdatedName), externalVolumeName, comment, allowWritesTrue), + Check: assert.AssertThat(t, + resourceassert.ExternalVolumeResource(t, "snowflake_external_volume.complete"). + HasNameString(externalVolumeName). + HasCommentString(comment). + HasAllowWritesString(allowWritesTrue). + HasStorageLocationLength(2), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.0.storage_location_name", s3StorageLocationName)), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.0.storage_provider", s3StorageProvider)), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.0.storage_base_url", s3StorageBaseUrl)), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.0.storage_aws_role_arn", s3StorageAwsRoleArn)), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.0.encryption_type", s3EncryptionTypeNone)), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.0.encryption_kms_key_id", "")), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.1.storage_location_name", s3StorageLocationName2)), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.1.storage_provider", s3StorageProvider)), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.1.storage_base_url", s3StorageBaseUrl)), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.1.storage_aws_role_arn", s3StorageAwsRoleArn)), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.1.encryption_type", s3EncryptionTypeNone)), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.1.encryption_kms_key_id", "")), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "show_output.#", "1")), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "show_output.0.name", externalVolumeName)), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "show_output.0.allow_writes", allowWritesTrue)), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "show_output.0.comment", comment)), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "describe_output.#", "5")), + ), + }, + // import - 2 storage locations without all s3 optionals set + { + ConfigDirectory: acc.ConfigurationDirectory("TestAcc_ExternalVolume/s3/complete"), + ConfigVariables: externalVolume(config.ListVariable(s3StorageLocation, s3StorageLocationUpdatedName), externalVolumeName, comment, allowWritesTrue), + ResourceName: "snowflake_external_volume.complete", + ImportState: true, + ImportStateVerify: true, + }, + // update comment and change back to 1 storage location { ConfigDirectory: acc.ConfigurationDirectory("TestAcc_ExternalVolume/s3/complete"), ConfigVariables: externalVolume(config.ListVariable(s3StorageLocation), externalVolumeName, comment2, allowWritesTrue), @@ -403,33 +442,47 @@ func TestAcc_External_Volume_S3(t *testing.T) { ImportState: true, ImportStateVerify: true, }, - // change back to sse s3 encryption + // add second storage location with all s3 optionals set { - ConfigDirectory: acc.ConfigurationDirectory("TestAcc_ExternalVolume/s3/complete-add-encryption-type"), - ConfigVariables: externalVolume(config.ListVariable(s3StorageLocationSseEncryption), externalVolumeName, comment2, allowWritesFalse), + ConfigDirectory: acc.ConfigurationDirectory("TestAcc_ExternalVolume/s3/complete-add-kms-encryption-type"), + ConfigVariables: externalVolume(config.ListVariable(s3StorageLocationKmsEncryptionUpdatedKey, s3StorageLocationKmsEncryptionUpdatedName), externalVolumeName, comment2, allowWritesFalse), Check: assert.AssertThat(t, resourceassert.ExternalVolumeResource(t, "snowflake_external_volume.complete"). HasNameString(externalVolumeName). HasCommentString(comment2). HasAllowWritesString(allowWritesFalse). - HasStorageLocationLength(1), + HasStorageLocationLength(2), assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.0.storage_location_name", s3StorageLocationName)), assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.0.storage_provider", s3StorageProvider)), assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.0.storage_base_url", s3StorageBaseUrl)), assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.0.storage_aws_role_arn", s3StorageAwsRoleArn)), - assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.0.encryption_type", s3EncryptionTypeSseS3)), - assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.0.encryption_kms_key_id", "")), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.0.encryption_type", s3EncryptionTypeSseKms)), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.0.encryption_kms_key_id", s3EncryptionKmsKeyId2)), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.1.storage_location_name", s3StorageLocationName2)), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.1.storage_provider", s3StorageProvider)), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.1.storage_base_url", s3StorageBaseUrl)), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.1.storage_aws_role_arn", s3StorageAwsRoleArn)), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.1.encryption_type", s3EncryptionTypeSseKms)), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.1.encryption_kms_key_id", s3EncryptionKmsKeyId)), assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "show_output.#", "1")), assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "show_output.0.name", externalVolumeName)), assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "show_output.0.allow_writes", allowWritesFalse)), assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "show_output.0.comment", comment2)), - assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "describe_output.#", "4")), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "describe_output.#", "5")), ), }, - // change back to none encryption + // import - 2 s3 storage locations, with all s3 optionals set + { + ConfigDirectory: acc.ConfigurationDirectory("TestAcc_ExternalVolume/s3/complete-add-kms-encryption-type"), + ConfigVariables: externalVolume(config.ListVariable(s3StorageLocationKmsEncryptionUpdatedKey, s3StorageLocationKmsEncryptionUpdatedName), externalVolumeName, comment2, allowWritesFalse), + ResourceName: "snowflake_external_volume.complete", + ImportState: true, + ImportStateVerify: true, + }, + // change back to AWS_SSE_S3 encryption with 1 s3 storage location { ConfigDirectory: acc.ConfigurationDirectory("TestAcc_ExternalVolume/s3/complete-add-encryption-type"), - ConfigVariables: externalVolume(config.ListVariable(s3StorageLocation), externalVolumeName, comment2, allowWritesFalse), + ConfigVariables: externalVolume(config.ListVariable(s3StorageLocationSseEncryption), externalVolumeName, comment2, allowWritesFalse), Check: assert.AssertThat(t, resourceassert.ExternalVolumeResource(t, "snowflake_external_volume.complete"). HasNameString(externalVolumeName). @@ -440,7 +493,7 @@ func TestAcc_External_Volume_S3(t *testing.T) { assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.0.storage_provider", s3StorageProvider)), assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.0.storage_base_url", s3StorageBaseUrl)), assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.0.storage_aws_role_arn", s3StorageAwsRoleArn)), - assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.0.encryption_type", s3EncryptionTypeNone)), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.0.encryption_type", s3EncryptionTypeSseS3)), assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.0.encryption_kms_key_id", "")), assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "show_output.#", "1")), assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "show_output.0.name", externalVolumeName)), @@ -449,9 +502,9 @@ func TestAcc_External_Volume_S3(t *testing.T) { assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "describe_output.#", "4")), ), }, - // change back to no encryption + // change back to none encryption { - ConfigDirectory: acc.ConfigurationDirectory("TestAcc_ExternalVolume/s3/complete"), + ConfigDirectory: acc.ConfigurationDirectory("TestAcc_ExternalVolume/s3/complete-add-encryption-type"), ConfigVariables: externalVolume(config.ListVariable(s3StorageLocation), externalVolumeName, comment2, allowWritesFalse), Check: assert.AssertThat(t, resourceassert.ExternalVolumeResource(t, "snowflake_external_volume.complete"). @@ -472,15 +525,15 @@ func TestAcc_External_Volume_S3(t *testing.T) { assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "describe_output.#", "4")), ), }, - // remove allow writes and comment from config + // change back to no encryption { - ConfigDirectory: acc.ConfigurationDirectory("TestAcc_ExternalVolume/s3/basic"), - ConfigVariables: externalVolume(config.ListVariable(s3StorageLocation), externalVolumeName, "", ""), + ConfigDirectory: acc.ConfigurationDirectory("TestAcc_ExternalVolume/s3/complete"), + ConfigVariables: externalVolume(config.ListVariable(s3StorageLocation), externalVolumeName, comment2, allowWritesFalse), Check: assert.AssertThat(t, resourceassert.ExternalVolumeResource(t, "snowflake_external_volume.complete"). HasNameString(externalVolumeName). - HasCommentString(""). - HasAllowWritesString(r.BooleanDefault). + HasCommentString(comment2). + HasAllowWritesString(allowWritesFalse). HasStorageLocationLength(1), assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.0.storage_location_name", s3StorageLocationName)), assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.0.storage_provider", s3StorageProvider)), @@ -491,113 +544,31 @@ func TestAcc_External_Volume_S3(t *testing.T) { assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "show_output.#", "1")), assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "show_output.0.name", externalVolumeName)), assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "show_output.0.allow_writes", allowWritesFalse)), - assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "show_output.0.comment", "")), - assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "describe_output.#", "3")), - ), - }, - // add second storage location - { - ConfigDirectory: acc.ConfigurationDirectory("TestAcc_ExternalVolume/s3/basic"), - ConfigVariables: externalVolume(config.ListVariable(s3StorageLocation, s3StorageLocationUpdatedName), externalVolumeName, "", ""), - Check: assert.AssertThat(t, - resourceassert.ExternalVolumeResource(t, "snowflake_external_volume.complete"). - HasNameString(externalVolumeName). - HasCommentString(""). - HasAllowWritesString(r.BooleanDefault). - HasStorageLocationLength(2), - assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.0.storage_location_name", s3StorageLocationName)), - assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.0.storage_provider", s3StorageProvider)), - assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.0.storage_base_url", s3StorageBaseUrl)), - assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.0.storage_aws_role_arn", s3StorageAwsRoleArn)), - assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.0.encryption_type", s3EncryptionTypeNone)), - assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.0.encryption_kms_key_id", "")), - assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.1.storage_location_name", s3StorageLocationName2)), - assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.1.storage_provider", s3StorageProvider)), - assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.1.storage_base_url", s3StorageBaseUrl)), - assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.1.storage_aws_role_arn", s3StorageAwsRoleArn)), - assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.1.encryption_type", s3EncryptionTypeNone)), - assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.1.encryption_kms_key_id", "")), - assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "show_output.#", "1")), - assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "show_output.0.name", externalVolumeName)), - assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "show_output.0.allow_writes", allowWritesFalse)), - assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "show_output.0.comment", "")), - assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "describe_output.#", "4")), - ), - }, - // externally remove storage location - { - PreConfig: func() { - acc.TestClient().ExternalVolume.Alter(t, sdk.NewAlterExternalVolumeRequest(id).WithRemoveStorageLocation(s3StorageLocationName)) - }, - ConfigDirectory: acc.ConfigurationDirectory("TestAcc_ExternalVolume/s3/basic"), - ConfigVariables: externalVolume(config.ListVariable(s3StorageLocation, s3StorageLocationUpdatedName), externalVolumeName, "", ""), - Check: assert.AssertThat(t, - resourceassert.ExternalVolumeResource(t, "snowflake_external_volume.complete"). - HasNameString(externalVolumeName). - HasCommentString(""). - HasAllowWritesString(r.BooleanDefault). - HasStorageLocationLength(2), - assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.0.storage_location_name", s3StorageLocationName)), - assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.0.storage_provider", s3StorageProvider)), - assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.0.storage_base_url", s3StorageBaseUrl)), - assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.0.storage_aws_role_arn", s3StorageAwsRoleArn)), - assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.0.encryption_type", s3EncryptionTypeNone)), - assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.0.encryption_kms_key_id", "")), - assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.1.storage_location_name", s3StorageLocationName2)), - assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.1.storage_provider", s3StorageProvider)), - assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.1.storage_base_url", s3StorageBaseUrl)), - assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.1.storage_aws_role_arn", s3StorageAwsRoleArn)), - assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.1.encryption_type", s3EncryptionTypeNone)), - assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.1.encryption_kms_key_id", "")), - assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "show_output.#", "1")), - assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "show_output.0.name", externalVolumeName)), - assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "show_output.0.allow_writes", allowWritesFalse)), - assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "show_output.0.comment", "")), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "show_output.0.comment", comment2)), assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "describe_output.#", "4")), ), }, - // externally add storage location + // remove allow writes and comment from config { - PreConfig: func() { - acc.TestClient().ExternalVolume.Alter( - t, - sdk.NewAlterExternalVolumeRequest(id).WithAddStorageLocation( - *sdk.NewExternalVolumeStorageLocationRequest().WithS3StorageLocationParams( - *sdk.NewS3StorageLocationParamsRequest( - "externally-added-s3-storage-location", - "s3", - "arn:aws:iam::123456789012:role/externally-added-role", - "s3://externally-added-bucket", - ), - ), - ), - ) - }, ConfigDirectory: acc.ConfigurationDirectory("TestAcc_ExternalVolume/s3/basic"), - ConfigVariables: externalVolume(config.ListVariable(s3StorageLocation, s3StorageLocationUpdatedName), externalVolumeName, "", ""), + ConfigVariables: externalVolume(config.ListVariable(s3StorageLocation), externalVolumeName, "", ""), Check: assert.AssertThat(t, resourceassert.ExternalVolumeResource(t, "snowflake_external_volume.complete"). HasNameString(externalVolumeName). HasCommentString(""). HasAllowWritesString(r.BooleanDefault). - HasStorageLocationLength(2), + HasStorageLocationLength(1), assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.0.storage_location_name", s3StorageLocationName)), assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.0.storage_provider", s3StorageProvider)), assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.0.storage_base_url", s3StorageBaseUrl)), assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.0.storage_aws_role_arn", s3StorageAwsRoleArn)), assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.0.encryption_type", s3EncryptionTypeNone)), assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.0.encryption_kms_key_id", "")), - assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.1.storage_location_name", s3StorageLocationName2)), - assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.1.storage_provider", s3StorageProvider)), - assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.1.storage_base_url", s3StorageBaseUrl)), - assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.1.storage_aws_role_arn", s3StorageAwsRoleArn)), - assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.1.encryption_type", s3EncryptionTypeNone)), - assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.1.encryption_kms_key_id", "")), assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "show_output.#", "1")), assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "show_output.0.name", externalVolumeName)), assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "show_output.0.allow_writes", allowWritesFalse)), assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "show_output.0.comment", "")), - assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "describe_output.#", "4")), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "describe_output.#", "3")), ), }, }, @@ -652,7 +623,7 @@ func TestAcc_External_Volume_GCS(t *testing.T) { HasStorageLocationLength(1), ), }, - // set optionals + // set external volume optionals { ConfigDirectory: acc.ConfigurationDirectory("TestAcc_ExternalVolume/gcs/complete"), ConfigVariables: externalVolume(config.ListVariable(gcsStorageLocation), externalVolumeName, comment, allowWritesTrue), @@ -674,7 +645,7 @@ func TestAcc_External_Volume_GCS(t *testing.T) { assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "describe_output.#", "4")), ), }, - // import - with optionals + // import - with external volume optionals { ConfigDirectory: acc.ConfigurationDirectory("TestAcc_ExternalVolume/gcs/complete"), ConfigVariables: externalVolume(config.ListVariable(gcsStorageLocation), externalVolumeName, comment, allowWritesTrue), @@ -682,7 +653,42 @@ func TestAcc_External_Volume_GCS(t *testing.T) { ImportState: true, ImportStateVerify: true, }, - // update comment + // add second storage location without gcs optionals + { + ConfigDirectory: acc.ConfigurationDirectory("TestAcc_ExternalVolume/gcs/complete"), + ConfigVariables: externalVolume(config.ListVariable(gcsStorageLocation, gcsStorageLocationUpdatedName), externalVolumeName, comment, allowWritesTrue), + Check: assert.AssertThat(t, + resourceassert.ExternalVolumeResource(t, "snowflake_external_volume.complete"). + HasNameString(externalVolumeName). + HasCommentString(comment). + HasAllowWritesString(allowWritesTrue). + HasStorageLocationLength(2), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.0.storage_location_name", gcsStorageLocationName)), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.0.storage_provider", gcsStorageProvider)), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.0.storage_base_url", gcsStorageBaseUrl)), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.0.encryption_type", gcsEncryptionTypeNone)), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.0.encryption_kms_key_id", "")), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.1.storage_location_name", gcsStorageLocationName2)), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.1.storage_provider", gcsStorageProvider)), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.1.storage_base_url", gcsStorageBaseUrl)), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.1.encryption_type", gcsEncryptionTypeNone)), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.1.encryption_kms_key_id", "")), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "show_output.#", "1")), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "show_output.0.name", externalVolumeName)), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "show_output.0.allow_writes", allowWritesTrue)), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "show_output.0.comment", comment)), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "describe_output.#", "5")), + ), + }, + // import - 2 storage locations without all gcs optionals set + { + ConfigDirectory: acc.ConfigurationDirectory("TestAcc_ExternalVolume/gcs/complete"), + ConfigVariables: externalVolume(config.ListVariable(gcsStorageLocation, gcsStorageLocationUpdatedName), externalVolumeName, comment, allowWritesTrue), + ResourceName: "snowflake_external_volume.complete", + ImportState: true, + ImportStateVerify: true, + }, + // update comment and change back to 1 storage location { ConfigDirectory: acc.ConfigurationDirectory("TestAcc_ExternalVolume/gcs/complete"), ConfigVariables: externalVolume(config.ListVariable(gcsStorageLocation), externalVolumeName, comment2, allowWritesTrue), @@ -800,7 +806,42 @@ func TestAcc_External_Volume_GCS(t *testing.T) { ImportState: true, ImportStateVerify: true, }, - // change back to none encryption + // add second storage location with all gcs optionals set + { + ConfigDirectory: acc.ConfigurationDirectory("TestAcc_ExternalVolume/gcs/complete-add-kms-encryption-type"), + ConfigVariables: externalVolume(config.ListVariable(gcsStorageLocationKmsEncryptionUpdatedKey, gcsStorageLocationKmsEncryptionUpdatedName), externalVolumeName, comment2, allowWritesFalse), + Check: assert.AssertThat(t, + resourceassert.ExternalVolumeResource(t, "snowflake_external_volume.complete"). + HasNameString(externalVolumeName). + HasCommentString(comment2). + HasAllowWritesString(allowWritesFalse). + HasStorageLocationLength(2), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.0.storage_location_name", gcsStorageLocationName)), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.0.storage_provider", gcsStorageProvider)), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.0.storage_base_url", gcsStorageBaseUrl)), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.0.encryption_type", gcsEncryptionTypeSseKms)), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.0.encryption_kms_key_id", gcsEncryptionKmsKeyId2)), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.1.storage_location_name", gcsStorageLocationName2)), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.1.storage_provider", gcsStorageProvider)), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.1.storage_base_url", gcsStorageBaseUrl)), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.1.encryption_type", gcsEncryptionTypeSseKms)), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.1.encryption_kms_key_id", gcsEncryptionKmsKeyId)), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "show_output.#", "1")), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "show_output.0.name", externalVolumeName)), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "show_output.0.allow_writes", allowWritesFalse)), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "show_output.0.comment", comment2)), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "describe_output.#", "5")), + ), + }, + // import - 2 gcs storage locations, with all gcs optionals set + { + ConfigDirectory: acc.ConfigurationDirectory("TestAcc_ExternalVolume/gcs/complete-add-kms-encryption-type"), + ConfigVariables: externalVolume(config.ListVariable(gcsStorageLocationKmsEncryptionUpdatedKey, gcsStorageLocationKmsEncryptionUpdatedName), externalVolumeName, comment2, allowWritesFalse), + ResourceName: "snowflake_external_volume.complete", + ImportState: true, + ImportStateVerify: true, + }, + // change back to none encryption with 1 gcs storage location { ConfigDirectory: acc.ConfigurationDirectory("TestAcc_ExternalVolume/gcs/complete-add-encryption-type"), ConfigVariables: externalVolume(config.ListVariable(gcsStorageLocation), externalVolumeName, comment2, allowWritesFalse), @@ -917,7 +958,7 @@ func TestAcc_External_Volume_Azure(t *testing.T) { HasStorageLocationLength(1), ), }, - // set optionals + // set external volume optionals { ConfigDirectory: acc.ConfigurationDirectory("TestAcc_ExternalVolume/azure/complete"), ConfigVariables: externalVolume(config.ListVariable(azureStorageLocation), externalVolumeName, comment, allowWritesTrue), @@ -938,7 +979,40 @@ func TestAcc_External_Volume_Azure(t *testing.T) { assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "describe_output.#", "4")), ), }, - // import - with optionals + // import - with external volume optionals + { + ConfigDirectory: acc.ConfigurationDirectory("TestAcc_ExternalVolume/azure/complete"), + ConfigVariables: externalVolume(config.ListVariable(azureStorageLocation), externalVolumeName, comment, allowWritesTrue), + ResourceName: "snowflake_external_volume.complete", + ImportState: true, + ImportStateVerify: true, + }, + // add second storage location + { + ConfigDirectory: acc.ConfigurationDirectory("TestAcc_ExternalVolume/azure/complete"), + ConfigVariables: externalVolume(config.ListVariable(azureStorageLocation, azureStorageLocationUpdatedName), externalVolumeName, comment, allowWritesTrue), + Check: assert.AssertThat(t, + resourceassert.ExternalVolumeResource(t, "snowflake_external_volume.complete"). + HasNameString(externalVolumeName). + HasCommentString(comment). + HasAllowWritesString(allowWritesTrue). + HasStorageLocationLength(2), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.0.storage_location_name", azureStorageLocationName)), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.0.storage_provider", azureStorageProvider)), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.0.storage_base_url", azureStorageBaseUrl)), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.0.azure_tenant_id", azureTenantId)), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.1.storage_location_name", azureStorageLocationName2)), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.1.storage_provider", azureStorageProvider)), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.1.storage_base_url", azureStorageBaseUrl)), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "storage_location.1.azure_tenant_id", azureTenantId)), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "show_output.#", "1")), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "show_output.0.name", externalVolumeName)), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "show_output.0.allow_writes", allowWritesTrue)), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "show_output.0.comment", comment)), + assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "describe_output.#", "5")), + ), + }, + // import - 2 storage locations { ConfigDirectory: acc.ConfigurationDirectory("TestAcc_ExternalVolume/azure/complete"), ConfigVariables: externalVolume(config.ListVariable(azureStorageLocation), externalVolumeName, comment, allowWritesTrue), @@ -946,7 +1020,7 @@ func TestAcc_External_Volume_Azure(t *testing.T) { ImportState: true, ImportStateVerify: true, }, - // update comment + // update comment and change back to 1 storage location { ConfigDirectory: acc.ConfigurationDirectory("TestAcc_ExternalVolume/azure/complete"), ConfigVariables: externalVolume(config.ListVariable(azureStorageLocation), externalVolumeName, comment2, allowWritesTrue), @@ -1014,7 +1088,7 @@ func TestAcc_External_Volume_Azure(t *testing.T) { } // Test volume with multiple storage locations that span multiple providers -// Test adding/removing storage locations at different positions in the store +// Test adding/removing storage locations at different positions in the storage_location list func TestAcc_External_Volume_Multiple(t *testing.T) { _ = testenvs.GetOrSkipTest(t, testenvs.EnableAcceptance) id := acc.TestClient().Ids.RandomAccountObjectIdentifier() @@ -1129,7 +1203,7 @@ func TestAcc_External_Volume_Multiple(t *testing.T) { assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "describe_output.#", "6")), ), }, - // add new s3 storage integration to position 0 + // add new s3 storage location to position 0 { ConfigDirectory: acc.ConfigurationDirectory("TestAcc_ExternalVolume/multiple/complete"), ConfigVariables: externalVolumeMultiple(config.ListVariable(s3StorageLocationUpdatedName, s3StorageLocation), config.ListVariable(gcsStorageLocation), config.ListVariable(azureStorageLocation), externalVolumeName, comment, allowWritesTrue), @@ -1166,7 +1240,7 @@ func TestAcc_External_Volume_Multiple(t *testing.T) { assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "describe_output.#", "7")), ), }, - // remove s3 storage integration at position 0 + // remove s3 storage location at position 0 { ConfigDirectory: acc.ConfigurationDirectory("TestAcc_ExternalVolume/multiple/complete"), ConfigVariables: externalVolumeMultiple(config.ListVariable(s3StorageLocation), config.ListVariable(gcsStorageLocation), config.ListVariable(azureStorageLocation), externalVolumeName, comment, allowWritesTrue), @@ -1259,7 +1333,7 @@ func TestAcc_External_Volume_Multiple(t *testing.T) { assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "describe_output.#", "6")), ), }, - // add new s3 storage integration to position 1 + // add new s3 storage location to position 1 { ConfigDirectory: acc.ConfigurationDirectory("TestAcc_ExternalVolume/multiple/complete"), ConfigVariables: externalVolumeMultiple(config.ListVariable(s3StorageLocation, s3StorageLocationUpdatedName), config.ListVariable(gcsStorageLocation), config.ListVariable(azureStorageLocation), externalVolumeName, comment, allowWritesTrue), @@ -1296,7 +1370,7 @@ func TestAcc_External_Volume_Multiple(t *testing.T) { assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "describe_output.#", "7")), ), }, - // remove s3 storage integration at position 1 + // remove s3 storage location at position 1 { ConfigDirectory: acc.ConfigurationDirectory("TestAcc_ExternalVolume/multiple/complete"), ConfigVariables: externalVolumeMultiple(config.ListVariable(s3StorageLocation), config.ListVariable(gcsStorageLocation), config.ListVariable(azureStorageLocation), externalVolumeName, comment, allowWritesTrue), @@ -1389,7 +1463,7 @@ func TestAcc_External_Volume_Multiple(t *testing.T) { assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "describe_output.#", "6")), ), }, - // add new gcs storage integration to position 2 + // add new gcs storage location to position 2 { ConfigDirectory: acc.ConfigurationDirectory("TestAcc_ExternalVolume/multiple/complete"), ConfigVariables: externalVolumeMultiple(config.ListVariable(s3StorageLocation), config.ListVariable(gcsStorageLocation, gcsStorageLocationUpdatedName), config.ListVariable(azureStorageLocation), externalVolumeName, comment, allowWritesTrue), @@ -1425,7 +1499,7 @@ func TestAcc_External_Volume_Multiple(t *testing.T) { assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "describe_output.#", "7")), ), }, - // remove gcs storage integration at position 2 + // remove gcs storage location at position 2 { ConfigDirectory: acc.ConfigurationDirectory("TestAcc_ExternalVolume/multiple/complete"), ConfigVariables: externalVolumeMultiple(config.ListVariable(s3StorageLocation), config.ListVariable(gcsStorageLocation), config.ListVariable(azureStorageLocation), externalVolumeName, comment, allowWritesTrue), @@ -1456,7 +1530,7 @@ func TestAcc_External_Volume_Multiple(t *testing.T) { assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "describe_output.#", "6")), ), }, - // add new azure storage integration to position 3 + // add new azure storage location to position 3 { ConfigDirectory: acc.ConfigurationDirectory("TestAcc_ExternalVolume/multiple/complete"), ConfigVariables: externalVolumeMultiple(config.ListVariable(s3StorageLocation), config.ListVariable(gcsStorageLocation), config.ListVariable(azureStorageLocation, azureStorageLocationUpdatedName), externalVolumeName, comment, allowWritesTrue), @@ -1492,7 +1566,7 @@ func TestAcc_External_Volume_Multiple(t *testing.T) { assert.Check(resource.TestCheckResourceAttr("snowflake_external_volume.complete", "describe_output.#", "7")), ), }, - // remove azure storage integration from position 3 + // remove azure storage location from position 3 { ConfigDirectory: acc.ConfigurationDirectory("TestAcc_ExternalVolume/multiple/complete"), ConfigVariables: externalVolumeMultiple(config.ListVariable(s3StorageLocation), config.ListVariable(gcsStorageLocation), config.ListVariable(azureStorageLocation), externalVolumeName, comment, allowWritesTrue), diff --git a/pkg/resources/helpers.go b/pkg/resources/helpers.go index 2320b537d3c..8a116306526 100644 --- a/pkg/resources/helpers.go +++ b/pkg/resources/helpers.go @@ -495,7 +495,7 @@ func LongestCommonPrefix(a []sdk.ExternalVolumeStorageLocation, b []sdk.External return -1, nil } - for i := 0; i < min(len(a), len(b)); i++ { + for i := 1; i < min(len(a), len(b)); i++ { storageLocationsAreEqual, err := StorageLocationsEqual(a[i], b[i]) if err != nil { return -1, err diff --git a/pkg/resources/helpers_test.go b/pkg/resources/helpers_test.go index a90c29a3a36..f4255c07afc 100644 --- a/pkg/resources/helpers_test.go +++ b/pkg/resources/helpers_test.go @@ -611,68 +611,34 @@ var s3StorageAwsExternalId = "1234567890" func Test_CopyStorageLocationWithTempName(t *testing.T) { t.Run("S3 storage location", func(t *testing.T) { storageLocationInput := sdk.ExternalVolumeStorageLocation{S3StorageLocationParams: &s3StorageLocationA} - - storageLocationExpectedOutput := sdk.ExternalVolumeStorageLocation{ - S3StorageLocationParams: &sdk.S3StorageLocationParams{ - Name: fmt.Sprintf("temp_%s", s3StorageLocationName), - StorageProvider: sdk.S3StorageProviderS3, - StorageBaseUrl: s3StorageBaseUrl, - StorageAwsRoleArn: s3StorageAwsRoleArn, - StorageAwsExternalId: &s3StorageAwsExternalId, - Encryption: &sdk.ExternalVolumeS3Encryption{ - Type: sdk.S3EncryptionTypeSseKms, - KmsKeyId: &s3EncryptionKmsKeyId, - }, - }, - } - copiedStorageLocation, err := resources.CopyStorageLocationWithTempName(storageLocationInput) require.NoError(t, err) - assert.Equal(t, copiedStorageLocation.S3StorageLocationParams.Name, storageLocationExpectedOutput.S3StorageLocationParams.Name) - assert.Equal(t, copiedStorageLocation.S3StorageLocationParams.StorageProvider, storageLocationExpectedOutput.S3StorageLocationParams.StorageProvider) - assert.Equal(t, copiedStorageLocation.S3StorageLocationParams.StorageBaseUrl, storageLocationExpectedOutput.S3StorageLocationParams.StorageBaseUrl) - assert.Equal(t, copiedStorageLocation.S3StorageLocationParams.StorageAwsRoleArn, storageLocationExpectedOutput.S3StorageLocationParams.StorageAwsRoleArn) - assert.Equal(t, copiedStorageLocation.S3StorageLocationParams.StorageAwsExternalId, storageLocationExpectedOutput.S3StorageLocationParams.StorageAwsExternalId) - assert.Equal(t, copiedStorageLocation.S3StorageLocationParams.Encryption.Type, storageLocationExpectedOutput.S3StorageLocationParams.Encryption.Type) - assert.Equal(t, *copiedStorageLocation.S3StorageLocationParams.Encryption.KmsKeyId, *storageLocationExpectedOutput.S3StorageLocationParams.Encryption.KmsKeyId) + assert.Equal(t, copiedStorageLocation.S3StorageLocationParams.Name, fmt.Sprintf("temp_%s", s3StorageLocationA.Name)) + assert.Equal(t, copiedStorageLocation.S3StorageLocationParams.StorageProvider, s3StorageLocationA.StorageProvider) + assert.Equal(t, copiedStorageLocation.S3StorageLocationParams.StorageBaseUrl, s3StorageLocationA.StorageBaseUrl) + assert.Equal(t, copiedStorageLocation.S3StorageLocationParams.StorageAwsRoleArn, s3StorageLocationA.StorageAwsRoleArn) + assert.Equal(t, copiedStorageLocation.S3StorageLocationParams.StorageAwsExternalId, s3StorageLocationA.StorageAwsExternalId) + assert.Equal(t, copiedStorageLocation.S3StorageLocationParams.Encryption.Type, s3StorageLocationA.Encryption.Type) + assert.Equal(t, *copiedStorageLocation.S3StorageLocationParams.Encryption.KmsKeyId, *s3StorageLocationA.Encryption.KmsKeyId) }) t.Run("GCS storage location", func(t *testing.T) { storageLocationInput := sdk.ExternalVolumeStorageLocation{GCSStorageLocationParams: &gcsStorageLocationA} - storageLocationExpectedOutput := sdk.ExternalVolumeStorageLocation{ - GCSStorageLocationParams: &sdk.GCSStorageLocationParams{ - Name: fmt.Sprintf("temp_%s", gcsStorageLocationName), - StorageBaseUrl: gcsStorageBaseUrl, - Encryption: &sdk.ExternalVolumeGCSEncryption{ - Type: sdk.GCSEncryptionTypeSseKms, - KmsKeyId: &gcsEncryptionKmsKeyId, - }, - }, - } - copiedStorageLocation, err := resources.CopyStorageLocationWithTempName(storageLocationInput) require.NoError(t, err) - assert.Equal(t, copiedStorageLocation.GCSStorageLocationParams.Name, storageLocationExpectedOutput.GCSStorageLocationParams.Name) - assert.Equal(t, copiedStorageLocation.GCSStorageLocationParams.StorageBaseUrl, storageLocationExpectedOutput.GCSStorageLocationParams.StorageBaseUrl) - assert.Equal(t, copiedStorageLocation.GCSStorageLocationParams.Encryption.Type, storageLocationExpectedOutput.GCSStorageLocationParams.Encryption.Type) - assert.Equal(t, *copiedStorageLocation.GCSStorageLocationParams.Encryption.KmsKeyId, *storageLocationExpectedOutput.GCSStorageLocationParams.Encryption.KmsKeyId) + assert.Equal(t, copiedStorageLocation.GCSStorageLocationParams.Name, fmt.Sprintf("temp_%s", gcsStorageLocationA.Name)) + assert.Equal(t, copiedStorageLocation.GCSStorageLocationParams.StorageBaseUrl, gcsStorageLocationA.StorageBaseUrl) + assert.Equal(t, copiedStorageLocation.GCSStorageLocationParams.Encryption.Type, gcsStorageLocationA.Encryption.Type) + assert.Equal(t, *copiedStorageLocation.GCSStorageLocationParams.Encryption.KmsKeyId, *gcsStorageLocationA.Encryption.KmsKeyId) }) t.Run("Azure storage location", func(t *testing.T) { storageLocationInput := sdk.ExternalVolumeStorageLocation{AzureStorageLocationParams: &azureStorageLocationA} - storageLocationExpectedOutput := sdk.ExternalVolumeStorageLocation{ - AzureStorageLocationParams: &sdk.AzureStorageLocationParams{ - Name: fmt.Sprintf("temp_%s", azureStorageLocationName), - StorageBaseUrl: azureStorageBaseUrl, - AzureTenantId: azureTenantId, - }, - } - copiedStorageLocation, err := resources.CopyStorageLocationWithTempName(storageLocationInput) require.NoError(t, err) - assert.Equal(t, copiedStorageLocation.AzureStorageLocationParams.Name, storageLocationExpectedOutput.AzureStorageLocationParams.Name) - assert.Equal(t, copiedStorageLocation.AzureStorageLocationParams.StorageBaseUrl, storageLocationExpectedOutput.AzureStorageLocationParams.StorageBaseUrl) - assert.Equal(t, copiedStorageLocation.AzureStorageLocationParams.AzureTenantId, storageLocationExpectedOutput.AzureStorageLocationParams.AzureTenantId) + assert.Equal(t, copiedStorageLocation.AzureStorageLocationParams.Name, fmt.Sprintf("temp_%s", azureStorageLocationA.Name)) + assert.Equal(t, copiedStorageLocation.AzureStorageLocationParams.StorageBaseUrl, azureStorageLocationA.StorageBaseUrl) + assert.Equal(t, copiedStorageLocation.AzureStorageLocationParams.AzureTenantId, azureStorageLocationA.AzureTenantId) }) invalidTestCases := []struct { @@ -719,17 +685,29 @@ func Test_LongestCommonPrefix(t *testing.T) { ExpectedOutput: -1, }, { - Name: "One empty list", + Name: "First list empty", ListA: []sdk.ExternalVolumeStorageLocation{}, ListB: []sdk.ExternalVolumeStorageLocation{{S3StorageLocationParams: &s3StorageLocationA}}, ExpectedOutput: -1, }, { - Name: "Lists with no common prefix", + Name: "Second list empty", + ListA: []sdk.ExternalVolumeStorageLocation{{S3StorageLocationParams: &s3StorageLocationA}}, + ListB: []sdk.ExternalVolumeStorageLocation{}, + ExpectedOutput: -1, + }, + { + Name: "Lists with no common prefix - length 1", ListA: []sdk.ExternalVolumeStorageLocation{{S3StorageLocationParams: &s3StorageLocationA}}, ListB: []sdk.ExternalVolumeStorageLocation{{S3StorageLocationParams: &s3StorageLocationB}}, ExpectedOutput: -1, }, + { + Name: "Lists with no common prefix - length 2", + ListA: []sdk.ExternalVolumeStorageLocation{{S3StorageLocationParams: &s3StorageLocationA}, {AzureStorageLocationParams: &azureStorageLocationA}}, + ListB: []sdk.ExternalVolumeStorageLocation{{S3StorageLocationParams: &s3StorageLocationB}, {AzureStorageLocationParams: &azureStorageLocationB}}, + ExpectedOutput: -1, + }, { Name: "Identical lists - length 1", ListA: []sdk.ExternalVolumeStorageLocation{{S3StorageLocationParams: &s3StorageLocationA}}, @@ -743,7 +721,21 @@ func Test_LongestCommonPrefix(t *testing.T) { ExpectedOutput: 1, }, { - Name: "Lists with a common prefix - length 3, matching til last element", + Name: "Identical lists - length 3", + ListA: []sdk.ExternalVolumeStorageLocation{ + {S3StorageLocationParams: &s3StorageLocationA}, + {AzureStorageLocationParams: &azureStorageLocationA}, + {S3StorageLocationParams: &s3GovStorageLocationA}, + }, + ListB: []sdk.ExternalVolumeStorageLocation{ + {S3StorageLocationParams: &s3StorageLocationA}, + {AzureStorageLocationParams: &azureStorageLocationA}, + {S3StorageLocationParams: &s3GovStorageLocationA}, + }, + ExpectedOutput: 2, + }, + { + Name: "Lists with a common prefix - length 3, matching up to and including index 1", ListA: []sdk.ExternalVolumeStorageLocation{ {S3StorageLocationParams: &s3StorageLocationA}, {AzureStorageLocationParams: &azureStorageLocationA}, @@ -757,7 +749,7 @@ func Test_LongestCommonPrefix(t *testing.T) { ExpectedOutput: 1, }, { - Name: "Lists with a common prefix - length 4, matching til last element", + Name: "Lists with a common prefix - length 4, matching up to and including index 2", ListA: []sdk.ExternalVolumeStorageLocation{ {S3StorageLocationParams: &s3StorageLocationA}, {AzureStorageLocationParams: &azureStorageLocationA}, @@ -773,7 +765,7 @@ func Test_LongestCommonPrefix(t *testing.T) { ExpectedOutput: 2, }, { - Name: "Lists with a common prefix - length 4, 2 matching elements", + Name: "Lists with a common prefix - length 4, matching up to and including index 1", ListA: []sdk.ExternalVolumeStorageLocation{ {S3StorageLocationParams: &s3StorageLocationA}, {AzureStorageLocationParams: &azureStorageLocationA}, @@ -789,7 +781,7 @@ func Test_LongestCommonPrefix(t *testing.T) { ExpectedOutput: 1, }, { - Name: "Lists with a common prefix - different lengths, matching til last element of shorter list", + Name: "Lists with a common prefix - different lengths, matching up to and including index 1 (last index of shorter list)", ListA: []sdk.ExternalVolumeStorageLocation{ {S3StorageLocationParams: &s3StorageLocationA}, {AzureStorageLocationParams: &azureStorageLocationA}, @@ -802,7 +794,7 @@ func Test_LongestCommonPrefix(t *testing.T) { ExpectedOutput: 1, }, { - Name: "Lists with a common prefix - different lengths, matching til 3rd element of shorter list", + Name: "Lists with a common prefix - different lengths, matching up to and including index 2", ListA: []sdk.ExternalVolumeStorageLocation{ {S3StorageLocationParams: &s3StorageLocationA}, {AzureStorageLocationParams: &azureStorageLocationA},