Skip to content

Commit f0d8bfc

Browse files
authored
Merge pull request #1 from getindata/initial_commit
feat: Initial commit
2 parents 1f2f66e + 1dbd099 commit f0d8bfc

File tree

19 files changed

+634
-75
lines changed

19 files changed

+634
-75
lines changed

README.md

Lines changed: 60 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1-
# Terraform Module Template
2-
3-
4-
> **Warning**:
5-
> This is a template document. Remember to **remove** all text in _italics_ and **update** Module name, Repo name and links/badges to the acual name of your GitHub repository/module!!!
1+
# Terraform Snowflake Warehouse
62

73
<!--- Pick Cloud provider Badge -->
84
<!---![Azure](https://img.shields.io/badge/azure-%230072C6.svg?style=for-the-badge&logo=microsoftazure&logoColor=white) -->
95
<!---![Google Cloud](https://img.shields.io/badge/GoogleCloud-%234285F4.svg?style=for-the-badge&logo=google-cloud&logoColor=white) -->
10-
![AWS](https://img.shields.io/badge/AWS-%23FF9900.svg?style=for-the-badge&logo=amazon-aws&logoColor=white)
6+
![Snowflake](https://img.shields.io/badge/-SNOWFLAKE-249edc?style=for-the-badge&logo=snowflake&logoColor=white)
117
![Terraform](https://img.shields.io/badge/terraform-%235835CC.svg?style=for-the-badge&logo=terraform&logoColor=white)
128

139
<!--- Replace repository name -->
14-
![License](https://badgen.net/github/license/getindata/terraform-module-template/)
15-
![Release](https://badgen.net/github/release/getindata/terraform-module-template/)
10+
![License](https://badgen.net/github/license/getindata/terraform-snowflake-warehouse/)
11+
![Release](https://badgen.net/github/release/getindata/terraform-snowflake-warehouse/)
1612

1713
<p align="center">
1814
<img height="150" src="https://getindata.com/img/logo.svg">
@@ -21,21 +17,41 @@
2117

2218
---
2319

24-
_Brief Description of MODULE:_
20+
Terraform module for Snowflake Warehouse management
2521

26-
* _What it does_
27-
* _What techonlogies it uses_
22+
* Creates Snowflake Warehouse
23+
* Can create custom Snowflake Roles with role-to-role, role-to-user assignments
24+
* Can create a set of default, functional roles to simplify access management:
25+
* `ADMIN` - full access
26+
* `MODIFY` - abillity to modify warehouse
27+
* `MONITOR` - abillity to monitor warehouse
28+
* `USAGE` - abillity to use warehouse
2829

2930
## USAGE
3031

31-
_Example usage of the module - terraform code snippet_
32-
3332
```terraform
34-
module "template" {
35-
source = "github.com/getindata/terraform-module-template"
33+
module "terraform_snowflake_warehouse" {
34+
source = "github.com/getindata/terraform-snowflake-warehouse"
35+
context = module.this.context
36+
37+
name = "warehouse"
38+
comment = "My Warehouse"
3639
37-
example_var = "foo"
40+
warehouse_size = "x-small"
41+
42+
auto_resume = true
43+
auto_suspend = 600
44+
initially_suspended = true
45+
46+
create_default_roles = true
47+
48+
roles = {
49+
admin = {
50+
granted_to_roles = ["SYSADMIN"]
51+
}
52+
}
3853
}
54+
3955
```
4056

4157
## NOTES
@@ -44,7 +60,8 @@ _Additional information that should be made public, for ex. how to solve known i
4460

4561
## EXAMPLES
4662

47-
- [Full example](examples/full-example)
63+
* [Simple](examples/simple)
64+
* [Complete](examples/complete)
4865

4966
<!-- BEGIN_TF_DOCS -->
5067

@@ -57,54 +74,73 @@ _Additional information that should be made public, for ex. how to solve known i
5774
|------|-------------|------|---------|:--------:|
5875
| <a name="input_additional_tag_map"></a> [additional\_tag\_map](#input\_additional\_tag\_map) | Additional key-value pairs to add to each map in `tags_as_list_of_maps`. Not added to `tags` or `id`.<br>This is for some rare cases where resources want additional configuration of tags<br>and therefore take a list of maps with tag key, value, and additional configuration. | `map(string)` | `{}` | no |
5976
| <a name="input_attributes"></a> [attributes](#input\_attributes) | ID element. Additional attributes (e.g. `workers` or `cluster`) to add to `id`,<br>in the order they appear in the list. New attributes are appended to the<br>end of the list. The elements of the list are joined by the `delimiter`<br>and treated as a single ID element. | `list(string)` | `[]` | no |
77+
| <a name="input_auto_resume"></a> [auto\_resume](#input\_auto\_resume) | Specifies whether to automatically resume a warehouse when a SQL statement (e.g. query) is submitted to it. | `bool` | `true` | no |
78+
| <a name="input_auto_suspend"></a> [auto\_suspend](#input\_auto\_suspend) | Specifies the number of seconds of inactivity after which a warehouse is automatically suspended. | `number` | `null` | no |
79+
| <a name="input_comment"></a> [comment](#input\_comment) | Warehouse comment/description. | `string` | `null` | no |
6080
| <a name="input_context"></a> [context](#input\_context) | Single object for setting entire context at once.<br>See description of individual variables for details.<br>Leave string and numeric variables as `null` to use default value.<br>Individual variable settings (non-null) override settings in context object,<br>except for attributes, tags, and additional\_tag\_map, which are merged. | `any` | <pre>{<br> "additional_tag_map": {},<br> "attributes": [],<br> "delimiter": null,<br> "descriptor_formats": {},<br> "enabled": true,<br> "environment": null,<br> "id_length_limit": null,<br> "label_key_case": null,<br> "label_order": [],<br> "label_value_case": null,<br> "labels_as_tags": [<br> "unset"<br> ],<br> "name": null,<br> "namespace": null,<br> "regex_replace_chars": null,<br> "stage": null,<br> "tags": {},<br> "tenant": null<br>}</pre> | no |
81+
| <a name="input_create_default_roles"></a> [create\_default\_roles](#input\_create\_default\_roles) | Whether the default roles should be created | `bool` | `false` | no |
6182
| <a name="input_delimiter"></a> [delimiter](#input\_delimiter) | Delimiter to be used between ID elements.<br>Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no |
6283
| <a name="input_descriptor_formats"></a> [descriptor\_formats](#input\_descriptor\_formats) | Describe additional descriptors to be output in the `descriptors` output map.<br>Map of maps. Keys are names of descriptors. Values are maps of the form<br>`{<br> format = string<br> labels = list(string)<br>}`<br>(Type is `any` so the map values can later be enhanced to provide additional options.)<br>`format` is a Terraform format string to be passed to the `format()` function.<br>`labels` is a list of labels, in order, to pass to `format()` function.<br>Label values will be normalized before being passed to `format()` so they will be<br>identical to how they appear in `id`.<br>Default is `{}` (`descriptors` output will be empty). | `any` | `{}` | no |
84+
| <a name="input_enable_query_acceleration"></a> [enable\_query\_acceleration](#input\_enable\_query\_acceleration) | Specifies whether to enable the query acceleration service for queries that rely on this warehouse for compute resources. | `bool` | `true` | no |
6385
| <a name="input_enabled"></a> [enabled](#input\_enabled) | Set to false to prevent the module from creating any resources | `bool` | `null` | no |
6486
| <a name="input_environment"></a> [environment](#input\_environment) | ID element. Usually used for region e.g. 'uw2', 'us-west-2', OR role 'prod', 'staging', 'dev', 'UAT' | `string` | `null` | no |
65-
| <a name="input_example_var"></a> [example\_var](#input\_example\_var) | Example varible passed into the module | `string` | n/a | yes |
6687
| <a name="input_id_length_limit"></a> [id\_length\_limit](#input\_id\_length\_limit) | Limit `id` to this many characters (minimum 6).<br>Set to `0` for unlimited length.<br>Set to `null` for keep the existing setting, which defaults to `0`.<br>Does not affect `id_full`. | `number` | `null` | no |
88+
| <a name="input_initially_suspended"></a> [initially\_suspended](#input\_initially\_suspended) | Specifies whether the warehouse is created initially in the ‘Suspended’ state. | `bool` | `true` | no |
6789
| <a name="input_label_key_case"></a> [label\_key\_case](#input\_label\_key\_case) | Controls the letter case of the `tags` keys (label names) for tags generated by this module.<br>Does not affect keys of tags passed in via the `tags` input.<br>Possible values: `lower`, `title`, `upper`.<br>Default value: `title`. | `string` | `null` | no |
6890
| <a name="input_label_order"></a> [label\_order](#input\_label\_order) | The order in which the labels (ID elements) appear in the `id`.<br>Defaults to ["namespace", "environment", "stage", "name", "attributes"].<br>You can omit any of the 6 labels ("tenant" is the 6th), but at least one must be present. | `list(string)` | `null` | no |
6991
| <a name="input_label_value_case"></a> [label\_value\_case](#input\_label\_value\_case) | Controls the letter case of ID elements (labels) as included in `id`,<br>set as tag values, and output by this module individually.<br>Does not affect values of tags passed in via the `tags` input.<br>Possible values: `lower`, `title`, `upper` and `none` (no transformation).<br>Set this to `title` and set `delimiter` to `""` to yield Pascal Case IDs.<br>Default value: `lower`. | `string` | `null` | no |
7092
| <a name="input_labels_as_tags"></a> [labels\_as\_tags](#input\_labels\_as\_tags) | Set of labels (ID elements) to include as tags in the `tags` output.<br>Default is to include all labels.<br>Tags with empty values will not be included in the `tags` output.<br>Set to `[]` to suppress all generated tags.<br>**Notes:**<br> The value of the `name` tag, if included, will be the `id`, not the `name`.<br> Unlike other `null-label` inputs, the initial setting of `labels_as_tags` cannot be<br> changed in later chained modules. Attempts to change it will be silently ignored. | `set(string)` | <pre>[<br> "default"<br>]</pre> | no |
93+
| <a name="input_max_cluster_count"></a> [max\_cluster\_count](#input\_max\_cluster\_count) | Specifies the maximum number of server clusters for the warehouse. | `number` | `1` | no |
94+
| <a name="input_max_concurrency_level"></a> [max\_concurrency\_level](#input\_max\_concurrency\_level) | Object parameter that specifies the concurrency level for SQL statements (i.e. queries and DML) executed by a warehouse. | `number` | `null` | no |
95+
| <a name="input_min_cluster_count"></a> [min\_cluster\_count](#input\_min\_cluster\_count) | Specifies the minimum number of server clusters for the warehouse (only applies to multi-cluster warehouses). | `number` | `1` | no |
7196
| <a name="input_name"></a> [name](#input\_name) | ID element. Usually the component or solution name, e.g. 'app' or 'jenkins'.<br>This is the only ID element not also included as a `tag`.<br>The "name" tag is set to the full `id` string. There is no tag with the value of the `name` input. | `string` | `null` | no |
7297
| <a name="input_namespace"></a> [namespace](#input\_namespace) | ID element. Usually an abbreviation of your organization name, e.g. 'eg' or 'cp', to help ensure generated IDs are globally unique | `string` | `null` | no |
98+
| <a name="input_query_acceleration_max_scale_factor"></a> [query\_acceleration\_max\_scale\_factor](#input\_query\_acceleration\_max\_scale\_factor) | Specifies the maximum scale factor for leasing compute resources for query acceleration. The scale factor is used as a multiplier based on warehouse size. | `number` | `null` | no |
7399
| <a name="input_regex_replace_chars"></a> [regex\_replace\_chars](#input\_regex\_replace\_chars) | Terraform regular expression (regex) string.<br>Characters matching the regex will be removed from the ID elements.<br>If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits. | `string` | `null` | no |
100+
| <a name="input_resource_monitor"></a> [resource\_monitor](#input\_resource\_monitor) | Specifies the name of a resource monitor that is explicitly assigned to the warehouse. | `string` | `null` | no |
101+
| <a name="input_roles"></a> [roles](#input\_roles) | Roles created on the warehouse level | `any` | `{}` | no |
102+
| <a name="input_scaling_policy"></a> [scaling\_policy](#input\_scaling\_policy) | Specifies the policy for automatically starting and shutting down clusters in a multi-cluster warehouse running in Auto-scale mode. | `string` | `null` | no |
74103
| <a name="input_stage"></a> [stage](#input\_stage) | ID element. Usually used to indicate role, e.g. 'prod', 'staging', 'source', 'build', 'test', 'deploy', 'release' | `string` | `null` | no |
104+
| <a name="input_statement_queued_timeout_in_seconds"></a> [statement\_queued\_timeout\_in\_seconds](#input\_statement\_queued\_timeout\_in\_seconds) | Object parameter that specifies the time, in seconds, a SQL statement (query, DDL, DML, etc.) can be queued on a warehouse before it is canceled by the system. | `number` | `null` | no |
105+
| <a name="input_statement_timeout_in_seconds"></a> [statement\_timeout\_in\_seconds](#input\_statement\_timeout\_in\_seconds) | Specifies the time, in seconds, after which a running SQL statement (query, DDL, DML, etc.) is canceled by the system | `number` | `null` | no |
75106
| <a name="input_tags"></a> [tags](#input\_tags) | Additional tags (e.g. `{'BusinessUnit': 'XYZ'}`).<br>Neither the tag keys nor the tag values will be modified by this module. | `map(string)` | `{}` | no |
76107
| <a name="input_tenant"></a> [tenant](#input\_tenant) | ID element \_(Rarely used, not included by default)\_. A customer identifier, indicating who this instance of a resource is for | `string` | `null` | no |
108+
| <a name="input_warehouse_size"></a> [warehouse\_size](#input\_warehouse\_size) | Specifies the size of the virtual warehouse. | `string` | `"X-Small"` | no |
77109

78110
## Modules
79111

80112
| Name | Source | Version |
81113
|------|--------|---------|
114+
| <a name="module_roles_deep_merge"></a> [roles\_deep\_merge](#module\_roles\_deep\_merge) | Invicton-Labs/deepmerge/null | 0.1.5 |
115+
| <a name="module_snowflake_role"></a> [snowflake\_role](#module\_snowflake\_role) | github.com/getindata/terraform-snowflake-role | v1.0.0 |
82116
| <a name="module_this"></a> [this](#module\_this) | cloudposse/label/null | 0.25.0 |
83117

84118
## Outputs
85119

86120
| Name | Description |
87121
|------|-------------|
88-
| <a name="output_example_output"></a> [example\_output](#output\_example\_output) | Example output of the module |
122+
| <a name="output_roles"></a> [roles](#output\_roles) | Functional roles created for warehouse |
123+
| <a name="output_warehouse"></a> [warehouse](#output\_warehouse) | Details of the warehouse |
89124

90125
## Providers
91126

92127
| Name | Version |
93128
|------|---------|
94-
| <a name="provider_null"></a> [null](#provider\_null) | 3.1.1 |
129+
| <a name="provider_snowflake"></a> [snowflake](#provider\_snowflake) | ~> 0.47 |
95130

96131
## Requirements
97132

98133
| Name | Version |
99134
|------|---------|
100-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.0 |
101-
| <a name="requirement_null"></a> [null](#requirement\_null) | 3.1.1 |
135+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3 |
136+
| <a name="requirement_snowflake"></a> [snowflake](#requirement\_snowflake) | ~> 0.47 |
102137

103138
## Resources
104139

105140
| Name | Type |
106141
|------|------|
107-
| [null_resource.output_input](https://registry.terraform.io/providers/hashicorp/null/3.1.1/docs/resources/resource) | resource |
142+
| [snowflake_warehouse.this](https://registry.terraform.io/providers/Snowflake-Labs/snowflake/latest/docs/resources/warehouse) | resource |
143+
| [snowflake_warehouse_grant.this](https://registry.terraform.io/providers/Snowflake-Labs/snowflake/latest/docs/resources/warehouse_grant) | resource |
108144
<!-- END_TF_DOCS -->
109145

110146
## CONTRIBUTING
@@ -121,7 +157,7 @@ Apache 2 Licensed. See [LICENSE](LICENSE) for full details.
121157

122158
<!--- Replace repository name -->
123159
<a href="https://github.com/getindata/REPO_NAME/graphs/contributors">
124-
<img src="https://contrib.rocks/image?repo=getindata/terraform-module-template" />
160+
<img src="https://contrib.rocks/image?repo=getindata/terraform-snowflake-warehouse" />
125161
</a>
126162

127163
Made with [contrib.rocks](https://contrib.rocks).

examples/complete/main.tf

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
resource "snowflake_role" "this_admin" {
2+
name = "WAREHOUSE_ADMIN"
3+
comment = "Role for Snowflake Administrators"
4+
}
5+
6+
resource "snowflake_role" "this_dev" {
7+
name = "WAREHOUSE_DEV"
8+
comment = "Role for Snowflake Developers"
9+
}
10+
11+
resource "snowflake_resource_monitor" "this" {
12+
name = "warehouse-rm"
13+
credit_quota = 20
14+
15+
notify_triggers = [50, 100]
16+
17+
set_for_account = false
18+
}
19+
20+
module "terraform_snowflake_warehouse" {
21+
source = "../../"
22+
context = module.this.context
23+
24+
descriptor_formats = {
25+
snowflake-role = {
26+
labels = ["attributes", "name"]
27+
format = "%v_%v"
28+
}
29+
snowflake-warehouse = {
30+
labels = ["name"]
31+
format = "%v"
32+
}
33+
}
34+
35+
enabled = true
36+
37+
name = "full_warehouse"
38+
comment = "My Warehouse"
39+
40+
warehouse_size = "x-small"
41+
42+
auto_resume = true
43+
auto_suspend = 600
44+
initially_suspended = true
45+
min_cluster_count = 1
46+
max_cluster_count = 10
47+
scaling_policy = "Economy"
48+
49+
max_concurrency_level = 3
50+
enable_query_acceleration = true
51+
query_acceleration_max_scale_factor = 2
52+
53+
statement_timeout_in_seconds = 300
54+
statement_queued_timeout_in_seconds = 600
55+
56+
resource_monitor = snowflake_resource_monitor.this.name
57+
58+
create_default_roles = true
59+
60+
roles = {
61+
admin = {
62+
granted_to_roles = [snowflake_role.this_admin.name]
63+
}
64+
custom_role = {
65+
privileges = ["USAGE", "MODIFY"]
66+
granted_to_roles = [snowflake_role.this_dev.name]
67+
}
68+
}
69+
}

examples/complete/outputs.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
output "warehouse" {
2+
description = "Details of Snowflake warehouse"
3+
value = module.terraform_snowflake_warehouse
4+
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
provider "null" {
1+
provider "snowflake" {
22
# Configuration options
33
}

examples/complete/versions.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
terraform {
2+
required_version = ">= 1.3"
3+
4+
required_providers {
5+
snowflake = {
6+
source = "Snowflake-Labs/snowflake"
7+
version = "~> 0.47"
8+
}
9+
}
10+
}

examples/full-example/main.tf

Lines changed: 0 additions & 6 deletions
This file was deleted.

examples/full-example/outputs.tf

Lines changed: 0 additions & 4 deletions
This file was deleted.

examples/full-example/versions.tf

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)