Skip to content

Commit

Permalink
docs: Add multiple target groups with for loop pattern (#327)
Browse files Browse the repository at this point in the history
Co-authored-by: Bryant Biggs <[email protected]>
  • Loading branch information
rdhar and bryantbiggs authored Dec 11, 2023
1 parent 6b4073c commit a1a54c5
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions docs/patterns.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,3 +317,41 @@ module "alb" {
}
}
```

### Multiple Target Groups with For Loop

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.

```hcl
local {
services = {
blue = {
path = "/"
port = 80
}
green = {
path = "/"
port = 80
}
}
}
module "alb" {
source = "terraform-aws-modules/alb/aws"
# Truncated for brevity ...
target_groups = {
for key, value in local.services : key => {
name = key
port = value.port
target_type = "ip"
create_attachment = false
health_check = {
path = value.path
}
}
}
}
```

0 comments on commit a1a54c5

Please sign in to comment.