diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index a646d0b..2692f2a 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -5,8 +5,8 @@ repos:
- id: terraform-validate # It should be the first step as it runs terraform init required by tflint
- id: terraform-fmt
- id: tflint
- args:
- - "--config=__GIT_ROOT__/.tflint.hcl"
+ # args:
+ # - "--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
diff --git a/.tflint.hcl b/.tflint.hcl
deleted file mode 100644
index 3b6ace1..0000000
--- a/.tflint.hcl
+++ /dev/null
@@ -1,3 +0,0 @@
-rule "terraform_standard_module_structure" {
- enabled = false # Fails on context.tf
-}
diff --git a/README.md b/README.md
index 53ea6ce..b83cf16 100644
--- a/README.md
+++ b/README.md
@@ -19,12 +19,12 @@
Terraform module for Snowflake Resource Monitor management
-* Creates Snowflake Resource Monitor
-* Can create custom Snowflake Roles with role-to-role, role-to-user assignments
-* Can create a set of default, functional roles to simplify access management:
- * `ADMIN` - full access
- * `MODIFY` - abillity to modify resource monitor
- * `MONITOR` - abillity to monitor resource monitor
+- Creates Snowflake Resource Monitor
+- Can create custom Snowflake Roles with role-to-role, role-to-user assignments
+- Can create a set of default, functional roles to simplify access management:
+ - `ADMIN` - full access
+ - `MODIFY` - abillity to modify resource monitor
+ - `MONITOR` - abillity to monitor resource monitor
## USAGE
@@ -46,8 +46,43 @@ module "resource_monitors" {
## EXAMPLES
-* [Simple](examples/simple)
-* [Complete](examples/complete)
+- [Simple](examples/simple)
+- [Complete](examples/complete)
+
+## Breaking changes in v4.x of the module
+
+Due to replacement of nulllabel (`context.tf`) with context provider, some **breaking changes** were introduced in `v4.0.0` version of this module.
+
+List of code and variable (API) changes:
+
+- Removed `context.tf` file (a single-file module with additional variables), which implied a removal of all its variables (except `name`):
+ - `descriptor_formats`
+ - `label_value_case`
+ - `label_key_case`
+ - `id_length_limit`
+ - `regex_replace_chars`
+ - `label_order`
+ - `additional_tag_map`
+ - `tags`
+ - `labels_as_tags`
+ - `attributes`
+ - `delimiter`
+ - `stage`
+ - `environment`
+ - `tenant`
+ - `namespace`
+ - `enabled`
+ - `context`
+- Remove support `enabled` flag - that might cause some backward compatibility issues with terraform state (please take into account that proper `move` clauses were added to minimize the impact), but proceed with caution
+- Additional `context` provider configuration
+- New variables were added, to allow naming configuration via `context` provider:
+ - `context_templates`
+ - `name_schema`
+
+Additionally, due to breaking changes introduced in `snowflake` terraform provider `v0.96.0` (`snowflake_resource_monitor` resource):
+
+- Removal of `set_for_account` variable / flag (will be settable on account resource)
+- Removal of `warehouses` variable (will be settable on warehouse resource)
@@ -58,83 +93,64 @@ module "resource_monitors" {
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
-| [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`.
This is for some rare cases where resources want additional configuration of tags
and therefore take a list of maps with tag key, value, and additional configuration. | `map(string)` | `{}` | no |
-| [attributes](#input\_attributes) | ID element. Additional attributes (e.g. `workers` or `cluster`) to add to `id`,
in the order they appear in the list. New attributes are appended to the
end of the list. The elements of the list are joined by the `delimiter`
and treated as a single ID element. | `list(string)` | `[]` | no |
-| [context](#input\_context) | Single object for setting entire context at once.
See description of individual variables for details.
Leave string and numeric variables as `null` to use default value.
Individual variable settings (non-null) override settings in context object,
except for attributes, tags, and additional\_tag\_map, which are merged. | `any` |
{
"additional_tag_map": {},
"attributes": [],
"delimiter": null,
"descriptor_formats": {},
"enabled": true,
"environment": null,
"id_length_limit": null,
"label_key_case": null,
"label_order": [],
"label_value_case": null,
"labels_as_tags": [
"unset"
],
"name": null,
"namespace": null,
"regex_replace_chars": null,
"stage": null,
"tags": {},
"tenant": null
}
| no |
+| [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 |
| [create\_default\_roles](#input\_create\_default\_roles) | Whether the default roles should be created | `bool` | `false` | no |
| [credit\_quota](#input\_credit\_quota) | The number of credits allocated monthly to the resource monitor. | `number` | `null` | no |
-| [delimiter](#input\_delimiter) | Delimiter to be used between ID elements.
Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no |
-| [descriptor\_formats](#input\_descriptor\_formats) | Describe additional descriptors to be output in the `descriptors` output map.
Map of maps. Keys are names of descriptors. Values are maps of the form
`{
format = string
labels = list(string)
}`
(Type is `any` so the map values can later be enhanced to provide additional options.)
`format` is a Terraform format string to be passed to the `format()` function.
`labels` is a list of labels, in order, to pass to `format()` function.
Label values will be normalized before being passed to `format()` so they will be
identical to how they appear in `id`.
Default is `{}` (`descriptors` output will be empty). | `any` | `{}` | no |
-| [descriptor\_name](#input\_descriptor\_name) | Name of the descriptor used to form a resource name | `string` | `"snowflake-resource-monitor"` | no |
-| [enabled](#input\_enabled) | Set to false to prevent the module from creating any resources | `bool` | `null` | no |
| [end\_timestamp](#input\_end\_timestamp) | The date and time when the resource monitor suspends the assigned warehouses. | `string` | `null` | no |
-| [environment](#input\_environment) | ID element. Usually used for region e.g. 'uw2', 'us-west-2', OR role 'prod', 'staging', 'dev', 'UAT' | `string` | `null` | no |
| [frequency](#input\_frequency) | The frequency interval at which the credit usage resets to 0. If you set a frequency for a resource monitor, you must also set START\_TIMESTAMP. | `string` | `null` | no |
-| [id\_length\_limit](#input\_id\_length\_limit) | Limit `id` to this many characters (minimum 6).
Set to `0` for unlimited length.
Set to `null` for keep the existing setting, which defaults to `0`.
Does not affect `id_full`. | `number` | `null` | no |
-| [label\_key\_case](#input\_label\_key\_case) | Controls the letter case of the `tags` keys (label names) for tags generated by this module.
Does not affect keys of tags passed in via the `tags` input.
Possible values: `lower`, `title`, `upper`.
Default value: `title`. | `string` | `null` | no |
-| [label\_order](#input\_label\_order) | The order in which the labels (ID elements) appear in the `id`.
Defaults to ["namespace", "environment", "stage", "name", "attributes"].
You can omit any of the 6 labels ("tenant" is the 6th), but at least one must be present. | `list(string)` | `null` | no |
-| [label\_value\_case](#input\_label\_value\_case) | Controls the letter case of ID elements (labels) as included in `id`,
set as tag values, and output by this module individually.
Does not affect values of tags passed in via the `tags` input.
Possible values: `lower`, `title`, `upper` and `none` (no transformation).
Set this to `title` and set `delimiter` to `""` to yield Pascal Case IDs.
Default value: `lower`. | `string` | `null` | no |
-| [labels\_as\_tags](#input\_labels\_as\_tags) | Set of labels (ID elements) to include as tags in the `tags` output.
Default is to include all labels.
Tags with empty values will not be included in the `tags` output.
Set to `[]` to suppress all generated tags.
**Notes:**
The value of the `name` tag, if included, will be the `id`, not the `name`.
Unlike other `null-label` inputs, the initial setting of `labels_as_tags` cannot be
changed in later chained modules. Attempts to change it will be silently ignored. | `set(string)` | [
"default"
]
| no |
-| [name](#input\_name) | ID element. Usually the component or solution name, e.g. 'app' or 'jenkins'.
This is the only ID element not also included as a `tag`.
The "name" tag is set to the full `id` string. There is no tag with the value of the `name` input. | `string` | `null` | no |
-| [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 |
+| [name](#input\_name) | Name of the resource | `string` | n/a | yes |
+| [name\_scheme](#input\_name\_scheme) | Naming scheme configuration for the resource. This configuration is used to generate names using context provider:
- `properties` - list of properties to use when creating the name - is superseded by `var.context_templates`
- `delimiter` - delimited used to create the name from `properties` - is superseded by `var.context_templates`
- `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 | object({
properties = optional(list(string), ["environment", "name"])
delimiter = optional(string, "_")
context_template_name = optional(string, "snowflake-resource-monitor")
replace_chars_regex = optional(string, "[^a-zA-Z0-9_]")
extra_values = optional(map(string))
})
| `{}` | no |
| [notify\_triggers](#input\_notify\_triggers) | A list of percentage thresholds at which to send an alert to subscribed users. | `list(number)` | `null` | no |
| [notify\_users](#input\_notify\_users) | Specifies the list of users to receive email notifications on resource monitors. | `list(string)` | `null` | no |
-| [regex\_replace\_chars](#input\_regex\_replace\_chars) | Terraform regular expression (regex) string.
Characters matching the regex will be removed from the ID elements.
If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits. | `string` | `null` | no |
-| [roles](#input\_roles) | Roles created on the Resource Monitor level | map(object({
enabled = optional(bool, true)
descriptor_name = optional(string, "snowflake-role")
comment = optional(string)
role_ownership_grant = optional(string)
granted_roles = optional(list(string))
granted_to_roles = optional(list(string))
granted_to_users = optional(list(string))
resource_monitor_grants = optional(object({
all_privileges = optional(bool)
with_grant_option = optional(bool, false)
privileges = optional(list(string))
}))
}))
| `{}` | no |
-| [set\_for\_account](#input\_set\_for\_account) | Specifies whether the resource monitor should be applied globally to your Snowflake account. | `bool` | `false` | no |
-| [stage](#input\_stage) | ID element. Usually used to indicate role, e.g. 'prod', 'staging', 'source', 'build', 'test', 'deploy', 'release' | `string` | `null` | no |
+| [roles](#input\_roles) | Roles created on the Resource Monitor level | map(object({
name_scheme = optional(object({
properties = optional(list(string))
delimiter = optional(string)
context_template_name = optional(string)
replace_chars_regex = optional(string)
extra_labels = optional(map(string))
}))
comment = optional(string)
role_ownership_grant = optional(string)
granted_roles = optional(list(string))
granted_to_roles = optional(list(string))
granted_to_users = optional(list(string))
resource_monitor_grants = optional(object({
all_privileges = optional(bool)
with_grant_option = optional(bool, false)
privileges = optional(list(string))
}))
}))
| `{}` | no |
| [start\_timestamp](#input\_start\_timestamp) | The date and time when the resource monitor starts monitoring credit usage for the assigned warehouses. | `string` | `null` | no |
| [suspend\_immediate\_trigger](#input\_suspend\_immediate\_trigger) | The number that represents the percentage threshold at which to immediately suspend all warehouses. | `number` | `null` | no |
| [suspend\_trigger](#input\_suspend\_trigger) | The number that represents the percentage threshold at which to suspend all warehouses. | `number` | `null` | no |
-| [tags](#input\_tags) | Additional tags (e.g. `{'BusinessUnit': 'XYZ'}`).
Neither the tag keys nor the tag values will be modified by this module. | `map(string)` | `{}` | no |
-| [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 |
-| [warehouses](#input\_warehouses) | A list of warehouse names to apply the resource monitor to. | `list(string)` | `null` | no |
## Modules
| Name | Source | Version |
|------|--------|---------|
-| [monitor\_label](#module\_monitor\_label) | cloudposse/label/null | 0.25.0 |
| [roles\_deep\_merge](#module\_roles\_deep\_merge) | Invicton-Labs/deepmerge/null | 0.1.5 |
-| [snowflake\_custom\_role](#module\_snowflake\_custom\_role) | getindata/role/snowflake | 2.1.0 |
-| [snowflake\_default\_role](#module\_snowflake\_default\_role) | getindata/role/snowflake | 2.1.0 |
-| [this](#module\_this) | cloudposse/label/null | 0.25.0 |
+| [snowflake\_custom\_role](#module\_snowflake\_custom\_role) | getindata/role/snowflake | 3.0.1 |
+| [snowflake\_default\_role](#module\_snowflake\_default\_role) | getindata/role/snowflake | 3.0.1 |
## Outputs
| Name | Description |
|------|-------------|
-| [credit\_quota](#output\_credit\_quota) | he number of credits allocated monthly to the resource monitor |
+| [credit\_quota](#output\_credit\_quota) | The number of credits allocated monthly to the resource monitor |
| [end\_timestamp](#output\_end\_timestamp) | The date and time when the resource monitor suspends the assigned warehouses |
| [frequency](#output\_frequency) | The frequency interval at which the credit usage resets to 0 |
| [name](#output\_name) | Name of resource monitor |
| [notify\_triggers](#output\_notify\_triggers) | A list of percentage thresholds at which to send an alert to subscribed users |
| [notify\_users](#output\_notify\_users) | A list of users to receive email notifications on resource monitors |
| [roles](#output\_roles) | Access roles created for resource monitor |
-| [set\_for\_account](#output\_set\_for\_account) | Whether the resource monitor should be applied globally to your Snowflake account |
| [start\_timestamp](#output\_start\_timestamp) | The date and time when the resource monitor starts monitoring credit usage |
| [suspend\_immediate\_triggers](#output\_suspend\_immediate\_triggers) | A list of percentage thresholds at which to immediately suspend all warehouses |
| [suspend\_triggers](#output\_suspend\_triggers) | A list of percentage thresholds at which to suspend all warehouses |
-| [warehouses](#output\_warehouses) | A list of warehouse names to apply the resource monitor to |
## Providers
| Name | Version |
|------|---------|
-| [snowflake](#provider\_snowflake) | ~> 0.94 |
+| [context](#provider\_context) | >=0.4.0 |
+| [snowflake](#provider\_snowflake) | >= 0.96 |
## Requirements
| Name | Version |
|------|---------|
| [terraform](#requirement\_terraform) | >= 1.3 |
-| [snowflake](#requirement\_snowflake) | ~> 0.94 |
+| [context](#requirement\_context) | >=0.4.0 |
+| [snowflake](#requirement\_snowflake) | >= 0.96 |
## Resources
| Name | Type |
|------|------|
| [snowflake_resource_monitor.this](https://registry.terraform.io/providers/Snowflake-Labs/snowflake/latest/docs/resources/resource_monitor) | resource |
+| [context_label.this](https://registry.terraform.io/providers/cloudposse/context/latest/docs/data-sources/label) | data source |
## CONTRIBUTING
diff --git a/context.tf b/context.tf
deleted file mode 100644
index 5e0ef88..0000000
--- a/context.tf
+++ /dev/null
@@ -1,279 +0,0 @@
-#
-# ONLY EDIT THIS FILE IN github.com/cloudposse/terraform-null-label
-# All other instances of this file should be a copy of that one
-#
-#
-# Copy this file from https://github.com/cloudposse/terraform-null-label/blob/master/exports/context.tf
-# and then place it in your Terraform module to automatically get
-# Cloud Posse's standard configuration inputs suitable for passing
-# to Cloud Posse modules.
-#
-# curl -sL https://raw.githubusercontent.com/cloudposse/terraform-null-label/master/exports/context.tf -o context.tf
-#
-# Modules should access the whole context as `module.this.context`
-# to get the input variables with nulls for defaults,
-# for example `context = module.this.context`,
-# and access individual variables as `module.this.`,
-# with final values filled in.
-#
-# For example, when using defaults, `module.this.context.delimiter`
-# will be null, and `module.this.delimiter` will be `-` (hyphen).
-#
-
-module "this" {
- source = "cloudposse/label/null"
- version = "0.25.0" # requires Terraform >= 0.13.0
-
- enabled = var.enabled
- namespace = var.namespace
- tenant = var.tenant
- environment = var.environment
- stage = var.stage
- name = var.name
- delimiter = var.delimiter
- attributes = var.attributes
- tags = var.tags
- additional_tag_map = var.additional_tag_map
- label_order = var.label_order
- regex_replace_chars = var.regex_replace_chars
- id_length_limit = var.id_length_limit
- label_key_case = var.label_key_case
- label_value_case = var.label_value_case
- descriptor_formats = var.descriptor_formats
- labels_as_tags = var.labels_as_tags
-
- context = var.context
-}
-
-# Copy contents of cloudposse/terraform-null-label/variables.tf here
-
-variable "context" {
- type = any
- default = {
- enabled = true
- namespace = null
- tenant = null
- environment = null
- stage = null
- name = null
- delimiter = null
- attributes = []
- tags = {}
- additional_tag_map = {}
- regex_replace_chars = null
- label_order = []
- id_length_limit = null
- label_key_case = null
- label_value_case = null
- descriptor_formats = {}
- # Note: we have to use [] instead of null for unset lists due to
- # https://github.com/hashicorp/terraform/issues/28137
- # which was not fixed until Terraform 1.0.0,
- # but we want the default to be all the labels in `label_order`
- # and we want users to be able to prevent all tag generation
- # by setting `labels_as_tags` to `[]`, so we need
- # a different sentinel to indicate "default"
- labels_as_tags = ["unset"]
- }
- description = <<-EOT
- Single object for setting entire context at once.
- See description of individual variables for details.
- Leave string and numeric variables as `null` to use default value.
- Individual variable settings (non-null) override settings in context object,
- except for attributes, tags, and additional_tag_map, which are merged.
- EOT
-
- validation {
- condition = lookup(var.context, "label_key_case", null) == null ? true : contains(["lower", "title", "upper"], var.context["label_key_case"])
- error_message = "Allowed values: `lower`, `title`, `upper`."
- }
-
- validation {
- condition = lookup(var.context, "label_value_case", null) == null ? true : contains(["lower", "title", "upper", "none"], var.context["label_value_case"])
- error_message = "Allowed values: `lower`, `title`, `upper`, `none`."
- }
-}
-
-variable "enabled" {
- type = bool
- default = null
- description = "Set to false to prevent the module from creating any resources"
-}
-
-variable "namespace" {
- type = string
- default = null
- description = "ID element. Usually an abbreviation of your organization name, e.g. 'eg' or 'cp', to help ensure generated IDs are globally unique"
-}
-
-variable "tenant" {
- type = string
- default = null
- description = "ID element _(Rarely used, not included by default)_. A customer identifier, indicating who this instance of a resource is for"
-}
-
-variable "environment" {
- type = string
- default = null
- description = "ID element. Usually used for region e.g. 'uw2', 'us-west-2', OR role 'prod', 'staging', 'dev', 'UAT'"
-}
-
-variable "stage" {
- type = string
- default = null
- description = "ID element. Usually used to indicate role, e.g. 'prod', 'staging', 'source', 'build', 'test', 'deploy', 'release'"
-}
-
-variable "name" {
- type = string
- default = null
- description = <<-EOT
- ID element. Usually the component or solution name, e.g. 'app' or 'jenkins'.
- This is the only ID element not also included as a `tag`.
- The "name" tag is set to the full `id` string. There is no tag with the value of the `name` input.
- EOT
-}
-
-variable "delimiter" {
- type = string
- default = null
- description = <<-EOT
- Delimiter to be used between ID elements.
- Defaults to `-` (hyphen). Set to `""` to use no delimiter at all.
- EOT
-}
-
-variable "attributes" {
- type = list(string)
- default = []
- description = <<-EOT
- ID element. Additional attributes (e.g. `workers` or `cluster`) to add to `id`,
- in the order they appear in the list. New attributes are appended to the
- end of the list. The elements of the list are joined by the `delimiter`
- and treated as a single ID element.
- EOT
-}
-
-variable "labels_as_tags" {
- type = set(string)
- default = ["default"]
- description = <<-EOT
- Set of labels (ID elements) to include as tags in the `tags` output.
- Default is to include all labels.
- Tags with empty values will not be included in the `tags` output.
- Set to `[]` to suppress all generated tags.
- **Notes:**
- The value of the `name` tag, if included, will be the `id`, not the `name`.
- Unlike other `null-label` inputs, the initial setting of `labels_as_tags` cannot be
- changed in later chained modules. Attempts to change it will be silently ignored.
- EOT
-}
-
-variable "tags" {
- type = map(string)
- default = {}
- description = <<-EOT
- Additional tags (e.g. `{'BusinessUnit': 'XYZ'}`).
- Neither the tag keys nor the tag values will be modified by this module.
- EOT
-}
-
-variable "additional_tag_map" {
- type = map(string)
- default = {}
- description = <<-EOT
- Additional key-value pairs to add to each map in `tags_as_list_of_maps`. Not added to `tags` or `id`.
- This is for some rare cases where resources want additional configuration of tags
- and therefore take a list of maps with tag key, value, and additional configuration.
- EOT
-}
-
-variable "label_order" {
- type = list(string)
- default = null
- description = <<-EOT
- The order in which the labels (ID elements) appear in the `id`.
- Defaults to ["namespace", "environment", "stage", "name", "attributes"].
- You can omit any of the 6 labels ("tenant" is the 6th), but at least one must be present.
- EOT
-}
-
-variable "regex_replace_chars" {
- type = string
- default = null
- description = <<-EOT
- Terraform regular expression (regex) string.
- Characters matching the regex will be removed from the ID elements.
- If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits.
- EOT
-}
-
-variable "id_length_limit" {
- type = number
- default = null
- description = <<-EOT
- Limit `id` to this many characters (minimum 6).
- Set to `0` for unlimited length.
- Set to `null` for keep the existing setting, which defaults to `0`.
- Does not affect `id_full`.
- EOT
- validation {
- condition = var.id_length_limit == null ? true : var.id_length_limit >= 6 || var.id_length_limit == 0
- error_message = "The id_length_limit must be >= 6 if supplied (not null), or 0 for unlimited length."
- }
-}
-
-variable "label_key_case" {
- type = string
- default = null
- description = <<-EOT
- Controls the letter case of the `tags` keys (label names) for tags generated by this module.
- Does not affect keys of tags passed in via the `tags` input.
- Possible values: `lower`, `title`, `upper`.
- Default value: `title`.
- EOT
-
- validation {
- condition = var.label_key_case == null ? true : contains(["lower", "title", "upper"], var.label_key_case)
- error_message = "Allowed values: `lower`, `title`, `upper`."
- }
-}
-
-variable "label_value_case" {
- type = string
- default = null
- description = <<-EOT
- Controls the letter case of ID elements (labels) as included in `id`,
- set as tag values, and output by this module individually.
- Does not affect values of tags passed in via the `tags` input.
- Possible values: `lower`, `title`, `upper` and `none` (no transformation).
- Set this to `title` and set `delimiter` to `""` to yield Pascal Case IDs.
- Default value: `lower`.
- EOT
-
- validation {
- condition = var.label_value_case == null ? true : contains(["lower", "title", "upper", "none"], var.label_value_case)
- error_message = "Allowed values: `lower`, `title`, `upper`, `none`."
- }
-}
-
-variable "descriptor_formats" {
- type = any
- default = {}
- description = <<-EOT
- Describe additional descriptors to be output in the `descriptors` output map.
- Map of maps. Keys are names of descriptors. Values are maps of the form
- `{
- format = string
- labels = list(string)
- }`
- (Type is `any` so the map values can later be enhanced to provide additional options.)
- `format` is a Terraform format string to be passed to the `format()` function.
- `labels` is a list of labels, in order, to pass to `format()` function.
- Label values will be normalized before being passed to `format()` so they will be
- identical to how they appear in `id`.
- Default is `{}` (`descriptors` output will be empty).
- EOT
-}
-
-#### End of copy of cloudposse/terraform-null-label/variables.tf
diff --git a/examples/complete/Makefile b/examples/complete/Makefile
index 9d9205a..2699785 100644
--- a/examples/complete/Makefile
+++ b/examples/complete/Makefile
@@ -2,7 +2,7 @@ init:
terraform init
plan:
- terraform plan -out tfplan
+ terraform plan -var-file=fixtures.tfvars -out tfplan
apply:
terraform apply tfplan
diff --git a/examples/complete/README.md b/examples/complete/README.md
index e516607..20f48c5 100644
--- a/examples/complete/README.md
+++ b/examples/complete/README.md
@@ -3,14 +3,15 @@
This example creates:
-* Resource monitor for warehouse, that will ill notify account
+* Resource monitor, that will will notify account
administrators and specified users when 50%, 80% of credit
quota is reached, will also suspend all warehouses assigned
to this monitor.
-* Resource monitor for account, that will notify account
+* Resource monitor, that will notify account
administrators when 50%, 80%,90% of credit quota is reached,
will also suspend immediately (all running queries will be cancelled)
all warehouses in the account when 100% quota is reached.
+* Resource monitor, simmilar to the abve, with different name scheme
@@ -18,41 +19,23 @@ This example creates:
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
-| [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`.
This is for some rare cases where resources want additional configuration of tags
and therefore take a list of maps with tag key, value, and additional configuration. | `map(string)` | `{}` | no |
-| [attributes](#input\_attributes) | ID element. Additional attributes (e.g. `workers` or `cluster`) to add to `id`,
in the order they appear in the list. New attributes are appended to the
end of the list. The elements of the list are joined by the `delimiter`
and treated as a single ID element. | `list(string)` | `[]` | no |
-| [context](#input\_context) | Single object for setting entire context at once.
See description of individual variables for details.
Leave string and numeric variables as `null` to use default value.
Individual variable settings (non-null) override settings in context object,
except for attributes, tags, and additional\_tag\_map, which are merged. | `any` | {
"additional_tag_map": {},
"attributes": [],
"delimiter": null,
"descriptor_formats": {},
"enabled": true,
"environment": null,
"id_length_limit": null,
"label_key_case": null,
"label_order": [],
"label_value_case": null,
"labels_as_tags": [
"unset"
],
"name": null,
"namespace": null,
"regex_replace_chars": null,
"stage": null,
"tags": {},
"tenant": null
}
| no |
-| [delimiter](#input\_delimiter) | Delimiter to be used between ID elements.
Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no |
-| [descriptor\_formats](#input\_descriptor\_formats) | Describe additional descriptors to be output in the `descriptors` output map.
Map of maps. Keys are names of descriptors. Values are maps of the form
`{
format = string
labels = list(string)
}`
(Type is `any` so the map values can later be enhanced to provide additional options.)
`format` is a Terraform format string to be passed to the `format()` function.
`labels` is a list of labels, in order, to pass to `format()` function.
Label values will be normalized before being passed to `format()` so they will be
identical to how they appear in `id`.
Default is `{}` (`descriptors` output will be empty). | `any` | `{}` | no |
-| [enabled](#input\_enabled) | Set to false to prevent the module from creating any resources | `bool` | `null` | no |
-| [environment](#input\_environment) | ID element. Usually used for region e.g. 'uw2', 'us-west-2', OR role 'prod', 'staging', 'dev', 'UAT' | `string` | `null` | no |
-| [id\_length\_limit](#input\_id\_length\_limit) | Limit `id` to this many characters (minimum 6).
Set to `0` for unlimited length.
Set to `null` for keep the existing setting, which defaults to `0`.
Does not affect `id_full`. | `number` | `null` | no |
-| [label\_key\_case](#input\_label\_key\_case) | Controls the letter case of the `tags` keys (label names) for tags generated by this module.
Does not affect keys of tags passed in via the `tags` input.
Possible values: `lower`, `title`, `upper`.
Default value: `title`. | `string` | `null` | no |
-| [label\_order](#input\_label\_order) | The order in which the labels (ID elements) appear in the `id`.
Defaults to ["namespace", "environment", "stage", "name", "attributes"].
You can omit any of the 6 labels ("tenant" is the 6th), but at least one must be present. | `list(string)` | `null` | no |
-| [label\_value\_case](#input\_label\_value\_case) | Controls the letter case of ID elements (labels) as included in `id`,
set as tag values, and output by this module individually.
Does not affect values of tags passed in via the `tags` input.
Possible values: `lower`, `title`, `upper` and `none` (no transformation).
Set this to `title` and set `delimiter` to `""` to yield Pascal Case IDs.
Default value: `lower`. | `string` | `null` | no |
-| [labels\_as\_tags](#input\_labels\_as\_tags) | Set of labels (ID elements) to include as tags in the `tags` output.
Default is to include all labels.
Tags with empty values will not be included in the `tags` output.
Set to `[]` to suppress all generated tags.
**Notes:**
The value of the `name` tag, if included, will be the `id`, not the `name`.
Unlike other `null-label` inputs, the initial setting of `labels_as_tags` cannot be
changed in later chained modules. Attempts to change it will be silently ignored. | `set(string)` | [
"default"
]
| no |
-| [name](#input\_name) | ID element. Usually the component or solution name, e.g. 'app' or 'jenkins'.
This is the only ID element not also included as a `tag`.
The "name" tag is set to the full `id` string. There is no tag with the value of the `name` input. | `string` | `null` | no |
-| [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 |
-| [regex\_replace\_chars](#input\_regex\_replace\_chars) | Terraform regular expression (regex) string.
Characters matching the regex will be removed from the ID elements.
If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits. | `string` | `null` | no |
-| [stage](#input\_stage) | ID element. Usually used to indicate role, e.g. 'prod', 'staging', 'source', 'build', 'test', 'deploy', 'release' | `string` | `null` | no |
-| [tags](#input\_tags) | Additional tags (e.g. `{'BusinessUnit': 'XYZ'}`).
Neither the tag keys nor the tag values will be modified by this module. | `map(string)` | `{}` | no |
-| [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 |
+| [context\_templates](#input\_context\_templates) | A map of context templates to use for generating user names | `map(string)` | n/a | yes |
## Modules
| Name | Source | Version |
|------|--------|---------|
-| [account\_resource\_monitor](#module\_account\_resource\_monitor) | ../../ | n/a |
-| [this](#module\_this) | cloudposse/label/null | 0.25.0 |
-| [warehouse\_dbt](#module\_warehouse\_dbt) | getindata/warehouse/snowflake | 2.2.0 |
-| [warehouse\_resource\_monitor](#module\_warehouse\_resource\_monitor) | ../../ | n/a |
-| [warehouse\_users](#module\_warehouse\_users) | getindata/warehouse/snowflake | 2.2.0 |
+| [resource\_monitor\_1](#module\_resource\_monitor\_1) | ../../ | n/a |
+| [resource\_monitor\_2](#module\_resource\_monitor\_2) | ../../ | n/a |
+| [resource\_monitor\_3](#module\_resource\_monitor\_3) | ../../ | n/a |
## Outputs
| Name | Description |
|------|-------------|
-| [account\_resource\_monitor](#output\_account\_resource\_monitor) | Details of account resource monitor |
-| [warehouse\_resource\_monitor](#output\_warehouse\_resource\_monitor) | Details of warehouse resource monitor |
+| [resource\_monitor\_1](#output\_resource\_monitor\_1) | Details of resource monitor |
+| [resource\_monitor\_2](#output\_resource\_monitor\_2) | Details of resource monitor |
+| [resource\_monitor\_3](#output\_resource\_monitor\_3) | Details of resource monitor |
## Providers
@@ -64,7 +47,8 @@ This example creates:
| Name | Version |
|------|---------|
-| [terraform](#requirement\_terraform) | >= 1.3 |
+| [terraform](#requirement\_terraform) | >= 1.5 |
+| [context](#requirement\_context) | >=0.4.0 |
| [snowflake](#requirement\_snowflake) | ~> 0.54 |
## Resources
diff --git a/examples/complete/context.tf b/examples/complete/context.tf
deleted file mode 100644
index 5e0ef88..0000000
--- a/examples/complete/context.tf
+++ /dev/null
@@ -1,279 +0,0 @@
-#
-# ONLY EDIT THIS FILE IN github.com/cloudposse/terraform-null-label
-# All other instances of this file should be a copy of that one
-#
-#
-# Copy this file from https://github.com/cloudposse/terraform-null-label/blob/master/exports/context.tf
-# and then place it in your Terraform module to automatically get
-# Cloud Posse's standard configuration inputs suitable for passing
-# to Cloud Posse modules.
-#
-# curl -sL https://raw.githubusercontent.com/cloudposse/terraform-null-label/master/exports/context.tf -o context.tf
-#
-# Modules should access the whole context as `module.this.context`
-# to get the input variables with nulls for defaults,
-# for example `context = module.this.context`,
-# and access individual variables as `module.this.`,
-# with final values filled in.
-#
-# For example, when using defaults, `module.this.context.delimiter`
-# will be null, and `module.this.delimiter` will be `-` (hyphen).
-#
-
-module "this" {
- source = "cloudposse/label/null"
- version = "0.25.0" # requires Terraform >= 0.13.0
-
- enabled = var.enabled
- namespace = var.namespace
- tenant = var.tenant
- environment = var.environment
- stage = var.stage
- name = var.name
- delimiter = var.delimiter
- attributes = var.attributes
- tags = var.tags
- additional_tag_map = var.additional_tag_map
- label_order = var.label_order
- regex_replace_chars = var.regex_replace_chars
- id_length_limit = var.id_length_limit
- label_key_case = var.label_key_case
- label_value_case = var.label_value_case
- descriptor_formats = var.descriptor_formats
- labels_as_tags = var.labels_as_tags
-
- context = var.context
-}
-
-# Copy contents of cloudposse/terraform-null-label/variables.tf here
-
-variable "context" {
- type = any
- default = {
- enabled = true
- namespace = null
- tenant = null
- environment = null
- stage = null
- name = null
- delimiter = null
- attributes = []
- tags = {}
- additional_tag_map = {}
- regex_replace_chars = null
- label_order = []
- id_length_limit = null
- label_key_case = null
- label_value_case = null
- descriptor_formats = {}
- # Note: we have to use [] instead of null for unset lists due to
- # https://github.com/hashicorp/terraform/issues/28137
- # which was not fixed until Terraform 1.0.0,
- # but we want the default to be all the labels in `label_order`
- # and we want users to be able to prevent all tag generation
- # by setting `labels_as_tags` to `[]`, so we need
- # a different sentinel to indicate "default"
- labels_as_tags = ["unset"]
- }
- description = <<-EOT
- Single object for setting entire context at once.
- See description of individual variables for details.
- Leave string and numeric variables as `null` to use default value.
- Individual variable settings (non-null) override settings in context object,
- except for attributes, tags, and additional_tag_map, which are merged.
- EOT
-
- validation {
- condition = lookup(var.context, "label_key_case", null) == null ? true : contains(["lower", "title", "upper"], var.context["label_key_case"])
- error_message = "Allowed values: `lower`, `title`, `upper`."
- }
-
- validation {
- condition = lookup(var.context, "label_value_case", null) == null ? true : contains(["lower", "title", "upper", "none"], var.context["label_value_case"])
- error_message = "Allowed values: `lower`, `title`, `upper`, `none`."
- }
-}
-
-variable "enabled" {
- type = bool
- default = null
- description = "Set to false to prevent the module from creating any resources"
-}
-
-variable "namespace" {
- type = string
- default = null
- description = "ID element. Usually an abbreviation of your organization name, e.g. 'eg' or 'cp', to help ensure generated IDs are globally unique"
-}
-
-variable "tenant" {
- type = string
- default = null
- description = "ID element _(Rarely used, not included by default)_. A customer identifier, indicating who this instance of a resource is for"
-}
-
-variable "environment" {
- type = string
- default = null
- description = "ID element. Usually used for region e.g. 'uw2', 'us-west-2', OR role 'prod', 'staging', 'dev', 'UAT'"
-}
-
-variable "stage" {
- type = string
- default = null
- description = "ID element. Usually used to indicate role, e.g. 'prod', 'staging', 'source', 'build', 'test', 'deploy', 'release'"
-}
-
-variable "name" {
- type = string
- default = null
- description = <<-EOT
- ID element. Usually the component or solution name, e.g. 'app' or 'jenkins'.
- This is the only ID element not also included as a `tag`.
- The "name" tag is set to the full `id` string. There is no tag with the value of the `name` input.
- EOT
-}
-
-variable "delimiter" {
- type = string
- default = null
- description = <<-EOT
- Delimiter to be used between ID elements.
- Defaults to `-` (hyphen). Set to `""` to use no delimiter at all.
- EOT
-}
-
-variable "attributes" {
- type = list(string)
- default = []
- description = <<-EOT
- ID element. Additional attributes (e.g. `workers` or `cluster`) to add to `id`,
- in the order they appear in the list. New attributes are appended to the
- end of the list. The elements of the list are joined by the `delimiter`
- and treated as a single ID element.
- EOT
-}
-
-variable "labels_as_tags" {
- type = set(string)
- default = ["default"]
- description = <<-EOT
- Set of labels (ID elements) to include as tags in the `tags` output.
- Default is to include all labels.
- Tags with empty values will not be included in the `tags` output.
- Set to `[]` to suppress all generated tags.
- **Notes:**
- The value of the `name` tag, if included, will be the `id`, not the `name`.
- Unlike other `null-label` inputs, the initial setting of `labels_as_tags` cannot be
- changed in later chained modules. Attempts to change it will be silently ignored.
- EOT
-}
-
-variable "tags" {
- type = map(string)
- default = {}
- description = <<-EOT
- Additional tags (e.g. `{'BusinessUnit': 'XYZ'}`).
- Neither the tag keys nor the tag values will be modified by this module.
- EOT
-}
-
-variable "additional_tag_map" {
- type = map(string)
- default = {}
- description = <<-EOT
- Additional key-value pairs to add to each map in `tags_as_list_of_maps`. Not added to `tags` or `id`.
- This is for some rare cases where resources want additional configuration of tags
- and therefore take a list of maps with tag key, value, and additional configuration.
- EOT
-}
-
-variable "label_order" {
- type = list(string)
- default = null
- description = <<-EOT
- The order in which the labels (ID elements) appear in the `id`.
- Defaults to ["namespace", "environment", "stage", "name", "attributes"].
- You can omit any of the 6 labels ("tenant" is the 6th), but at least one must be present.
- EOT
-}
-
-variable "regex_replace_chars" {
- type = string
- default = null
- description = <<-EOT
- Terraform regular expression (regex) string.
- Characters matching the regex will be removed from the ID elements.
- If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits.
- EOT
-}
-
-variable "id_length_limit" {
- type = number
- default = null
- description = <<-EOT
- Limit `id` to this many characters (minimum 6).
- Set to `0` for unlimited length.
- Set to `null` for keep the existing setting, which defaults to `0`.
- Does not affect `id_full`.
- EOT
- validation {
- condition = var.id_length_limit == null ? true : var.id_length_limit >= 6 || var.id_length_limit == 0
- error_message = "The id_length_limit must be >= 6 if supplied (not null), or 0 for unlimited length."
- }
-}
-
-variable "label_key_case" {
- type = string
- default = null
- description = <<-EOT
- Controls the letter case of the `tags` keys (label names) for tags generated by this module.
- Does not affect keys of tags passed in via the `tags` input.
- Possible values: `lower`, `title`, `upper`.
- Default value: `title`.
- EOT
-
- validation {
- condition = var.label_key_case == null ? true : contains(["lower", "title", "upper"], var.label_key_case)
- error_message = "Allowed values: `lower`, `title`, `upper`."
- }
-}
-
-variable "label_value_case" {
- type = string
- default = null
- description = <<-EOT
- Controls the letter case of ID elements (labels) as included in `id`,
- set as tag values, and output by this module individually.
- Does not affect values of tags passed in via the `tags` input.
- Possible values: `lower`, `title`, `upper` and `none` (no transformation).
- Set this to `title` and set `delimiter` to `""` to yield Pascal Case IDs.
- Default value: `lower`.
- EOT
-
- validation {
- condition = var.label_value_case == null ? true : contains(["lower", "title", "upper", "none"], var.label_value_case)
- error_message = "Allowed values: `lower`, `title`, `upper`, `none`."
- }
-}
-
-variable "descriptor_formats" {
- type = any
- default = {}
- description = <<-EOT
- Describe additional descriptors to be output in the `descriptors` output map.
- Map of maps. Keys are names of descriptors. Values are maps of the form
- `{
- format = string
- labels = list(string)
- }`
- (Type is `any` so the map values can later be enhanced to provide additional options.)
- `format` is a Terraform format string to be passed to the `format()` function.
- `labels` is a list of labels, in order, to pass to `format()` function.
- Label values will be normalized before being passed to `format()` so they will be
- identical to how they appear in `id`.
- Default is `{}` (`descriptors` output will be empty).
- EOT
-}
-
-#### End of copy of cloudposse/terraform-null-label/variables.tf
diff --git a/examples/complete/fixtures.tfvars b/examples/complete/fixtures.tfvars
new file mode 100644
index 0000000..6f6a70d
--- /dev/null
+++ b/examples/complete/fixtures.tfvars
@@ -0,0 +1,5 @@
+context_templates = {
+ snowflake-resource-monitor = "{{.environment}}_{{.name}}"
+ snowflake-resource-monitor-role = "{{.prefix}}_{{.environment}}_{{.resource-monitor}}_{{.name}}"
+ snowflake-project-resource-monitor = "{{.environment}}_{{.project}}_{{.name}}"
+}
diff --git a/examples/complete/main.tf b/examples/complete/main.tf
index 36d40b6..316d36e 100644
--- a/examples/complete/main.tf
+++ b/examples/complete/main.tf
@@ -3,14 +3,15 @@
*
* This example creates:
*
-* * Resource monitor for warehouse, that will ill notify account
+* * Resource monitor, that will will notify account
* administrators and specified users when 50%, 80% of credit
* quota is reached, will also suspend all warehouses assigned
* to this monitor.
-* * Resource monitor for account, that will notify account
+* * Resource monitor, that will notify account
* administrators when 50%, 80%,90% of credit quota is reached,
* will also suspend immediately (all running queries will be cancelled)
* all warehouses in the account when 100% quota is reached.
+* * Resource monitor, simmilar to the abve, with different name scheme
*/
resource "snowflake_user" "this_user" {
@@ -36,88 +37,55 @@ resource "snowflake_account_role" "this_dev" {
comment = "Role for Snowflake Users"
}
-module "warehouse_users" {
- source = "getindata/warehouse/snowflake"
- version = "2.2.0"
-
- name = "warehouse_users"
- comment = "warehouse for users"
-
- warehouse_size = "x-small"
-
- auto_resume = true
- auto_suspend = 600
- initially_suspended = true
-
- create_default_roles = true
+module "resource_monitor_1" {
+ source = "../../"
- roles = {
- usage = {
- granted_to_roles = ["USER"]
+ name = "test_1"
+ name_scheme = {
+ properties = ["environment", "project", "name"]
+ extra_values = {
+ project = "project"
}
}
-}
-
-module "warehouse_dbt" {
- source = "getindata/warehouse/snowflake"
- version = "2.2.0"
- name = "warehouse_dbt"
- comment = "warehouse for dbt usage"
+ credit_quota = 20
- warehouse_size = "x-small"
+ frequency = "MONTHLY"
+ start_timestamp = formatdate("YYYY-MM-DD hh:mm", timeadd(plantimestamp(), "4h"))
+ end_timestamp = formatdate("YYYY-MM-DD hh:mm", timeadd(plantimestamp(), "1000h"))
- auto_resume = true
- auto_suspend = 600
- initially_suspended = true
+ suspend_trigger = 100
+ notify_triggers = [50, 80]
create_default_roles = true
roles = {
- usage = {
- granted_to_users = ["dbt_user"]
+ admin = {
+ granted_to_roles = [snowflake_account_role.this_admin.name]
+ }
+ custom_role = {
+ resource_monitor_grants = {
+ privileges = ["MONITOR", "MODIFY"]
+ }
+ granted_to_roles = [snowflake_account_role.this_dev.name]
+ granted_to_users = [snowflake_user.this_user.name]
}
}
-
- depends_on = [snowflake_user.this_dbt]
}
-/*
- * Resource monitor for warehouse
- * Will notify account administrators and specified users when
- * 50%, 80% of credit quota is reached.
- * Will notify account administrators plus specified users and
- * suspend all warehouses assigned to this monitor.
-*/
-module "warehouse_resource_monitor" {
+module "resource_monitor_2" {
source = "../../"
- descriptor_formats = {
- snowflake-role = {
- labels = ["attributes", "name"]
- format = "%v_%v"
- }
- snowflake-resource-monitor = {
- labels = ["name", "attributes"]
- format = "%v_%v"
- }
- }
-
- enabled = true
+ name = "test_2"
+ context_templates = var.context_templates
- name = "warehouse"
- attributes = ["resource", "monitor"]
-
- credit_quota = 20
+ credit_quota = 200
+ start_timestamp = formatdate("YYYY-MM-DD hh:mm", timeadd(plantimestamp(), "4h"))
frequency = "MONTHLY"
- start_timestamp = formatdate("YYYY-MM-DD HH:MM", timeadd(timestamp(), "1h"))
- end_timestamp = formatdate("YYYY-MM-DD HH:MM", timeadd(timestamp(), "1000h"))
- suspend_trigger = 100
- notify_triggers = [50, 80]
-
- warehouses = [module.warehouse_users.warehouse.name]
+ notify_triggers = [50, 80, 90]
+ suspend_immediate_trigger = 100
create_default_roles = true
@@ -125,55 +93,25 @@ module "warehouse_resource_monitor" {
admin = {
granted_to_roles = [snowflake_account_role.this_admin.name]
}
- custom_role = {
- resource_monitor_grants = {
- privileges = ["MONITOR", "MODIFY"]
- }
- granted_to_roles = [snowflake_account_role.this_dev.name]
- granted_to_users = [nonsensitive(snowflake_user.this_user.name)]
- }
}
-
- depends_on = [
- snowflake_account_role.this_dev,
- snowflake_account_role.this_admin,
- snowflake_user.this_user,
- module.warehouse_users.warehouse,
- ]
}
-/*
- * Resource monitor for account.
- * Will notify account administrators when 50%, 80%,90%
- * of credit quota is reached.
- * Will notify account administrators and suspend immediately
- * (all running queries will be cancelled) all warehouses in
- * the accouny when 100% quota is reached.
-*/
-module "account_resource_monitor" {
+module "resource_monitor_3" {
source = "../../"
- descriptor_formats = {
- snowflake-role = {
- labels = ["attributes", "name"]
- format = "%v_%v"
- }
- snowflake-resource-monitor = {
- labels = ["name", "attributes"]
- format = "%v_%v"
+ name = "test_3"
+ name_scheme = {
+ context_template_name = "snowflake-project-resource-monitor"
+ extra_values = {
+ project = "project"
}
}
+ context_templates = var.context_templates
- enabled = true
- set_for_account = true
-
- name = "account"
- attributes = ["resource", "monitor"]
+ credit_quota = 10
- credit_quota = 200
-
- start_timestamp = formatdate("YYYY-MM-DD HH:MM", timeadd(timestamp(), "1h"))
+ start_timestamp = formatdate("YYYY-MM-DD hh:mm", timeadd(plantimestamp(), "4h"))
frequency = "MONTHLY"
notify_triggers = [50, 80, 90]
@@ -187,6 +125,4 @@ module "account_resource_monitor" {
}
}
- depends_on = [snowflake_account_role.this_admin]
-
}
diff --git a/examples/complete/outputs.tf b/examples/complete/outputs.tf
index b9201a9..ea55518 100644
--- a/examples/complete/outputs.tf
+++ b/examples/complete/outputs.tf
@@ -1,9 +1,14 @@
-output "warehouse_resource_monitor" {
- description = "Details of warehouse resource monitor"
- value = module.warehouse_resource_monitor
+output "resource_monitor_1" {
+ description = "Details of resource monitor"
+ value = module.resource_monitor_1
}
-output "account_resource_monitor" {
- description = "Details of account resource monitor"
- value = module.account_resource_monitor
+output "resource_monitor_2" {
+ description = "Details of resource monitor"
+ value = module.resource_monitor_2
+}
+
+output "resource_monitor_3" {
+ description = "Details of resource monitor"
+ value = module.resource_monitor_3
}
diff --git a/examples/complete/providers.tf b/examples/complete/providers.tf
index d343f0d..5b943b9 100644
--- a/examples/complete/providers.tf
+++ b/examples/complete/providers.tf
@@ -1 +1,12 @@
provider "snowflake" {}
+
+provider "context" {
+ properties = {
+ "environment" = {}
+ "name" = { required = true }
+ }
+
+ values = {
+ environment = "dev"
+ }
+}
diff --git a/examples/complete/variables.tf b/examples/complete/variables.tf
new file mode 100644
index 0000000..45dbcd2
--- /dev/null
+++ b/examples/complete/variables.tf
@@ -0,0 +1,4 @@
+variable "context_templates" {
+ description = "A map of context templates to use for generating user names"
+ type = map(string)
+}
diff --git a/examples/complete/versions.tf b/examples/complete/versions.tf
index beae9eb..76fdc33 100644
--- a/examples/complete/versions.tf
+++ b/examples/complete/versions.tf
@@ -1,9 +1,13 @@
terraform {
- required_version = ">= 1.3"
+ required_version = ">= 1.5"
required_providers {
snowflake = {
source = "Snowflake-Labs/snowflake"
version = "~> 0.54"
}
+ context = {
+ source = "cloudposse/context"
+ version = ">=0.4.0"
+ }
}
}
diff --git a/examples/simple/main.tf b/examples/simple/main.tf
index 30a379a..909405d 100644
--- a/examples/simple/main.tf
+++ b/examples/simple/main.tf
@@ -10,8 +10,6 @@
module "resource_monitor" {
source = "../../"
- set_for_account = true
-
name = "example_resource_monitor"
credit_quota = 200
diff --git a/locals.tf b/locals.tf
index ee36860..25f71d7 100644
--- a/locals.tf
+++ b/locals.tf
@@ -1,10 +1,14 @@
locals {
- name_from_descriptor = module.monitor_label.enabled ? trim(replace(
- lookup(module.monitor_label.descriptors, var.descriptor_name, module.monitor_label.id), "/${module.monitor_label.delimiter}${module.monitor_label.delimiter}+/", module.monitor_label.delimiter
- ), module.monitor_label.delimiter) : null
+ context_template = lookup(var.context_templates, var.name_scheme.context_template_name, null)
- enabled = module.this.enabled
- create_default_roles = local.enabled && var.create_default_roles
+ default_role_naming_scheme = {
+ properties = ["prefix", "environment", "resource-monitor", "name"]
+ context_template_name = "snowflake-resource-monitor-role"
+ extra_values = {
+ prefix = "rmn"
+ resource-monitor = var.name
+ }
+ }
default_roles_definition = {
readonly = {
@@ -31,7 +35,7 @@ locals {
default_roles = {
for role_name, role in local.roles_definition : role_name => role
- if contains(keys(local.default_roles_definition), role_name)
+ if contains(keys(local.default_roles_definition), role_name) && var.create_default_roles
}
custom_roles = {
for role_name, role in local.roles_definition : role_name => role
@@ -43,7 +47,7 @@ locals {
module.snowflake_default_role,
module.snowflake_custom_role
) : role_name => role
- if role.name != null
+ if role_name != null
}
}
diff --git a/main.tf b/main.tf
index d8ad7cc..1e3cd8f 100644
--- a/main.tf
+++ b/main.tf
@@ -1,17 +1,18 @@
-module "monitor_label" {
- source = "cloudposse/label/null"
- version = "0.25.0"
- context = module.this.context
-
- delimiter = coalesce(module.this.context.delimiter, "_")
- regex_replace_chars = coalesce(module.this.context.regex_replace_chars, "/[^_a-zA-Z0-9]/")
- label_value_case = coalesce(module.this.context.label_value_case, "upper")
+data "context_label" "this" {
+ delimiter = local.context_template == null ? var.name_scheme.delimiter : null
+ properties = local.context_template == null ? var.name_scheme.properties : null
+ template = local.context_template
+
+ replace_chars_regex = var.name_scheme.replace_chars_regex
+
+ values = merge(
+ var.name_scheme.extra_values,
+ { name = var.name }
+ )
}
resource "snowflake_resource_monitor" "this" {
- count = local.enabled ? 1 : 0
-
- name = local.name_from_descriptor
+ name = data.context_label.this.rendered
credit_quota = var.credit_quota
@@ -24,22 +25,23 @@ resource "snowflake_resource_monitor" "this" {
suspend_immediate_trigger = var.suspend_immediate_trigger
notify_users = var.notify_users
-
- set_for_account = var.set_for_account
- warehouses = var.warehouses
+}
+moved {
+ from = snowflake_resource_monitor.this[0]
+ to = snowflake_resource_monitor.this
}
module "snowflake_default_role" {
for_each = local.default_roles
source = "getindata/role/snowflake"
- version = "2.1.0"
- context = module.this.context
+ version = "3.0.1"
- name = each.key
- attributes = ["RMN", one(snowflake_resource_monitor.this[*].name)]
- enabled = local.create_default_roles && lookup(each.value, "enabled", true)
- descriptor_name = lookup(each.value, "descriptor_name", "snowflake-role")
+ name = each.key
+ name_scheme = merge(
+ local.default_role_naming_scheme,
+ lookup(each.value, "name_scheme", {})
+ )
role_ownership_grant = lookup(each.value, "role_ownership_grant", "SYSADMIN")
granted_to_users = lookup(each.value, "granted_to_users", [])
@@ -51,26 +53,22 @@ module "snowflake_default_role" {
all_privileges = each.value.resource_monitor_grants.all_privileges
privileges = each.value.resource_monitor_grants.privileges
with_grant_option = each.value.resource_monitor_grants.with_grant_option
- object_name = one(snowflake_resource_monitor.this[*].name)
+ object_name = snowflake_resource_monitor.this.name
}]
}
-
- depends_on = [
- snowflake_resource_monitor.this
- ]
}
module "snowflake_custom_role" {
for_each = local.custom_roles
source = "getindata/role/snowflake"
- version = "2.1.0"
- context = module.this.context
+ version = "3.0.1"
- name = each.key
- attributes = ["RMN", one(snowflake_resource_monitor.this[*].name)]
- enabled = lookup(each.value, "enabled", true)
- descriptor_name = lookup(each.value, "descriptor_name", "snowflake-role")
+ name = each.key
+ name_scheme = merge(
+ local.default_role_naming_scheme,
+ lookup(each.value, "name_scheme", {})
+ )
role_ownership_grant = lookup(each.value, "role_ownership_grant", "SYSADMIN")
granted_to_users = lookup(each.value, "granted_to_users", [])
@@ -82,11 +80,7 @@ module "snowflake_custom_role" {
all_privileges = each.value.resource_monitor_grants.all_privileges
privileges = each.value.resource_monitor_grants.privileges
with_grant_option = each.value.resource_monitor_grants.with_grant_option
- object_name = one(snowflake_resource_monitor.this[*].name)
+ object_name = snowflake_resource_monitor.this.name
}]
}
-
- depends_on = [
- snowflake_resource_monitor.this
- ]
}
diff --git a/outputs.tf b/outputs.tf
index a3720b1..45a1768 100644
--- a/outputs.tf
+++ b/outputs.tf
@@ -1,56 +1,46 @@
output "name" {
description = "Name of resource monitor"
- value = one(resource.snowflake_resource_monitor.this[*].name)
+ value = resource.snowflake_resource_monitor.this.name
}
output "credit_quota" {
- description = "he number of credits allocated monthly to the resource monitor"
- value = one(resource.snowflake_resource_monitor.this[*].credit_quota)
+ description = "The number of credits allocated monthly to the resource monitor"
+ value = resource.snowflake_resource_monitor.this.credit_quota
}
output "start_timestamp" {
description = "The date and time when the resource monitor starts monitoring credit usage"
- value = one(resource.snowflake_resource_monitor.this[*].start_timestamp)
+ value = resource.snowflake_resource_monitor.this.start_timestamp
}
output "end_timestamp" {
description = "The date and time when the resource monitor suspends the assigned warehouses"
- value = one(resource.snowflake_resource_monitor.this[*].end_timestamp)
+ value = resource.snowflake_resource_monitor.this.end_timestamp
}
output "frequency" {
description = "The frequency interval at which the credit usage resets to 0"
- value = one(resource.snowflake_resource_monitor.this[*].frequency)
+ value = resource.snowflake_resource_monitor.this.frequency
}
output "notify_triggers" {
description = "A list of percentage thresholds at which to send an alert to subscribed users"
- value = one(resource.snowflake_resource_monitor.this[*].notify_triggers)
+ value = resource.snowflake_resource_monitor.this.notify_triggers
}
output "notify_users" {
description = "A list of users to receive email notifications on resource monitors"
- value = one(resource.snowflake_resource_monitor.this[*].notify_users)
-}
-
-output "set_for_account" {
- description = "Whether the resource monitor should be applied globally to your Snowflake account"
- value = one(resource.snowflake_resource_monitor.this[*].set_for_account)
+ value = resource.snowflake_resource_monitor.this.notify_users
}
output "suspend_immediate_triggers" {
description = "A list of percentage thresholds at which to immediately suspend all warehouses"
- value = one(resource.snowflake_resource_monitor.this[*].suspend_immediate_triggers)
+ value = resource.snowflake_resource_monitor.this.suspend_immediate_trigger
}
output "suspend_triggers" {
description = "A list of percentage thresholds at which to suspend all warehouses"
- value = one(resource.snowflake_resource_monitor.this[*].suspend_triggers)
-}
-
-output "warehouses" {
- description = "A list of warehouse names to apply the resource monitor to"
- value = one(resource.snowflake_resource_monitor.this[*].warehouses)
+ value = resource.snowflake_resource_monitor.this.suspend_trigger
}
output "roles" {
diff --git a/variables.tf b/variables.tf
index ee841fe..d50a4cb 100644
--- a/variables.tf
+++ b/variables.tf
@@ -1,3 +1,8 @@
+variable "name" {
+ description = "Name of the resource"
+ type = string
+}
+
variable "credit_quota" {
description = "The number of credits allocated monthly to the resource monitor."
type = number
@@ -50,23 +55,16 @@ variable "notify_users" {
default = null
}
-variable "set_for_account" {
- description = "Specifies whether the resource monitor should be applied globally to your Snowflake account."
- type = bool
- default = false
-}
-
-variable "warehouses" {
- description = "A list of warehouse names to apply the resource monitor to."
- type = list(string)
- default = null
-}
-
variable "roles" {
description = "Roles created on the Resource Monitor level"
type = map(object({
- enabled = optional(bool, true)
- descriptor_name = optional(string, "snowflake-role")
+ name_scheme = optional(object({
+ properties = optional(list(string))
+ delimiter = optional(string)
+ context_template_name = optional(string)
+ replace_chars_regex = optional(string)
+ extra_labels = optional(map(string))
+ }))
comment = optional(string)
role_ownership_grant = optional(string)
granted_roles = optional(list(string))
@@ -87,8 +85,27 @@ variable "create_default_roles" {
default = false
}
-variable "descriptor_name" {
- description = "Name of the descriptor used to form a resource name"
- type = string
- default = "snowflake-resource-monitor"
+variable "name_scheme" {
+ description = <