Skip to content

Commit e2b880b

Browse files
authored
Terraform 0.12 support (#63)
* Terraform 0.12 support * add tests scenario * Update README
1 parent d58e7d8 commit e2b880b

File tree

23 files changed

+688
-415
lines changed

23 files changed

+688
-415
lines changed

README.md

Lines changed: 168 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ All [Cloud Posse modules](https://github.com/cloudposse?utf8=%E2%9C%93&q=terrafo
2020

2121
**NOTE:** The `null` refers to the primary Terraform [provider](https://www.terraform.io/docs/providers/null/index.html) used in this module.
2222

23+
Releases of this module from `0.12.0` onward support `HCL2` and only work with Terraform 0.12 or newer. Releases prior to this are compatible with earlier versions of terraform like Terraform 0.11.
24+
2325

2426
---
2527

@@ -85,17 +87,17 @@ Now reference the label when creating an instance:
8587
```hcl
8688
resource "aws_instance" "eg_prod_bastion_public" {
8789
instance_type = "t1.micro"
88-
tags = "${module.eg_prod_bastion_label.tags}"
90+
tags = module.eg_prod_bastion_label.tags
8991
}
9092
```
9193

9294
Or define a security group:
9395

9496
```hcl
9597
resource "aws_security_group" "eg_prod_bastion_public" {
96-
vpc_id = "${var.vpc_id}"
97-
name = "${module.eg_prod_bastion_label.id}"
98-
tags = "${module.eg_prod_bastion_label.tags}"
98+
vpc_id = var.vpc_id
99+
name = module.eg_prod_bastion_label.id
100+
tags = module.eg_prod_bastion_label.tags
99101
egress {
100102
from_port = 0
101103
to_port = 0
@@ -126,8 +128,8 @@ module "eg_prod_bastion_abc_label" {
126128
}
127129
128130
resource "aws_security_group" "eg_prod_bastion_abc" {
129-
name = "${module.eg_prod_bastion_abc_label.id}"
130-
tags = "${module.eg_prod_bastion_abc_label.tags}"
131+
name = module.eg_prod_bastion_abc_label.id
132+
tags = module.eg_prod_bastion_abc_label.tags
131133
ingress {
132134
from_port = 22
133135
to_port = 22
@@ -138,8 +140,8 @@ resource "aws_security_group" "eg_prod_bastion_abc" {
138140
139141
resource "aws_instance" "eg_prod_bastion_abc" {
140142
instance_type = "t1.micro"
141-
tags = "${module.eg_prod_bastion_abc_label.tags}"
142-
  vpc_security_group_ids = ["${aws_security_group.eg_prod_bastion_abc.id}"]
143+
tags = module.eg_prod_bastion_abc_label.tags
144+
  vpc_security_group_ids = [aws_security_group.eg_prod_bastion_abc.id]
143145
}
144146
145147
module "eg_prod_bastion_xyz_label" {
@@ -157,8 +159,8 @@ module "eg_prod_bastion_xyz_label" {
157159
}
158160
159161
resource "aws_security_group" "eg_prod_bastion_xyz" {
160-
name = "${module.eg_prod_bastion_xyz_label.id}"
161-
tags = "${module.eg_prod_bastion_xyz_label.tags}"
162+
name = module.eg_prod_bastion_xyz_label.id
163+
tags = module.eg_prod_bastion_xyz_label.tags
162164
ingress {
163165
from_port = 22
164166
to_port = 22
@@ -169,8 +171,8 @@ resource "aws_security_group" "eg_prod_bastion_xyz" {
169171
170172
resource "aws_instance" "eg_prod_bastion_xyz" {
171173
instance_type = "t1.micro"
172-
tags = "${module.eg_prod_bastion_xyz_label.tags}"
173-
vpc_security_group_ids = ["${aws_security_group.eg_prod_bastion_xyz.id}"]
174+
tags = module.eg_prod_bastion_xyz_label.tags
175+
vpc_security_group_ids = [aws_security_group.eg_prod_bastion_xyz.id]
174176
}
175177
```
176178

@@ -226,19 +228,19 @@ module "label" {
226228
resource "aws_launch_template" "default" {
227229
# terraform-null-label example used here: Set template name prefix
228230
name_prefix = "${module.label.id}-"
229-
image_id = "${data.aws_ami.amazon_linux.id}"
231+
image_id = data.aws_ami.amazon_linux.id
230232
instance_type = "t2.micro"
231233
instance_initiated_shutdown_behavior = "terminate"
232234
233-
vpc_security_group_ids = ["${data.aws_security_group.default.id}"]
235+
vpc_security_group_ids = [data.aws_security_group.default.id]
234236
235237
monitoring {
236238
enabled = false
237239
}
238240
# terraform-null-label example used here: Set tags on volumes
239241
tag_specifications {
240242
resource_type = "volume"
241-
tags = "${module.label.tags}"
243+
tags = module.label.tags
242244
}
243245
}
244246
@@ -248,18 +250,18 @@ resource "aws_launch_template" "default" {
248250
resource "aws_autoscaling_group" "default" {
249251
# terraform-null-label example used here: Set ASG name prefix
250252
name_prefix = "${module.label.id}-"
251-
vpc_zone_identifier = ["${data.aws_subnet_ids.all.ids}"]
253+
vpc_zone_identifier = data.aws_subnet_ids.all.ids
252254
max_size = "1"
253255
min_size = "1"
254256
desired_capacity = "1"
255257
256258
launch_template = {
257-
id = "${aws_launch_template.default.id}"
259+
id = "aws_launch_template.default.id
258260
version = "$$Latest"
259261
}
260262
261263
# terraform-null-label example used here: Set tags on ASG and EC2 Servers
262-
tags = ["${module.label.tags_as_list_of_maps}"]
264+
tags = module.label.tags_as_list_of_maps
263265
}
264266
```
265267

@@ -291,7 +293,7 @@ module "label1" {
291293
292294
module "label2" {
293295
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=master"
294-
context = "${module.label1.context}"
296+
context = module.label1.context
295297
name = "Charlie"
296298
stage = "test"
297299
delimiter = "+"
@@ -306,7 +308,7 @@ module "label3" {
306308
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=master"
307309
name = "Starfish"
308310
stage = "release"
309-
context = "${module.label1.context}"
311+
context = module.label1.context
310312
delimiter = "."
311313
312314
tags = {
@@ -320,82 +322,163 @@ This creates label outputs like this:
320322

321323
```hcl
322324
label1 = {
323-
attributes = [fire water earth air]
324-
id = winstonchurchroom-uat-build-fire-water-earth-air
325-
name = winstonchurchroom
326-
namespace = cloudposse
327-
stage = build
325+
"attributes" = [
326+
"fire",
327+
"water",
328+
"earth",
329+
"air",
330+
]
331+
"delimiter" = "-"
332+
"id" = "winstonchurchroom-uat-build-fire-water-earth-air"
333+
"name" = "winstonchurchroom"
334+
"namespace" = "cloudposse"
335+
"stage" = "build"
328336
}
329337
label1_context = {
330-
attributes = [fire water earth air]
331-
delimiter = [-]
332-
environment = [uat]
333-
label_order = [name environment stage attributes]
334-
name = [winstonchurchroom]
335-
namespace = [cloudposse]
336-
stage = [build]
337-
tags_keys = [City Environment Name Namespace Stage]
338-
tags_values = [Dublin Private winstonchurchroom-uat-build-fire-water-earth-air cloudposse build]
338+
"additional_tag_map" = {}
339+
"attributes" = [
340+
"fire",
341+
"water",
342+
"earth",
343+
"air",
344+
]
345+
"delimiter" = "-"
346+
"enabled" = true
347+
"environment" = "uat"
348+
"label_order" = [
349+
"name",
350+
"environment",
351+
"stage",
352+
"attributes",
353+
]
354+
"name" = "winstonchurchroom"
355+
"namespace" = "cloudposse"
356+
"regex_replace_chars" = "/[^a-zA-Z0-9-]/"
357+
"stage" = "build"
358+
"tags" = {
359+
"Attributes" = "fire-water-earth-air"
360+
"City" = "Dublin"
361+
"Environment" = "Private"
362+
"Name" = "winstonchurchroom"
363+
"Namespace" = "cloudposse"
364+
"Stage" = "build"
365+
}
339366
}
340367
label1_tags = {
341-
City = Dublin
342-
Environment = Private
343-
Name = winstonchurchroom-uat-build-fire-water-earth-air
344-
Namespace = cloudposse
345-
Stage = build
368+
"Attributes" = "fire-water-earth-air"
369+
"City" = "Dublin"
370+
"Environment" = "Private"
371+
"Name" = "winstonchurchroom"
372+
"Namespace" = "cloudposse"
373+
"Stage" = "build"
346374
}
347375
label2 = {
348-
attributes = [fire water earth air]
349-
id = charlie+uat+test+fire+water+earth+air
350-
name = charlie
351-
namespace = cloudposse
352-
stage = test
376+
"attributes" = [
377+
"fire",
378+
"water",
379+
"earth",
380+
"air",
381+
]
382+
"delimiter" = "+"
383+
"id" = "charlie+uat+test+firewaterearthair"
384+
"name" = "charlie"
385+
"namespace" = "cloudposse"
386+
"stage" = "test"
353387
}
354388
label2_context = {
355-
attributes = [fire water earth air]
356-
delimiter = [+]
357-
environment = [uat]
358-
label_order = [name environment stage attributes]
359-
name = [charlie]
360-
namespace = [cloudposse]
361-
stage = [test]
362-
tags_keys = [City Environment Name Namespace Stage]
363-
tags_values = [London Public charlie+uat+test+fire+water+earth+air cloudposse test]
389+
"additional_tag_map" = {}
390+
"attributes" = [
391+
"fire",
392+
"water",
393+
"earth",
394+
"air",
395+
]
396+
"delimiter" = "+"
397+
"enabled" = true
398+
"environment" = "uat"
399+
"label_order" = [
400+
"name",
401+
"environment",
402+
"stage",
403+
"attributes",
404+
]
405+
"name" = "charlie"
406+
"namespace" = "cloudposse"
407+
"regex_replace_chars" = "/[^a-zA-Z0-9-]/"
408+
"stage" = "test"
409+
"tags" = {
410+
"Attributes" = "firewaterearthair"
411+
"City" = "London"
412+
"Environment" = "Public"
413+
"Name" = "charlie"
414+
"Namespace" = "cloudposse"
415+
"Stage" = "test"
416+
}
364417
}
365418
label2_tags = {
366-
City = London
367-
Environment = Public
368-
Name = charlie+uat+test+fire+water+earth+air
369-
Namespace = cloudposse
370-
Stage = test
419+
"Attributes" = "firewaterearthair"
420+
"City" = "London"
421+
"Environment" = "Public"
422+
"Name" = "charlie"
423+
"Namespace" = "cloudposse"
424+
"Stage" = "test"
371425
}
372426
label3 = {
373-
attributes = [fire water earth air]
374-
id = starfish.uat.release.fire.water.earth.air
375-
name = starfish
376-
namespace = cloudposse
377-
stage = release
427+
"attributes" = [
428+
"fire",
429+
"water",
430+
"earth",
431+
"air",
432+
]
433+
"delimiter" = "."
434+
"id" = "starfish.uat.release.firewaterearthair"
435+
"name" = "starfish"
436+
"namespace" = "cloudposse"
437+
"stage" = "release"
378438
}
379439
label3_context = {
380-
attributes = [fire water earth air]
381-
delimiter = [.]
382-
environment = [uat]
383-
label_order = [name environment stage attributes]
384-
name = [starfish]
385-
namespace = [cloudposse]
386-
stage = [release]
387-
tags_keys = [Animal City Eat Environment Name Namespace Stage]
388-
tags_values = [Rabbit Dublin Carrot uat starfish.uat.release.fire.water.earth.air cloudposse release]
440+
"additional_tag_map" = {}
441+
"attributes" = [
442+
"fire",
443+
"water",
444+
"earth",
445+
"air",
446+
]
447+
"delimiter" = "."
448+
"enabled" = true
449+
"environment" = "uat"
450+
"label_order" = [
451+
"name",
452+
"environment",
453+
"stage",
454+
"attributes",
455+
]
456+
"name" = "starfish"
457+
"namespace" = "cloudposse"
458+
"regex_replace_chars" = "/[^a-zA-Z0-9-]/"
459+
"stage" = "release"
460+
"tags" = {
461+
"Animal" = "Rabbit"
462+
"Attributes" = "firewaterearthair"
463+
"City" = "Dublin"
464+
"Eat" = "Carrot"
465+
"Environment" = "uat"
466+
"Name" = "starfish"
467+
"Namespace" = "cloudposse"
468+
"Stage" = "release"
469+
}
389470
}
390471
label3_tags = {
391-
Animal = Rabbit
392-
City = Dublin
393-
Eat = Carrot
394-
Environment = uat
395-
Name = starfish.uat.release.fire.water.earth.air
396-
Namespace = cloudposse
397-
Stage = release
472+
"Animal" = "Rabbit"
473+
"Attributes" = "firewaterearthair"
474+
"City" = "Dublin"
475+
"Eat" = "Carrot"
476+
"Environment" = "uat"
477+
"Name" = "starfish"
478+
"Namespace" = "cloudposse"
479+
"Stage" = "release"
398480
}
481+
399482
```
400483

401484

@@ -417,18 +500,18 @@ Available targets:
417500

418501
| Name | Description | Type | Default | Required |
419502
|------|-------------|:----:|:-----:|:-----:|
420-
| additional_tag_map | Additional tags for appending to each tag map | map | `<map>` | no |
421-
| attributes | Additional attributes (e.g. `1`) | list | `<list>` | no |
422-
| context | Default context to use for passing state between label invocations | map | `<map>` | no |
503+
| additional_tag_map | Additional tags for appending to each tag map | map(string) | `<map>` | no |
504+
| attributes | Additional attributes (e.g. `1`) | list(string) | `<list>` | no |
505+
| context | Default context to use for passing state between label invocations | object | `<map>` | no |
423506
| delimiter | Delimiter to be used between `namespace`, `environment`, `stage`, `name` and `attributes` | string | `-` | no |
424-
| enabled | Set to false to prevent the module from creating any resources | string | `true` | no |
507+
| enabled | Set to false to prevent the module from creating any resources | bool | `true` | no |
425508
| environment | Environment, e.g. 'prod', 'staging', 'dev', 'pre-prod', 'UAT' | string | `` | no |
426-
| label_order | The naming order of the id output and Name tag | list | `<list>` | no |
509+
| label_order | The naming order of the id output and Name tag | list(string) | `<list>` | no |
427510
| name | Solution name, e.g. 'app' or 'jenkins' | string | `` | no |
428511
| namespace | Namespace, which could be your organization name or abbreviation, e.g. 'eg' or 'cp' | string | `` | no |
429512
| regex_replace_chars | Regex to replace chars with empty string in `namespace`, `environment`, `stage` and `name`. By default only hyphens, letters and digits are allowed, all other chars are removed | string | `/[^a-zA-Z0-9-]/` | no |
430513
| stage | Stage, e.g. 'prod', 'staging', 'dev', OR 'source', 'build', 'test', 'deploy', 'release' | string | `` | no |
431-
| tags | Additional tags (e.g. `map('BusinessUnit','XYZ')` | map | `<map>` | no |
514+
| tags | Additional tags (e.g. `map('BusinessUnit','XYZ')` | map(string) | `<map>` | no |
432515

433516
## Outputs
434517

0 commit comments

Comments
 (0)