Skip to content

Commit c62a1fe

Browse files
committed
allow users to exclude some values
1 parent fc0d18c commit c62a1fe

File tree

10 files changed

+142
-122
lines changed

10 files changed

+142
-122
lines changed

.header.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
# Terraform AWS Label Module
3+
The Terraform Amazon Web Services (AWS) Label module generates consistent label names and tags for Terraform resources.
4+
5+
---

.terraform-docs.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
formatter: markdown
2+
header-from: .header.md
3+
settings:
4+
anchor: true
5+
color: true
6+
default: true
7+
escape: true
8+
html: true
9+
indent: 2
10+
required: true
11+
sensitive: true
12+
type: true

README.md

Lines changed: 33 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -4,94 +4,48 @@ The Terraform Amazon Web Services (AWS) Label module generates consistent label
44

55
---
66

7-
## Inputs
8-
9-
* ```region```
10-
* description: AWS Region used to host Terraform resources.
11-
* type: ``` string ```
12-
* default: ``` us-west-1 ```
13-
<br />
14-
15-
* ```namespace```
16-
* description: Namespace, generally your organization or department name (for example, ```AWS```)
17-
* type: ``` string ```
18-
* default: ``` testenv ```
19-
<br />
20-
21-
* ```env```
22-
* description: Environment name (for example, ```sit```, ```uat```, or ```prod```)
23-
* type: ``` string ```
24-
* default: ``` testns ```
25-
<br />
7+
## Requirements
268

