Skip to content

Commit 637cc83

Browse files
authored
Merge pull request #16 from getindata/feature/align_module_with_provider_changes
feat!: Align module with latest Snowflake provider changes (removals and deprecations)
2 parents bb85824 + 80e5dcc commit 637cc83

File tree

19 files changed

+326
-195
lines changed

19 files changed

+326
-195
lines changed

.github/workflows/pre-commit.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ jobs:
1313
main:
1414
uses: getindata/github-workflows/.github/workflows/tf-pre-commit.yml@v1
1515
with:
16-
# tflint v0.46.0 is the latest version we can use with pre-commit v0.1.20
16+
# tflint v0.52.0 is the latest version we can use with pre-commit v0.1.23
1717
# See .pre-commit-config.yaml for more details.
18-
tflint-version: v0.46.0
18+
tflint-version: v0.52.0

.pre-commit-config.yaml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,26 @@
11
repos:
22
- repo: https://github.com/gruntwork-io/pre-commit
3-
# Stick to v0.1.20 until this bug is fixed: https://github.com/gruntwork-io/pre-commit/issues/102
43
# When updating, also check if tflint version in pre-commit workflow can be updated.
5-
rev: "v0.1.20" # Get the latest from: https://github.com/gruntwork-io/pre-commit/releases
4+
rev: "v0.1.23" # Get the latest from: https://github.com/gruntwork-io/pre-commit/releases
65
hooks:
76
- id: terraform-validate # It should be the first step as it runs terraform init required by tflint
87
- id: terraform-fmt
98
- id: tflint
10-
args:
11-
- --module
12-
- --config=.tflint.hcl
139

1410
- repo: https://github.com/terraform-docs/terraform-docs
15-
rev: "v0.16.0" # Get the latest from: https://github.com/terraform-docs/terraform-docs/releases
11+
rev: "v0.18.0" # Get the latest from: https://github.com/terraform-docs/terraform-docs/releases
1612
hooks:
1713
- id: terraform-docs-go
1814
args: ["."]
1915

2016
- repo: https://github.com/bridgecrewio/checkov.git
21-
rev: "2.5.13" # Get the latest from: https://github.com/bridgecrewio/checkov/releases
17+
rev: "3.2.192" # Get the latest from: https://github.com/bridgecrewio/checkov/releases
2218
hooks:
2319
- id: checkov
2420
args: [--skip-check, "CKV_TF_1"] # Terraform module sources do not use a git url with a commit hash revision
2521

2622
- repo: https://github.com/pre-commit/pre-commit-hooks
27-
rev: "v4.5.0" # Get the latest from: https://github.com/pre-commit/pre-commit-hooks/releases
23+
rev: "v4.6.0" # Get the latest from: https://github.com/pre-commit/pre-commit-hooks/releases
2824
hooks:
2925
- id: check-merge-conflict
3026
args: ["--assume-in-merge"]

.terraform-docs.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ sections:
66
hide: []
77
show: [all]
88

9+
recursive:
10+
enabled: true
11+
path: examples
12+
913
content: |-
1014
{{ .Header }}
1115

.tflint.hcl

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

README.md

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
Terraform module for Snowflake stage management.
1616

1717
* Creates Snowflake stage
18-
* Can create custom Snowflake roles with role-to-role, role-to-user assignments
18+
* Can create custom Snowflake database-roles with role-to-role assignments
1919
* Can create a set of default roles to simplify access management:
2020
* `READONLY` - granted `USAGE` or `READ` privilages
21-
* `READWRITE` - granted `WRITE` privilages
22-
* `ADMIN` - Full access, including schema options like `url` and `credentials`
21+
* `READWRITE` - granted `WRITE` privileges
22+
* `ADMIN` - granted `READ`, `WRITE` privileges (role can be additionally granted with `OWNER` attribute when specified)
2323

2424
## USAGE
2525

