-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from Snowflake-Labs/sovereign-cloud-support
Add support for sovereign cloud.
- Loading branch information
Showing
6 changed files
with
92 additions
and
26 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
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 |
---|---|---|
@@ -1,30 +1,76 @@ | ||
locals { | ||
storage_provider_map = lookup(local.snowflake_storage_provider_maps, local.aws_partition, null) | ||
snowflake_storage_provider = local.storage_provider_map["snowflake_storage_provider"] | ||
terraform_resource_provider = local.storage_provider_map["terraform_resource_provider"] | ||
|
||
storage_integration_name = "${upper(replace(var.prefix, "-", "_"))}_STORAGE_INTEGRATION" | ||
|
||
pipeline_bucket_ids = [ | ||
for bucket_arn in var.data_bucket_arns : element(split(":::", bucket_arn), 1) | ||
] | ||
storage_provider = length(regexall(".*gov.*", local.aws_region)) > 0 ? "S3GOV" : "S3" | ||
storage_allowed_locations = concat( | ||
["${local.snowflake_storage_provider}://${aws_s3_bucket.geff_bucket.id}/"], | ||
[for bucket_id in local.pipeline_bucket_ids : "${local.snowflake_storage_provider}://${bucket_id}/"] | ||
) | ||
|
||
storage_allowed_locations_snowsql = join(",", [for i in local.storage_allowed_locations : join("", ["'", i, "'"])]) | ||
} | ||
|
||
resource "snowflake_storage_integration" "this" { | ||
count = local.terraform_resource_provider == "snowflake" ? 1 : 0 | ||
provider = snowflake.storage_integration_role | ||
|
||
name = "${upper(replace(var.prefix, "-", "_"))}_STORAGE_INTEGRATION" | ||
name = local.storage_integration_name | ||
type = "EXTERNAL_STAGE" | ||
enabled = true | ||
storage_allowed_locations = concat( | ||
["${local.storage_provider}://${aws_s3_bucket.geff_bucket.id}/"], | ||
[for bucket_id in local.pipeline_bucket_ids : "s3://${bucket_id}/"] | ||
) | ||
storage_provider = local.storage_provider | ||
storage_aws_role_arn = "arn:${var.arn_format}:iam::${local.account_id}:role/${local.s3_reader_role_name}" | ||
|
||
storage_allowed_locations = local.storage_allowed_locations | ||
storage_provider = local.snowflake_storage_provider | ||
storage_aws_role_arn = "arn:${local.aws_partition}:iam::${local.account_id}:role/${local.s3_reader_role_name}" | ||
} | ||
|
||
## Create Snowflake storage integration with SnowSQL Terraform provider if the official Snowflake Terraform provider not yet support the specific sovereign cloud. | ||
resource "snowsql_exec" "snowflake_storage_integration" { | ||
count = local.terraform_resource_provider == "snowsql" ? 1 : 0 | ||
provider = snowsql.storage_integration_role | ||
|
||
create { | ||
statements = <<-EOT | ||
CREATE OR REPLACE STORAGE INTEGRATION "${local.storage_integration_name}" | ||
TYPE=EXTERNAL_STAGE | ||
STORAGE_PROVIDER='${local.snowflake_storage_provider}' | ||
STORAGE_AWS_ROLE_ARN="arn:${local.aws_partition}:iam::${local.account_id}:role/${local.s3_reader_role_name}" | ||
ENABLED=true | ||
STORAGE_ALLOWED_LOCATIONS=(${local.storage_allowed_locations_snowsql}); | ||
EOT | ||
} | ||
|
||
read { | ||
statements = "DESCRIBE STORAGE INTEGRATION ${local.storage_integration_name};" | ||
} | ||
|
||
delete { | ||
statements = "DROP INTEGRATION ${local.storage_integration_name};" | ||
} | ||
} | ||
|
||
locals { | ||
storage_integration_user_arn = local.terraform_resource_provider == "snowflake" ? snowflake_storage_integration.this[0].storage_aws_iam_user_arn : [for map in jsondecode(nonsensitive(snowsql_exec.snowflake_storage_integration[0].read_results)): map if map.property == "STORAGE_AWS_IAM_USER_ARN"][0]["property_value"] | ||
|
||
storage_integration_external_id = local.terraform_resource_provider == "snowflake" ? snowflake_storage_integration.this[0].storage_aws_external_id : [for map in jsondecode(nonsensitive(snowsql_exec.snowflake_storage_integration[0].read_results)): map if map.property == "STORAGE_AWS_EXTERNAL_ID"][0]["property_value"] | ||
} | ||
|
||
resource "snowflake_integration_grant" "this" { | ||
provider = snowflake.storage_integration_role | ||
integration_name = snowflake_storage_integration.this.name | ||
integration_name = local.storage_integration_name | ||
|
||
privilege = "USAGE" | ||
roles = var.snowflake_integration_user_roles | ||
|
||
with_grant_option = false | ||
|
||
depends_on = [ | ||
snowflake_storage_integration.this, | ||
snowsql_exec.snowflake_storage_integration, | ||
] | ||
} |
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