27-
* ```account```
28-
* description: AWS account name or number.
29-
* type: ``` string ```
30-
* default: ``` testacc ```
31-
<br />
9+
| Name | Version |
10+
|------|---------|
11+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.68 |
12+
| <a name="requirement_awscc"></a> [awscc](#requirement\_awscc) | ~> 0.9 |
3213

33-
* ```name```
34-
* description: Stack name
35-
* type: ``` string ```
36-
* default: ``` testname ```
37-
<br />
14+
## Providers
3815

16+
No providers.
3917

40-
* ```delimiter```
41-
* description: Character such as a slash (/) used between ```name```, ```namespace```, and ```env``` to form the resource name.
42-
* type: ``` string ```
43-
* default: ``` - ```
44-
<br />
18+
## Modules
4519

46-
* ```attributes```
47-
* description: Additional attributes.
48-
* type: ``` list ```
49-
* default: ``` [] ```
50-
<br />
20+
No modules.
5121

52-
* ```tags```
53-
* description: Additional tags.
54-
* type: ``` list(object({
55-
key = string
56-
value = string
57-
})) ```
58-
* default: ``` [] ```
59-
<br />
22+
## Resources
6023

61-
---
62-
63-
## Usage
24+
No resources.
6425

65-
module "label" {
66-
source = "aws-ia/label/aws"
67-
version = "0.0.2"
68-
region = "us-east-1"
69-
namespace = "my org"
70-
env = "sit"
71-
account = "aws-account-name"
72-
name = "deployment name"
73-
delimiter = "-"
74-
tags = tomap({ propogate_at_launch = "true", "terraform" = "true" })
75-
}
76-
77-
For more information please see the `examples` folder.
26+
## Inputs
7827

79-
---
28+
| Name | Description | Type | Default | Required |
29+
|------|-------------|------|---------|:--------:|
30+
| <a name="input_account"></a> [account](#input\_account) | account, which could be AWS Account Name or Number | `any` | `null` | no |
31+
| <a name="input_attributes"></a> [attributes](#input\_attributes) | attributes, which could be used for additional attributes | `list` | `[]` | no |
32+
| <a name="input_delimiter"></a> [delimiter](#input\_delimiter) | delimiter, which could be used between name, namespace and env | `string` | `"-"` | no |
33+
| <a name="input_env"></a> [env](#input\_env) | environment, e.g. 'sit', 'uat', 'prod' etc | `any` | `null` | no |
34+
| <a name="input_id_order"></a> [id\_order](#input\_id\_order) | n/a | `list` | <pre>[<br> "namespace",<br> "account",<br> "env",<br> "name"<br>]</pre> | no |
35+
| <a name="input_name"></a> [name](#input\_name) | stack name | `any` | `null` | no |
36+
| <a name="input_namespace"></a> [namespace](#input\_namespace) | namespace, which could be your organization name, e.g. amazon | `any` | `null` | no |
37+
| <a name="input_region"></a> [region](#input\_region) | n/a | `string` | `"us-west-1"` | no |
38+
| <a name="input_tags"></a> [tags](#input\_tags) | tags, which could be used for additional tags | `any` | `[]` | no |
8039

8140
## Outputs
8241

83-
* ```tags``` - List of tags.
84-
85-
* ```id``` - ID of a tag delimited with a dash (-).
86-
87-
* ```name``` - Stack name.
88-
89-
* ```namespace``` - Namespace.
90-
91-
* ```account``` - AWS account.
92-
93-
* ```env``` - Environment name.
94-
95-
* ```attributes``` - List of additional attributes.
96-
97-
---
42+
| Name | Description |
43+
|------|-------------|
44+
| <a name="output_account"></a> [account](#output\_account) | n/a |
45+
| <a name="output_attributes"></a> [attributes](#output\_attributes) | n/a |
46+
| <a name="output_env"></a> [env](#output\_env) | n/a |
47+
| <a name="output_id"></a> [id](#output\_id) | n/a |
48+
| <a name="output_name"></a> [name](#output\_name) | n/a |
49+
| <a name="output_namespace"></a> [namespace](#output\_namespace) | n/a |
50+
| <a name="output_tags"></a> [tags](#output\_tags) | n/a |
51+
| <a name="output_tags_aws"></a> [tags\_aws](#output\_tags\_aws) | n/a |

locals.tf

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,32 @@
1+
# resource "null_resource" "default" {
2+
# triggers = local.non_empty_vars_map
3+
4+
# lifecycle {
5+
# create_before_destroy = true
6+
# }
7+
# }
8+
19
locals {
10+
order = ["namespace", "account", "env", "name"]
11+
vars = {
12+
name = var.name
13+
namespace = var.namespace
14+
env = var.env
15+
account = var.account
16+
}
17+
non_empty_vars = [for k, v in local.vars : k if v != null]
18+
non_empty_vars_map = { for k in local.non_empty_vars : k => local.vars[k] }
19+
20+
# using the order from var.id_order, create the delmitied id from vars that are actually passed
21+
ordered_id = join(var.delimiter, compact(concat([for k in var.id_order : contains(local.non_empty_vars, k) ? lookup(local.vars, k) : null], var.attributes)))
222
generated_tags_awscc = [
23+
for k, v in local.non_empty_vars_map :
324
{
4-
"key" : "Name",
5-
"value" : join("", null_resource.default.*.triggers.id)
6-
},
7-
{
8-
"key" : "Namespace",
9-
"value" : join("", null_resource.default.*.triggers.namespace),
10-
},
11-
{
12-
"key" : "Account",
13-
"value" : join("", null_resource.default.*.triggers.account)
14-
},
15-
{
16-
"key" : "Env",
17-
"value" : join("", null_resource.default.*.triggers.env)
25+
key : k,
26+
value : v
1827
}
1928
]
29+
2030
generated_tags_aws = { for tag in local.generated_tags_awscc : tag["key"] => tag["value"] }
2131

2232
tags = try(
@@ -32,4 +42,4 @@ locals {
3242
# Tags are in awscc format. Converting to aws format
3343
merge(local.generated_tags_aws, { for tag in var.tags : tag["key"] => tag["value"] })
3444
)
35-
}
45+
}

main.tf

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

output.tf

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,21 @@ output "tags_aws" {
88
}
99

1010
output "id" {
11-
value = join("", null_resource.default.*.triggers.id)
11+
value = local.ordered_id
1212
}
1313

1414
output "name" {
15-
value = join("", null_resource.default.*.triggers.name)
15+
value = local.vars["name"]
1616
}
1717

1818
output "namespace" {
19-
value = join("", null_resource.default.*.triggers.namespace)
19+
value = local.vars["namespace"]
2020
}
2121

2222
output "account" {
23-
value = join("", null_resource.default.*.triggers.account)
23+
value = local.vars["account"]
2424
}
2525

2626
output "env" {
27-
value = join("", null_resource.default.*.triggers.env)
28-
}
29-
30-
output "attributes" {
31-
value = join("", null_resource.default.*.triggers.attributes)
27+
value = local.vars["env"]
3228
}

test/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
## Requirements
2+
3+
No requirements.
4+
5+
## Providers
6+
7+
No providers.
8+
9+
## Modules
10+
11+
No modules.
12+
13+
## Resources
14+
15+
No resources.
16+
17+
## Inputs
18+
19+
No inputs.
20+
21+
## Outputs
22+
23+
No outputs.

test/label_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"github.com/gruntwork-io/terratest/modules/terraform"
77
)
88

9-
func validate(t *testing.T, terraformOptions *terraform.Options) {
9+
func validate(t *testing.T, terraformOptions *terraform.Options) {
1010
defer terraform.Destroy(t, terraformOptions)
1111
terraform.InitAndApply(t, terraformOptions)
1212
}
@@ -30,4 +30,3 @@ func TestFormattedTags(t *testing.T) {
3030

3131
validate(t, terraformOptions)
3232
}
33-

variable.tf

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,40 @@
11
variable "region" {
2+
type = string
23
default = "us-west-1"
34
}
45

56
variable "namespace" {
7+
type = string
68
description = "namespace, which could be your organization name, e.g. amazon"
7-
default = "testns"
9+
default = null
810
}
911

1012
variable "env" {
13+
type = string
1114
description = "environment, e.g. 'sit', 'uat', 'prod' etc"
12-
default = "testenv"
15+
default = null
1316
}
1417

1518
variable "account" {
19+
type = string
1620
description = "account, which could be AWS Account Name or Number"
17-
default = "testacc"
21+
default = null
1822
}
1923

2024
variable "name" {
25+
type = string
2126
description = "stack name"
22-
default = "testname"
27+
default = null
2328
}
2429

2530
variable "delimiter" {
31+
type = string
2632
description = "delimiter, which could be used between name, namespace and env"
2733
default = "-"
2834
}
2935

3036
variable "attributes" {
37+
type = list(any)
3138
default = []
3239
description = "attributes, which could be used for additional attributes"
3340
}
@@ -37,3 +44,9 @@ variable "tags" {
3744
type = any
3845
default = []
3946
}
47+
48+
variable "id_order" {
49+
type = list(any)
50+
default = ["namespace", "account", "env", "name"]
51+
52+
}

versions.tf

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
terraform {
2+
required_providers {
3+
awscc = {
4+
source = "hashicorp/awscc"
5+
version = "~> 0.9"
6+
}
7+
aws = {
8+
source = "hashicorp/aws"
9+
version = ">= 3.68"
10+
}
11+
}
12+
}
13+
14+
provider "awscc" {
15+
user_agent = [{
16+
product_name = "terraform-aws-label"
17+
product_version = "0.0.1"
18+
comment = "V1/AWS-D69B4015/376222271"
19+
}]
20+
21+
}

0 commit comments

Comments
 (0)