@@ -35,7 +35,7 @@ module "snowflake_stage" {
3535
url = "s3://com.example.bucket/prefix"
3636
credentials = "AWS_KEY_ID='${var.example_aws_key_id}' AWS_SECRET_KEY='${var.example_aws_secret_key}'"
3737
38-
create_default_roles = true
38+
create_default_database_roles = true
3939
}
4040
```
4141

@@ -44,6 +44,35 @@ module "snowflake_stage" {
4444
- [Simple](examples/simple) - Basic usage of the module
4545
- [Complete](examples/complete) - Advanced usage of the module
4646

47+
48+
## Breaking changes in v2.x of the module
49+
Due to breaking changes in Snowflake provider and additional code optimizations, **breaking changes** were introduced in `v2.0.0` version of this module.
50+
51+
List of code and variable (API) changes:
52+
- Switched to `snowflake_grant_ownership` resource instead of provider-removed `snowflake_role_ownership_grant`
53+
- Switched to `snowflake_database_role` module to leverage new `database_roles` mechanism
54+
- `default_roles` and `custom_roles` are now combined and managed by single module
55+
- `create_default_roles` variable was renamed to `create_default_database_roles`
56+
- `roles` variable map received following additions:
57+
- `all_privileges` - optional, bool
58+
- `on_all` - optional, bool, defaults to false
59+
- `on_future` - optional, bool, defaults to false
60+
- `with_grant_option` - optional, bool
61+
- `granted_to_database_roles` - optional, string
62+
- `granted_database_roles` - optional, list of strings
63+
64+
- and got following items removed:
65+
- `enabled`
66+
- `comment`
67+
- `role_ownership_grant`
68+
- `granted_roles`
69+
- `granted_to_users`
70+
71+
72+
When upgrading from `v1.x`, expect most of the resources to be recreated - if recreation is impossible, then it is possible to import some existing resources.
73+
74+
For more information, refer to [variables.tf](variables.tf), list of inputs below and Snowflake provider documentation
75+
4776
<!-- BEGIN_TF_DOCS -->
4877

4978

@@ -59,7 +88,7 @@ module "snowflake_stage" {
5988
| <a name="input_comment"></a> [comment](#input\_comment) | Specifies a comment for the stage | `string` | `null` | no |
6089
| <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 |
6190
| <a name="input_copy_options"></a> [copy\_options](#input\_copy\_options) | Specifies the copy options for the stage | `string` | `null` | no |
62-
| <a name="input_create_default_roles"></a> [create\_default\_roles](#input\_create\_default\_roles) | Whether the default roles should be created | `bool` | `false` | no |
91+
| <a name="input_create_default_database_roles"></a> [create\_default\_database\_roles](#input\_create\_default\_database\_roles) | Whether the default database roles should be created | `bool` | `false` | no |
6392
| <a name="input_credentials"></a> [credentials](#input\_credentials) | Specifies the credentials for the stage | `string` | `null` | no |
6493
| <a name="input_database"></a> [database](#input\_database) | The database in which to create the stage | `string` | n/a | yes |
6594
| <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 |
@@ -78,10 +107,11 @@ module "snowflake_stage" {
78107
| <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 |
79108
| <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 |
80109
| <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 |
81-
| <a name="input_roles"></a> [roles](#input\_roles) | Roles created in the database scope | <pre>map(object({<br> enabled = optional(bool, true)<br> comment = optional(string)<br> role_ownership_grant = optional(string)<br> granted_roles = optional(list(string))<br> granted_to_roles = optional(list(string))<br> granted_to_users = optional(list(string))<br> stage_grants = optional(list(string))<br> }))</pre> | `{}` | no |
110+
| <a name="input_roles"></a> [roles](#input\_roles) | Database roles created in the stage scope | <pre>map(object({<br> enabled = optional(bool, true)<br> with_grant_option = optional(bool)<br> granted_to_roles = optional(list(string))<br> granted_to_database_roles = optional(list(string))<br> granted_database_roles = optional(list(string))<br> stage_grants = optional(list(string))<br> all_privileges = optional(bool)<br> on_all = optional(bool, false)<br> schema_name = optional(string)<br> on_future = optional(bool, false)<br> }))</pre> | `{}` | no |
82111
| <a name="input_schema"></a> [schema](#input\_schema) | The schema in which to create the stage | `string` | n/a | yes |
83112
| <a name="input_snowflake_iam_user"></a> [snowflake\_iam\_user](#input\_snowflake\_iam\_user) | Specifies the Snowflake IAM user | `string` | `null` | no |
84113
| <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 |
114+
| <a name="input_stage_ownership_grant"></a> [stage\_ownership\_grant](#input\_stage\_ownership\_grant) | To which role the stage ownership should be granted | `string` | `null` | no |
85115
| <a name="input_storage_integration"></a> [storage\_integration](#input\_storage\_integration) | Specifies the name of the storage integration used to delegate authentication responsibility for external cloud storage to a Snowflake identity and access management (IAM) entity | `string` | `null` | no |
86116
| <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 |
87117
| <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 |
@@ -92,37 +122,36 @@ module "snowflake_stage" {
92122
| Name | Source | Version |
93123
|------|--------|---------|
94124
| <a name="module_roles_deep_merge"></a> [roles\_deep\_merge](#module\_roles\_deep\_merge) | Invicton-Labs/deepmerge/null | 0.1.5 |
95-
| <a name="module_snowflake_custom_role"></a> [snowflake\_custom\_role](#module\_snowflake\_custom\_role) | getindata/role/snowflake | 1.0.3 |
96-
| <a name="module_snowflake_default_role"></a> [snowflake\_default\_role](#module\_snowflake\_default\_role) | getindata/role/snowflake | 1.0.3 |
125+
| <a name="module_snowflake_database_role"></a> [snowflake\_database\_role](#module\_snowflake\_database\_role) | getindata/database-role/snowflake | 1.1.0 |
97126
| <a name="module_stage_label"></a> [stage\_label](#module\_stage\_label) | cloudposse/label/null | 0.25.0 |
98127
| <a name="module_this"></a> [this](#module\_this) | cloudposse/label/null | 0.25.0 |
99128

100129
## Outputs
101130

102131
| Name | Description |
103132
|------|-------------|
133+
| <a name="output_database_roles"></a> [database\_roles](#output\_database\_roles) | This stage access roles |
104134
| <a name="output_name"></a> [name](#output\_name) | Name of the stage |
105-
| <a name="output_roles"></a> [roles](#output\_roles) | This stage access roles |
106135

107136
## Providers
108137

109138
| Name | Version |
110139
|------|---------|
111-
| <a name="provider_snowflake"></a> [snowflake](#provider\_snowflake) | ~> 0.54 |
140+
| <a name="provider_snowflake"></a> [snowflake](#provider\_snowflake) | ~> 0.90 |
112141

113142
## Requirements
114143

115144
| Name | Version |
116145
|------|---------|
117146
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3 |
118-
| <a name="requirement_snowflake"></a> [snowflake](#requirement\_snowflake) | ~> 0.54 |
147+
| <a name="requirement_snowflake"></a> [snowflake](#requirement\_snowflake) | ~> 0.90 |
119148

120149
## Resources
121150

122151
| Name | Type |
123152
|------|------|
153+
| [snowflake_grant_ownership.stage_ownership](https://registry.terraform.io/providers/Snowflake-Labs/snowflake/latest/docs/resources/grant_ownership) | resource |
124154
| [snowflake_stage.this](https://registry.terraform.io/providers/Snowflake-Labs/snowflake/latest/docs/resources/stage) | resource |
125-
| [snowflake_stage_grant.this](https://registry.terraform.io/providers/Snowflake-Labs/snowflake/latest/docs/resources/stage_grant) | resource |
126155
<!-- END_TF_DOCS -->
127156

128157
## CONTRIBUTING

examples/complete/.env.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ SNOWFLAKE_USER=
22
SNOWFLAKE_PASSWORD=
33
SNOWFLAKE_ROLE=
44
SNOWFLAKE_ACCOUNT=
5+
SNOWFLAKE_REGION=

0 commit comments

Comments
 (0)