Skip to content

Commit a1a54c5

Browse files
rdharbryantbiggs
andauthored
docs: Add multiple target groups with for loop pattern (#327)
Co-authored-by: Bryant Biggs <[email protected]>
1 parent 6b4073c commit a1a54c5

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

docs/patterns.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,3 +317,41 @@ module "alb" {
317317
}
318318
}
319319
```
320+
321+
### Multiple Target Groups with For Loop
322+
323+
The configuration snippet below creates two target groups using a for loop. This is useful to provision multiple different target groups with similar configurations at scale. The for loop will iterate over the `local.services` map definition and create corresponding `target_groups` map with the same key names and associated values.
324+
325+
```hcl
326+
local {
327+
services = {
328+
blue = {
329+
path = "/"
330+
port = 80
331+
}
332+
green = {
333+
path = "/"
334+
port = 80
335+
}
336+
}
337+
}
338+
339+
module "alb" {
340+
source = "terraform-aws-modules/alb/aws"
341+
342+
# Truncated for brevity ...
343+
344+
target_groups = {
345+
for key, value in local.services : key => {
346+
name = key
347+
port = value.port
348+
target_type = "ip"
349+
create_attachment = false
350+
351+
health_check = {
352+
path = value.path
353+
}
354+
}
355+
}
356+
}
357+
```

0 commit comments

Comments
 (0)