This file contains hidden or 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
| terraform { | |
| required_providers { | |
| aws = { | |
| source = "hashicorp/aws" | |
| version = "~> 3.0" | |
| } | |
| snowflake = { | |
| source = "chanzuckerberg/snowflake" | |
| version = "~> 0.25" |
This file contains hidden or 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
| export AWS_PROFILE=<aws-profile> | |
| export SNOWFLAKE_USER=<snowflake-user> | |
| export SNOWFLAKE_PASSWORD=<snowflake-password> | |
| export SNOWFLAKE_ACCOUNT=<snowflake-account> | |
| export SNOWFLAKE_REGION=<snowflake-region> |
This file contains hidden or 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
| locals { | |
| sys_admin_role = "SYSADMIN" | |
| snowflake_user = "SANDBOX_USER" | |
| } | |
| resource "snowflake_database" "sandbox" { | |
| provider = snowflake.sys_admin | |
| name = "SANDBOX" | |
| } |
This file contains hidden or 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
| resource "random_id" "aws_resource_id" { | |
| byte_length = 4 | |
| } | |
| resource "aws_s3_bucket" "snowflake_backups_bucket" { | |
| bucket = "snowflake-backups-${lower(random_id.aws_resource_id.id)}" | |
| acl = "private" | |
| versioning { |
This file contains hidden or 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
| resource "snowflake_procedure" "backup_database" { | |
| provider = snowflake.sys_admin | |
| name = "SPROC_BACKUP_DATABASE" | |
| database = snowflake_database.sandbox.name | |
| schema = snowflake_schema.sandbox_tools.name | |
| arguments { | |
| name = "DATABASE" | |
| type = "VARCHAR" | |
| } |
This file contains hidden or 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
| let schemaTablePairResult = getSchemaTablePairResult(DATABASE); | |
| while (schemaTablePairResult.next()) { | |
| let schema = schemaTablePairResult.getColumnValue(1); | |
| let table = schemaTablePairResult.getColumnValue(2); | |
| copyToS3(DATABASE, schema, table); | |
| } | |
| return `Database '${DATABASE}' successfully backed up to S3.`; |
This file contains hidden or 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
| resource "snowflake_database_grant" "usage_sandbox_database" { | |
| provider = snowflake.security_admin | |
| database_name = snowflake_database.sandbox.name | |
| privilege = "USAGE" | |
| roles = [ | |
| snowflake_role.sandbox_rw.name, | |
| snowflake_role.task_admin.name # UPDATE | |
| ] | |
| } |
This file contains hidden or 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
| resource "snowflake_stage" "snowflake_s3_backup" { | |
| provider = snowflake.account_admin | |
| name = "SNOWFLAKE_S3_BACKUP" | |
| url = "s3://${aws_s3_bucket.snowflake_backups_bucket.bucket}/" | |
| database = snowflake_database.sandbox.name | |
| schema = snowflake_schema.sandbox_tools.name | |
| file_format = "TYPE=CSV COMPRESSION=GZIP FIELD_OPTIONALLY_ENCLOSED_BY= '\"' SKIP_HEADER=1" | |
| storage_integration = snowflake_storage_integration.snowflake_s3_backup.name | |
| } |
This file contains hidden or 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
| data "snowflake_current_account" "this" {} | |
| resource "snowflake_schema" "sandbox_tools" { | |
| provider = snowflake.sys_admin | |
| database = snowflake_database.sandbox.name | |
| name = "TOOLS" | |
| } | |
| resource "snowflake_schema_grant" "usage_sandbox_tools" { | |
| provider = snowflake.security_admin |
This file contains hidden or 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
| from typing import Callable | |
| def double(n: int) -> int: | |
| return 2 * n | |
| def is_even(n: int) -> bool: | |
| return n % 2 == 0 | |
| def make_adder(n: int) -> Callable[int, int]: |