Skip to content

Commit 7c25a0d

Browse files
authored
fix: Fixed table naming via attributes (#2)
## Description <!--- Describe your changes in detail --> ## Motivation and Context <!--- Why is this change required? What problem does it solve? --> <!--- If it fixes an open issue, please link to the issue here. --> ## Breaking Changes <!-- Does this break backwards compatibility with the current major version? --> <!-- If so, please provide an explanation why it is necessary. --> ## How Has This Been Tested? - [ ] I have updated at least one of the `examples/*` to demonstrate and validate my change(s) - [ ] I have tested and validated these changes using one or more of the provided `examples/*` projects <!--- Users should start with an existing example as its written, deploy it, then check their changes against it --> <!--- This will highlight breaking/disruptive changes. Once you have checked, deploy your changes to verify --> <!--- Please describe how you tested your changes --> - [ ] I have executed `pre-commit run -a` on my pull request <!--- Please see https://github.com/antonbabenko/pre-commit-terraform#how-to-install for how to install -->
1 parent a418e52 commit 7c25a0d

File tree

5 files changed

+44
-5
lines changed

5 files changed

+44
-5
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ No providers.
1717
| Name | Source | Version |
1818
|------|--------|---------|
1919
| <a name="module_table"></a> [table](#module\_table) | github.com/justtrackio/terraform-aws-dynamodb-table | v1.0.1 |
20+
| <a name="module_table_label"></a> [table\_label](#module\_table\_label) | cloudposse/label/null | 0.25.0 |
2021
| <a name="module_this"></a> [this](#module\_this) | cloudposse/label/null | 0.25.0 |
2122

2223
## Resources
@@ -29,6 +30,7 @@ No resources.
2930
|------|-------------|------|---------|:--------:|
3031
| <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 |
3132
| <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 |
33+
| <a name="input_attributes_as_suffix"></a> [attributes\_as\_suffix](#input\_attributes\_as\_suffix) | Attributes passed into the module are put in front of each.key (model name) by default. Setting this to true will put the attributes after the each.key. | `bool` | `false` | no |
3234
| <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 |
3335
| <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 |
3436
| <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 |

examples/basic/main.tf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
module "example" {
22
source = "../.."
33

4-
environment = "example"
4+
namespace = "ns"
5+
environment = "env"
6+
stage = "st"
7+
name = "app"
8+
attributes = ["foo"]
59

610
tables = {
711
basic = {

examples/full/main.tf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
module "example" {
22
source = "../.."
33

4-
environment = "example"
4+
namespace = "ns"
5+
environment = "env"
6+
stage = "st"
7+
name = "app"
8+
attributes = ["foo"]
59

610
tables = {
711
full = {

main.tf

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,34 @@
1+
module "table_label" {
2+
source = "cloudposse/label/null"
3+
version = "0.25.0" # requires Terraform >= 0.13.0
4+
5+
for_each = var.tables
6+
7+
enabled = module.this.enabled
8+
namespace = module.this.namespace
9+
tenant = module.this.tenant
10+
environment = module.this.environment
11+
stage = module.this.stage
12+
name = module.this.name
13+
delimiter = module.this.delimiter
14+
tags = module.this.tags
15+
additional_tag_map = module.this.additional_tag_map
16+
label_order = var.label_order
17+
regex_replace_chars = module.this.regex_replace_chars
18+
id_length_limit = module.this.id_length_limit
19+
label_key_case = var.label_key_case
20+
label_value_case = var.label_value_case
21+
descriptor_formats = var.descriptor_formats
22+
labels_as_tags = var.labels_as_tags
23+
attributes = var.attributes_as_suffix ? concat([each.key], module.this.attributes) : concat(module.this.attributes, [each.key])
24+
}
25+
126
module "table" {
227
source = "github.com/justtrackio/terraform-aws-dynamodb-table?ref=v1.0.1"
328

429
for_each = var.tables
530

6-
context = module.this.context
7-
attributes = module.this.attributes
8-
name = each.key
31+
context = module.table_label[each.key].context
932

1033
autoscale_write_target = each.value.autoscaler.write_target
1134
autoscale_read_target = each.value.autoscaler.read_target

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,9 @@ variable "tables" {
8181
description = "Tables to be created"
8282
default = {}
8383
}
84+
85+
variable "attributes_as_suffix" {
86+
type = bool
87+
description = "Attributes passed into the module are put in front of each.key (model name) by default. Setting this to true will put the attributes after the each.key."
88+
default = false
89+
}

0 commit comments

Comments
 (0)