Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add flag to create upercase names #21

Merged
merged 10 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ on:

jobs:
main:
uses: getindata/github-workflows/.github/workflows/tf-pre-commit.yml@v1
uses: getindata/github-workflows/.github/workflows/tf-pre-commit.yml@feature/bump_pre-commit_versions
11 changes: 4 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
repos:
- repo: https://github.com/gruntwork-io/pre-commit
rev: "v0.1.24" # Get the latest from: https://github.com/gruntwork-io/pre-commit/releases
rev: "v0.1.25" # Get the latest from: https://github.com/gruntwork-io/pre-commit/releases
hooks:
- id: terraform-validate # It should be the first step as it runs terraform init required by tflint
- id: terraform-fmt
- id: tflint
args:
- --module
#- "--config=__GIT_ROOT__/.tflint.hcl"

- repo: https://github.com/terraform-docs/terraform-docs
rev: "v0.18.0" # Get the latest from: https://github.com/terraform-docs/terraform-docs/releases
rev: "v0.19.0" # Get the latest from: https://github.com/terraform-docs/terraform-docs/releases
hooks:
- id: terraform-docs-go
args: ["."]

- repo: https://github.com/bridgecrewio/checkov.git
rev: "3.2.213" # Get the latest from: https://github.com/bridgecrewio/checkov/releases
rev: "3.2.350" # Get the latest from: https://github.com/bridgecrewio/checkov/releases
hooks:
- id: checkov
args: [--skip-check, "CKV_TF_1"] # Terraform module sources do not use a git url with a commit hash revision

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: "v4.6.0" # Get the latest from: https://github.com/pre-commit/pre-commit-hooks/releases
rev: "v5.0.0" # Get the latest from: https://github.com/pre-commit/pre-commit-hooks/releases
hooks:
- id: check-merge-conflict
args: ["--assume-in-merge"]
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,19 +137,19 @@ List od code and variable (API) changes:

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_account_grants"></a> [account\_grants](#input\_account\_grants) | Grants on a account level | <pre>list(object({<br> all_privileges = optional(bool)<br> with_grant_option = optional(bool, false)<br> privileges = optional(list(string), null)<br> }))</pre> | `[]` | no |
| <a name="input_account_objects_grants"></a> [account\_objects\_grants](#input\_account\_objects\_grants) | Grants on account object level.<br> Account objects list: USER \| RESOURCE MONITOR \| WAREHOUSE \| COMPUTE POOL \| DATABASE \| INTEGRATION \| FAILOVER GROUP \| REPLICATION GROUP \| EXTERNAL VOLUME<br> Object type is used as a key in the map.<br><br> Exmpale usage:<pre>account_object_grants = {<br> "WAREHOUSE" = [<br> {<br> all_privileges = true<br> with_grant_option = true<br> object_name = "TEST_USER"<br> }<br> ]<br> "DATABASE" = [<br> {<br> privileges = ["CREATE SCHEMA", "CREATE DATABASE ROLE"]<br> object_name = "TEST_DATABASE"<br> },<br> {<br> privileges = ["CREATE SCHEMA"]<br> object_name = "OTHER_DATABASE"<br> }<br> ]<br> }</pre>Note: You can find a list of all object types [here](https://registry.terraform.io/providers/Snowflake-Labs/snowflake/latest/docs/resources/grant_privileges_to_account_role#nested-schema-for-on_account_object) | <pre>map(list(object({<br> all_privileges = optional(bool)<br> with_grant_option = optional(bool, false)<br> privileges = optional(list(string), null)<br> object_name = string<br> })))</pre> | `{}` | no |
| <a name="input_account_grants"></a> [account\_grants](#input\_account\_grants) | Grants on a account level | <pre>list(object({<br/> all_privileges = optional(bool)<br/> with_grant_option = optional(bool, false)<br/> privileges = optional(list(string), null)<br/> }))</pre> | `[]` | no |
| <a name="input_account_objects_grants"></a> [account\_objects\_grants](#input\_account\_objects\_grants) | Grants on account object level.<br/> Account objects list: USER \| RESOURCE MONITOR \| WAREHOUSE \| COMPUTE POOL \| DATABASE \| INTEGRATION \| FAILOVER GROUP \| REPLICATION GROUP \| EXTERNAL VOLUME<br/> Object type is used as a key in the map.<br/><br/> Exmpale usage:<pre>account_object_grants = {<br/> "WAREHOUSE" = [<br/> {<br/> all_privileges = true<br/> with_grant_option = true<br/> object_name = "TEST_USER"<br/> }<br/> ]<br/> "DATABASE" = [<br/> {<br/> privileges = ["CREATE SCHEMA", "CREATE DATABASE ROLE"]<br/> object_name = "TEST_DATABASE"<br/> },<br/> {<br/> privileges = ["CREATE SCHEMA"]<br/> object_name = "OTHER_DATABASE"<br/> }<br/> ]<br/> }</pre>Note: You can find a list of all object types [here](https://registry.terraform.io/providers/Snowflake-Labs/snowflake/latest/docs/resources/grant_privileges_to_account_role#nested-schema-for-on_account_object) | <pre>map(list(object({<br/> all_privileges = optional(bool)<br/> with_grant_option = optional(bool, false)<br/> privileges = optional(list(string), null)<br/> object_name = string<br/> })))</pre> | `{}` | no |
| <a name="input_comment"></a> [comment](#input\_comment) | Role description | `string` | `null` | no |
| <a name="input_context_templates"></a> [context\_templates](#input\_context\_templates) | Map of context templates used for naming conventions - this variable supersedes `naming_scheme.properties` and `naming_scheme.delimiter` configuration | `map(string)` | `{}` | no |
| <a name="input_granted_database_roles"></a> [granted\_database\_roles](#input\_granted\_database\_roles) | Database Roles granted to this role | `list(string)` | `[]` | no |
| <a name="input_granted_roles"></a> [granted\_roles](#input\_granted\_roles) | Roles granted to this role | `list(string)` | `[]` | no |
| <a name="input_granted_to_roles"></a> [granted\_to\_roles](#input\_granted\_to\_roles) | Roles which this role is granted to | `list(string)` | `[]` | no |
| <a name="input_granted_to_users"></a> [granted\_to\_users](#input\_granted\_to\_users) | Users which this role is granted to | `list(string)` | `[]` | no |
| <a name="input_name"></a> [name](#input\_name) | Name of the resource | `string` | n/a | yes |
| <a name="input_name_scheme"></a> [name\_scheme](#input\_name\_scheme) | Naming scheme configuration for the resource. This configuration is used to generate names using context provider:<br> - `properties` - list of properties to use when creating the name - is superseded by `var.context_templates`<br> - `delimiter` - delimited used to create the name from `properties` - is superseded by `var.context_templates`<br> - `context_template_name` - name of the context template used to create the name<br> - `replace_chars_regex` - regex to use for replacing characters in property-values created by the provider - any characters that match the regex will be removed from the name<br> - `extra_values` - map of extra label-value pairs, used to create a name | <pre>object({<br> properties = optional(list(string), ["environment", "name"])<br> delimiter = optional(string, "_")<br> context_template_name = optional(string, "snowflake-role")<br> replace_chars_regex = optional(string, "[^a-zA-Z0-9_]")<br> extra_values = optional(map(string))<br> })</pre> | `{}` | no |
| <a name="input_name_scheme"></a> [name\_scheme](#input\_name\_scheme) | Naming scheme configuration for the resource. This configuration is used to generate names using context provider:<br/> - `properties` - list of properties to use when creating the name - is superseded by `var.context_templates`<br/> - `delimiter` - delimited used to create the name from `properties` - is superseded by `var.context_templates`<br/> - `context_template_name` - name of the context template used to create the name<br/> - `replace_chars_regex` - regex to use for replacing characters in property-values created by the provider - any characters that match the regex will be removed from the name<br/> - `extra_values` - map of extra label-value pairs, used to create a name<br/> - `uppercase` - convert name to uppercase | <pre>object({<br/> properties = optional(list(string), ["environment", "name"])<br/> delimiter = optional(string, "_")<br/> context_template_name = optional(string, "snowflake-role")<br/> replace_chars_regex = optional(string, "[^a-zA-Z0-9_]")<br/> extra_values = optional(map(string))<br/> uppercase = optional(bool, true)<br/> })</pre> | `{}` | no |
| <a name="input_role_ownership_grant"></a> [role\_ownership\_grant](#input\_role\_ownership\_grant) | The name of the role to grant ownership | `string` | `null` | no |
| <a name="input_schema_grants"></a> [schema\_grants](#input\_schema\_grants) | Grants on a schema level | <pre>list(object({<br> all_privileges = optional(bool)<br> with_grant_option = optional(bool, false)<br> privileges = optional(list(string), null)<br> all_schemas_in_database = optional(bool, false)<br> future_schemas_in_database = optional(bool, false)<br> database_name = string<br> schema_name = optional(string, null)<br> }))</pre> | `[]` | no |
| <a name="input_schema_objects_grants"></a> [schema\_objects\_grants](#input\_schema\_objects\_grants) | Grants on a schema object level<br><br> Example usage:<pre>schema_objects_grants = {<br> "TABLE" = [<br> {<br> privileges = ["SELECT"]<br> object_name = snowflake_table.table_1.name<br> schema_name = snowflake_schema.this.name<br> },<br> {<br> all_privileges = true<br> object_name = snowflake_table.table_2.name<br> schema_name = snowflake_schema.this.name<br> }<br> ]<br> "ALERT" = [<br> {<br> all_privileges = true<br> on_future = true<br> on_all = true<br> }<br> ]<br> }</pre>Note: If you don't provide a schema\_name, the grants will be created for all objects of that type in the database.<br> You can find a list of all object types [here](https://registry.terraform.io/providers/Snowflake-Labs/snowflake/latest/docs/resources/grant_privileges_to_database_role#object_type) | <pre>map(list(object({<br> all_privileges = optional(bool)<br> with_grant_option = optional(bool)<br> privileges = optional(list(string))<br> object_name = optional(string)<br> on_all = optional(bool, false)<br> schema_name = optional(string)<br> database_name = string<br> on_future = optional(bool, false)<br> })))</pre> | `{}` | no |
| <a name="input_schema_grants"></a> [schema\_grants](#input\_schema\_grants) | Grants on a schema level | <pre>list(object({<br/> all_privileges = optional(bool)<br/> with_grant_option = optional(bool, false)<br/> privileges = optional(list(string), null)<br/> all_schemas_in_database = optional(bool, false)<br/> future_schemas_in_database = optional(bool, false)<br/> database_name = string<br/> schema_name = optional(string, null)<br/> }))</pre> | `[]` | no |
| <a name="input_schema_objects_grants"></a> [schema\_objects\_grants](#input\_schema\_objects\_grants) | Grants on a schema object level<br/><br/> Example usage:<pre>schema_objects_grants = {<br/> "TABLE" = [<br/> {<br/> privileges = ["SELECT"]<br/> object_name = snowflake_table.table_1.name<br/> schema_name = snowflake_schema.this.name<br/> },<br/> {<br/> all_privileges = true<br/> object_name = snowflake_table.table_2.name<br/> schema_name = snowflake_schema.this.name<br/> }<br/> ]<br/> "ALERT" = [<br/> {<br/> all_privileges = true<br/> on_future = true<br/> on_all = true<br/> }<br/> ]<br/> }</pre>Note: If you don't provide a schema\_name, the grants will be created for all objects of that type in the database.<br/> You can find a list of all object types [here](https://registry.terraform.io/providers/Snowflake-Labs/snowflake/latest/docs/resources/grant_privileges_to_database_role#object_type) | <pre>map(list(object({<br/> all_privileges = optional(bool)<br/> with_grant_option = optional(bool)<br/> privileges = optional(list(string))<br/> object_name = optional(string)<br/> on_all = optional(bool, false)<br/> schema_name = optional(string)<br/> database_name = string<br/> on_future = optional(bool, false)<br/> })))</pre> | `{}` | no |

## Modules

Expand All @@ -166,15 +166,15 @@ No modules.
| Name | Version |
|------|---------|
| <a name="provider_context"></a> [context](#provider\_context) | >=0.4.0 |
| <a name="provider_snowflake"></a> [snowflake](#provider\_snowflake) | ~> 0.94 |
| <a name="provider_snowflake"></a> [snowflake](#provider\_snowflake) | >= 0.94 |

## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3 |
| <a name="requirement_context"></a> [context](#requirement\_context) | >=0.4.0 |
| <a name="requirement_snowflake"></a> [snowflake](#requirement\_snowflake) | ~> 0.94 |
| <a name="requirement_snowflake"></a> [snowflake](#requirement\_snowflake) | >= 0.94 |

## Resources

Expand Down
7 changes: 4 additions & 3 deletions examples/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,14 @@ module "snowflake_role_1" {
module "snowflake_role_2" {
source = "../../"

name = "SAMPLE_TEST_2"
name = "sample_test_2"
context_templates = var.context_templates
name_scheme = {
context_template_name = "snowflake-project-role"
extra_values = {
project = "PROJECT"
project = "project"
}
uppercase = false
}

account_grants = [
Expand All @@ -186,7 +187,7 @@ module "snowflake_role_2" {
module "snowflake_role_3" {
source = "../../"

name = "SAMPLE-TEST-3"
name = "sample-test-3"
name_scheme = {
properties = ["name", "schema", "environment"]
delimiter = "_"
Expand Down
2 changes: 1 addition & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ data "context_label" "this" {
}

resource "snowflake_account_role" "this" {
name = data.context_label.this.rendered
name = var.name_scheme.uppercase ? upper(data.context_label.this.rendered) : data.context_label.this.rendered
comment = var.comment
}
moved {
Expand Down
2 changes: 2 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,15 @@ variable "name_scheme" {
- `context_template_name` - name of the context template used to create the name
- `replace_chars_regex` - regex to use for replacing characters in property-values created by the provider - any characters that match the regex will be removed from the name
- `extra_values` - map of extra label-value pairs, used to create a name
- `uppercase` - convert name to uppercase
EOT
type = object({
properties = optional(list(string), ["environment", "name"])
delimiter = optional(string, "_")
context_template_name = optional(string, "snowflake-role")
replace_chars_regex = optional(string, "[^a-zA-Z0-9_]")
extra_values = optional(map(string))
uppercase = optional(bool, true)
})
default = {}
}
Expand Down
2 changes: 1 addition & 1 deletion versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ terraform {
required_providers {
snowflake = {
source = "Snowflake-Labs/snowflake"
version = "~> 0.94"
version = ">= 0.94"
}
context = {
source = "cloudposse/context"
Expand Down
Loading