generated from getindata/terraform-module-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: initial commit of Snowflake Shared Database module
- Loading branch information
Showing
24 changed files
with
622 additions
and
151 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
SNOWFLAKE_USER= | ||
SNOWFLAKE_ACCOUNT= | ||
SNOWFLAKE_ROLE="ACCOUNTADMIN" | ||
|
||
# Login using RSA key | ||
# SNOWFLAKE_PRIVATE_KEY_PATH= | ||
# SNOWFLAKE_AUTHENTICATOR="JWT" | ||
|
||
# Login using password | ||
# SNOWFLAKE_PASSWORD= |
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,23 @@ | ||
CREATE DATABASE sample_shared_db; | ||
|
||
CREATE SCHEMA sample_shared_db.shared_schema; | ||
|
||
CREATE TABLE sample_shared_db.shared_schema.sample_table ( | ||
ID NUMBER, | ||
VALUE TEXT | ||
); | ||
|
||
INSERT INTO sample_shared_db.shared_schema.sample_table | ||
VALUES | ||
(1, 'TEST VALUE'), | ||
(2, 'ANOTHER TEST VALUE'); | ||
|
||
CREATE SHARE sample_share COMMENT = 'Test Share'; | ||
|
||
GRANT USAGE ON DATABASE sample_shared_db TO SHARE sample_share; | ||
|
||
GRANT USAGE ON SCHEMA sample_shared_db.shared_schema TO SHARE sample_share; | ||
|
||
GRANT SELECT ON ALL TABLES IN SCHEMA sample_shared_db.shared_schema TO SHARE sample_share; | ||
|
||
ALTER SHARE sample_share ADD ACCOUNT="<orgname.accountname>"; |
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,7 +1,14 @@ | ||
descriptor_formats = { | ||
|
||
} | ||
namespace = "gid" | ||
#stage = "example" | ||
#environment = "dev" | ||
|
||
tags = { | ||
Terraform = "True" | ||
descriptor_formats = { | ||
snowflake-role = { | ||
labels = ["attributes", "name"] | ||
format = "%v_%v" | ||
} | ||
snowflake-database = { | ||
labels = ["environment", "stage", "name", "attributes"] | ||
format = "%v_%v_%v_%v" | ||
} | ||
} |
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,9 +1,40 @@ | ||
module "terraform_module_template" { | ||
source = "../../" | ||
context = module.this.context | ||
resource "snowflake_user" "this" { | ||
name = "SAMPLE_USER" | ||
} | ||
|
||
resource "snowflake_account_role" "this" { | ||
name = "SAMPLE_ROLE" | ||
} | ||
|
||
module "snowflake_shared_database" { | ||
source = "../.." | ||
|
||
name = "SHARED_DATABASE" | ||
context = module.this.context | ||
from_share = var.from_share | ||
|
||
descriptor_name = "snowflake-database" | ||
comment = "Sample shared Database" | ||
replace_invalid_characters = true | ||
default_ddl_collation = "UTF8" | ||
log_level = "INFO" | ||
trace_level = "ON_EVENT" | ||
|
||
suspend_task_after_num_failures = 1 | ||
task_auto_retry_attempts = 1 | ||
user_task_managed_initial_warehouse_size = "X-Small" | ||
user_task_minimum_trigger_interval_in_seconds = 300 | ||
user_task_timeout_ms = 200 | ||
quoted_identifiers_ignore_case = true | ||
enable_console_output = true | ||
|
||
create_default_roles = true | ||
|
||
example_var = "This is a example value." | ||
sub_resource = { | ||
example_var = "This is a example value of sub resource." | ||
roles = { | ||
readonly = { | ||
comment = "Read-only role" | ||
granted_roles = [resource.snowflake_account_role.this.name] | ||
granted_to_users = [resource.snowflake_user.this.name] | ||
} | ||
} | ||
} |
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,4 +1,4 @@ | ||
output "example_output" { | ||
description = "Example output of the module" | ||
value = module.terraform_module_template | ||
value = module.snowflake_shared_database | ||
} |
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,3 +1 @@ | ||
provider "null" { | ||
# Configuration options | ||
} | ||
provider "snowflake" {} |
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,4 @@ | ||
variable "from_share" { | ||
description = "A fully qualified path to a share from which the database will be created. A fully qualified path follows the format of `<organization_name>.<account_name>.<share_name>`" | ||
type = string | ||
} |
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,10 +1,9 @@ | ||
terraform { | ||
required_version = ">= 1.3.0" | ||
|
||
required_version = ">= 1.3" | ||
required_providers { | ||
null = { | ||
source = "hashicorp/null" | ||
version = "3.1.1" | ||
snowflake = { | ||
source = "Snowflake-Labs/snowflake" | ||
version = ">= 0.95" | ||
} | ||
} | ||
} |
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,10 @@ | ||
SNOWFLAKE_USER= | ||
SNOWFLAKE_ACCOUNT= | ||
SNOWFLAKE_ROLE="ACCOUNTADMIN" | ||
|
||
# Login using RSA key | ||
# SNOWFLAKE_PRIVATE_KEY_PATH= | ||
# SNOWFLAKE_AUTHENTICATOR="JWT" | ||
|
||
# Login using password | ||
# SNOWFLAKE_PASSWORD= |
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 |
---|---|---|
|
@@ -8,4 +8,4 @@ apply: | |
terraform apply tfplan | ||
|
||
destroy: | ||
terraform destroy | ||
terraform destroy |
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,23 @@ | ||
CREATE DATABASE sample_shared_db; | ||
|
||
CREATE SCHEMA sample_shared_db.shared_schema; | ||
|
||
CREATE TABLE sample_shared_db.shared_schema.sample_table ( | ||
ID NUMBER, | ||
VALUE TEXT | ||
); | ||
|
||
INSERT INTO sample_shared_db.shared_schema.sample_table | ||
VALUES | ||
(1, 'TEST VALUE'), | ||
(2, 'ANOTHER TEST VALUE'); | ||
|
||
CREATE SHARE sample_share COMMENT = 'Test Share'; | ||
|
||
GRANT USAGE ON DATABASE sample_shared_db TO SHARE sample_share; | ||
|
||
GRANT USAGE ON SCHEMA sample_shared_db.shared_schema TO SHARE sample_share; | ||
|
||
GRANT SELECT ON ALL TABLES IN SCHEMA sample_shared_db.shared_schema TO SHARE sample_share; | ||
|
||
ALTER SHARE sample_share ADD ACCOUNT="<orgname.accountname>"; |
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,9 +1,6 @@ | ||
module "terraform_module_template" { | ||
source = "../../" | ||
module "snowflake_shared_database" { | ||
source = "../.." | ||
|
||
example_var = "This is a example value." | ||
|
||
sub_resource = { | ||
example_var = "This is a example value of sub resource." | ||
} | ||
name = "SHARED_DATABASE" | ||
from_share = var.from_share | ||
} |
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,4 +1,4 @@ | ||
output "example_output" { | ||
description = "Example output of the module" | ||
value = module.terraform_module_template | ||
value = module.snowflake_shared_database | ||
} |
Oops, something went wrong.