Skip to content

Commit 8500adb

Browse files
authored
feat: Added wrappers for all submodules (#333)
1 parent 43798ea commit 8500adb

File tree

296 files changed

+12570
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

296 files changed

+12570
-1
lines changed

.pre-commit-config.yaml

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@ repos:
33
rev: v1.96.1
44
hooks:
55
- id: terraform_fmt
6+
- id: terraform_wrapper_module_for_each
67
- id: terraform_docs
78
args:
89
- '--args=--lockfile=false'
910
- id: terraform_validate
10-
exclude: '^modules/_templates/[^/]+$'
11+
exclude: '^modules/_templates/[^/]+$|^wrappers/.+$'
1112
- repo: https://github.com/pre-commit/pre-commit-hooks
1213
rev: v5.0.0
1314
hooks:
1415
- id: check-merge-conflict
1516
- id: end-of-file-fixer
1617
- id: trailing-whitespace
18+
- id: mixed-line-ending
19+
args: [--fix=lf]

wrappers/README.md

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# Wrapper for the root module
2+
3+
The configuration in this directory contains an implementation of a single module wrapper pattern, which allows managing several copies of a module in places where using the native Terraform 0.13+ `for_each` feature is not feasible (e.g., with Terragrunt).
4+
5+
You may want to use a single Terragrunt configuration file to manage multiple resources without duplicating `terragrunt.hcl` files for each copy of the same module.
6+
7+
This wrapper does not implement any extra functionality.
8+
9+
## Usage with Terragrunt
10+
11+
`terragrunt.hcl`:
12+
13+
```hcl
14+
terraform {
15+
source = "tfr:///terraform-aws-modules/security-group/aws//wrappers"
16+
# Alternative source:
17+
# source = "git::[email protected]:terraform-aws-modules/terraform-aws-security-group.git//wrappers?ref=master"
18+
}
19+
20+
inputs = {
21+
defaults = { # Default values
22+
create = true
23+
tags = {
24+
Terraform = "true"
25+
Environment = "dev"
26+
}
27+
}
28+
29+
items = {
30+
my-item = {
31+
# omitted... can be any argument supported by the module
32+
}
33+
my-second-item = {
34+
# omitted... can be any argument supported by the module
35+
}
36+
# omitted...
37+
}
38+
}
39+
```
40+
41+
## Usage with Terraform
42+
43+
```hcl
44+
module "wrapper" {
45+
source = "terraform-aws-modules/security-group/aws//wrappers"
46+
47+
defaults = { # Default values
48+
create = true
49+
tags = {
50+
Terraform = "true"
51+
Environment = "dev"
52+
}
53+
}
54+
55+
items = {
56+
my-item = {
57+
# omitted... can be any argument supported by the module
58+
}
59+
my-second-item = {
60+
# omitted... can be any argument supported by the module
61+
}
62+
# omitted...
63+
}
64+
}
65+
```
66+
67+
## Example: Manage multiple S3 buckets in one Terragrunt layer
68+
69+
`eu-west-1/s3-buckets/terragrunt.hcl`:
70+
71+
```hcl
72+
terraform {
73+
source = "tfr:///terraform-aws-modules/s3-bucket/aws//wrappers"
74+
# Alternative source:
75+
# source = "git::[email protected]:terraform-aws-modules/terraform-aws-s3-bucket.git//wrappers?ref=master"
76+
}
77+
78+
inputs = {
79+
defaults = {
80+
force_destroy = true
81+
82+
attach_elb_log_delivery_policy = true
83+
attach_lb_log_delivery_policy = true
84+
attach_deny_insecure_transport_policy = true
85+
attach_require_latest_tls_policy = true
86+
}
87+
88+
items = {
89+
bucket1 = {
90+
bucket = "my-random-bucket-1"
91+
}
92+
bucket2 = {
93+
bucket = "my-random-bucket-2"
94+
tags = {
95+
Secure = "probably"
96+
}
97+
}
98+
}
99+
}
100+
```

wrappers/_templates/README.md

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# Wrapper for module: `modules/_templates`
2+
3+
The configuration in this directory contains an implementation of a single module wrapper pattern, which allows managing several copies of a module in places where using the native Terraform 0.13+ `for_each` feature is not feasible (e.g., with Terragrunt).
4+
5+
You may want to use a single Terragrunt configuration file to manage multiple resources without duplicating `terragrunt.hcl` files for each copy of the same module.
6+
7+
This wrapper does not implement any extra functionality.
8+
9+
## Usage with Terragrunt
10+
11+
`terragrunt.hcl`:
12+
13+
```hcl
14+
terraform {
15+
source = "tfr:///terraform-aws-modules/security-group/aws//wrappers/_templates"
16+
# Alternative source:
17+
# source = "git::[email protected]:terraform-aws-modules/terraform-aws-security-group.git//wrappers/_templates?ref=master"
18+
}
19+
20+
inputs = {
21+
defaults = { # Default values
22+
create = true
23+
tags = {
24+
Terraform = "true"
25+
Environment = "dev"
26+
}
27+
}
28+
29+
items = {
30+
my-item = {
31+
# omitted... can be any argument supported by the module
32+
}
33+
my-second-item = {
34+
# omitted... can be any argument supported by the module
35+
}
36+
# omitted...
37+
}
38+
}
39+
```
40+
41+
## Usage with Terraform
42+
43+
```hcl
44+
module "wrapper" {
45+
source = "terraform-aws-modules/security-group/aws//wrappers/_templates"
46+
47+
defaults = { # Default values
48+
create = true
49+
tags = {
50+
Terraform = "true"
51+
Environment = "dev"
52+
}
53+
}
54+
55+
items = {
56+
my-item = {
57+
# omitted... can be any argument supported by the module
58+
}
59+
my-second-item = {
60+
# omitted... can be any argument supported by the module
61+
}
62+
# omitted...
63+
}
64+
}
65+
```
66+
67+
## Example: Manage multiple S3 buckets in one Terragrunt layer
68+
69+
`eu-west-1/s3-buckets/terragrunt.hcl`:
70+
71+
```hcl
72+
terraform {
73+
source = "tfr:///terraform-aws-modules/s3-bucket/aws//wrappers"
74+
# Alternative source:
75+
# source = "git::[email protected]:terraform-aws-modules/terraform-aws-s3-bucket.git//wrappers?ref=master"
76+
}
77+
78+
inputs = {
79+
defaults = {
80+
force_destroy = true
81+
82+
attach_elb_log_delivery_policy = true
83+
attach_lb_log_delivery_policy = true
84+
attach_deny_insecure_transport_policy = true
85+
attach_require_latest_tls_policy = true
86+
}
87+
88+
items = {
89+
bucket1 = {
90+
bucket = "my-random-bucket-1"
91+
}
92+
bucket2 = {
93+
bucket = "my-random-bucket-2"
94+
tags = {
95+
Secure = "probably"
96+
}
97+
}
98+
}
99+
}
100+
```

wrappers/_templates/main.tf

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
module "wrapper" {
2+
source = "../../modules/_templates"
3+
4+
for_each = var.items
5+
6+
computed_egress_cidr_blocks = try(each.value.computed_egress_cidr_blocks, var.defaults.computed_egress_cidr_blocks, ["0.0.0.0/0"])
7+
computed_egress_ipv6_cidr_blocks = try(each.value.computed_egress_ipv6_cidr_blocks, var.defaults.computed_egress_ipv6_cidr_blocks, ["::/0"])
8+
computed_egress_prefix_list_ids = try(each.value.computed_egress_prefix_list_ids, var.defaults.computed_egress_prefix_list_ids, [])
9+
computed_egress_rules = try(each.value.computed_egress_rules, var.defaults.computed_egress_rules, [])
10+
computed_egress_with_cidr_blocks = try(each.value.computed_egress_with_cidr_blocks, var.defaults.computed_egress_with_cidr_blocks, [])
11+
computed_egress_with_ipv6_cidr_blocks = try(each.value.computed_egress_with_ipv6_cidr_blocks, var.defaults.computed_egress_with_ipv6_cidr_blocks, [])
12+
computed_egress_with_prefix_list_ids = try(each.value.computed_egress_with_prefix_list_ids, var.defaults.computed_egress_with_prefix_list_ids, [])
13+
computed_egress_with_self = try(each.value.computed_egress_with_self, var.defaults.computed_egress_with_self, [])
14+
computed_egress_with_source_security_group_id = try(each.value.computed_egress_with_source_security_group_id, var.defaults.computed_egress_with_source_security_group_id, [])
15+
computed_ingress_cidr_blocks = try(each.value.computed_ingress_cidr_blocks, var.defaults.computed_ingress_cidr_blocks, [])
16+
computed_ingress_ipv6_cidr_blocks = try(each.value.computed_ingress_ipv6_cidr_blocks, var.defaults.computed_ingress_ipv6_cidr_blocks, [])
17+
computed_ingress_prefix_list_ids = try(each.value.computed_ingress_prefix_list_ids, var.defaults.computed_ingress_prefix_list_ids, [])
18+
computed_ingress_rules = try(each.value.computed_ingress_rules, var.defaults.computed_ingress_rules, [])
19+
computed_ingress_with_cidr_blocks = try(each.value.computed_ingress_with_cidr_blocks, var.defaults.computed_ingress_with_cidr_blocks, [])
20+
computed_ingress_with_ipv6_cidr_blocks = try(each.value.computed_ingress_with_ipv6_cidr_blocks, var.defaults.computed_ingress_with_ipv6_cidr_blocks, [])
21+
computed_ingress_with_prefix_list_ids = try(each.value.computed_ingress_with_prefix_list_ids, var.defaults.computed_ingress_with_prefix_list_ids, [])
22+
computed_ingress_with_self = try(each.value.computed_ingress_with_self, var.defaults.computed_ingress_with_self, [])
23+
computed_ingress_with_source_security_group_id = try(each.value.computed_ingress_with_source_security_group_id, var.defaults.computed_ingress_with_source_security_group_id, [])
24+
create = try(each.value.create, var.defaults.create, true)
25+
description = try(each.value.description, var.defaults.description, "Security Group managed by Terraform")
26+
egress_cidr_blocks = try(each.value.egress_cidr_blocks, var.defaults.egress_cidr_blocks, ["0.0.0.0/0"])
27+
egress_ipv6_cidr_blocks = try(each.value.egress_ipv6_cidr_blocks, var.defaults.egress_ipv6_cidr_blocks, ["::/0"])
28+
egress_prefix_list_ids = try(each.value.egress_prefix_list_ids, var.defaults.egress_prefix_list_ids, [])
29+
egress_rules = try(each.value.egress_rules, var.defaults.egress_rules, [])
30+
egress_with_cidr_blocks = try(each.value.egress_with_cidr_blocks, var.defaults.egress_with_cidr_blocks, [])
31+
egress_with_ipv6_cidr_blocks = try(each.value.egress_with_ipv6_cidr_blocks, var.defaults.egress_with_ipv6_cidr_blocks, [])
32+
egress_with_prefix_list_ids = try(each.value.egress_with_prefix_list_ids, var.defaults.egress_with_prefix_list_ids, [])
33+
egress_with_self = try(each.value.egress_with_self, var.defaults.egress_with_self, [])
34+
egress_with_source_security_group_id = try(each.value.egress_with_source_security_group_id, var.defaults.egress_with_source_security_group_id, [])
35+
ingress_cidr_blocks = try(each.value.ingress_cidr_blocks, var.defaults.ingress_cidr_blocks, [])
36+
ingress_ipv6_cidr_blocks = try(each.value.ingress_ipv6_cidr_blocks, var.defaults.ingress_ipv6_cidr_blocks, [])
37+
ingress_prefix_list_ids = try(each.value.ingress_prefix_list_ids, var.defaults.ingress_prefix_list_ids, [])
38+
ingress_rules = try(each.value.ingress_rules, var.defaults.ingress_rules, [])
39+
ingress_with_cidr_blocks = try(each.value.ingress_with_cidr_blocks, var.defaults.ingress_with_cidr_blocks, [])
40+
ingress_with_ipv6_cidr_blocks = try(each.value.ingress_with_ipv6_cidr_blocks, var.defaults.ingress_with_ipv6_cidr_blocks, [])
41+
ingress_with_prefix_list_ids = try(each.value.ingress_with_prefix_list_ids, var.defaults.ingress_with_prefix_list_ids, [])
42+
ingress_with_self = try(each.value.ingress_with_self, var.defaults.ingress_with_self, [])
43+
ingress_with_source_security_group_id = try(each.value.ingress_with_source_security_group_id, var.defaults.ingress_with_source_security_group_id, [])
44+
name = try(each.value.name, var.defaults.name)
45+
number_of_computed_egress_cidr_blocks = try(each.value.number_of_computed_egress_cidr_blocks, var.defaults.number_of_computed_egress_cidr_blocks, 0)
46+
number_of_computed_egress_ipv6_cidr_blocks = try(each.value.number_of_computed_egress_ipv6_cidr_blocks, var.defaults.number_of_computed_egress_ipv6_cidr_blocks, 0)
47+
number_of_computed_egress_prefix_list_ids = try(each.value.number_of_computed_egress_prefix_list_ids, var.defaults.number_of_computed_egress_prefix_list_ids, 0)
48+
number_of_computed_egress_rules = try(each.value.number_of_computed_egress_rules, var.defaults.number_of_computed_egress_rules, 0)
49+
number_of_computed_egress_with_cidr_blocks = try(each.value.number_of_computed_egress_with_cidr_blocks, var.defaults.number_of_computed_egress_with_cidr_blocks, 0)
50+
number_of_computed_egress_with_ipv6_cidr_blocks = try(each.value.number_of_computed_egress_with_ipv6_cidr_blocks, var.defaults.number_of_computed_egress_with_ipv6_cidr_blocks, 0)
51+
number_of_computed_egress_with_prefix_list_ids = try(each.value.number_of_computed_egress_with_prefix_list_ids, var.defaults.number_of_computed_egress_with_prefix_list_ids, 0)
52+
number_of_computed_egress_with_self = try(each.value.number_of_computed_egress_with_self, var.defaults.number_of_computed_egress_with_self, 0)
53+
number_of_computed_egress_with_source_security_group_id = try(each.value.number_of_computed_egress_with_source_security_group_id, var.defaults.number_of_computed_egress_with_source_security_group_id, 0)
54+
number_of_computed_ingress_cidr_blocks = try(each.value.number_of_computed_ingress_cidr_blocks, var.defaults.number_of_computed_ingress_cidr_blocks, 0)
55+
number_of_computed_ingress_ipv6_cidr_blocks = try(each.value.number_of_computed_ingress_ipv6_cidr_blocks, var.defaults.number_of_computed_ingress_ipv6_cidr_blocks, 0)
56+
number_of_computed_ingress_prefix_list_ids = try(each.value.number_of_computed_ingress_prefix_list_ids, var.defaults.number_of_computed_ingress_prefix_list_ids, 0)
57+
number_of_computed_ingress_rules = try(each.value.number_of_computed_ingress_rules, var.defaults.number_of_computed_ingress_rules, 0)
58+
number_of_computed_ingress_with_cidr_blocks = try(each.value.number_of_computed_ingress_with_cidr_blocks, var.defaults.number_of_computed_ingress_with_cidr_blocks, 0)
59+
number_of_computed_ingress_with_ipv6_cidr_blocks = try(each.value.number_of_computed_ingress_with_ipv6_cidr_blocks, var.defaults.number_of_computed_ingress_with_ipv6_cidr_blocks, 0)
60+
number_of_computed_ingress_with_prefix_list_ids = try(each.value.number_of_computed_ingress_with_prefix_list_ids, var.defaults.number_of_computed_ingress_with_prefix_list_ids, 0)
61+
number_of_computed_ingress_with_self = try(each.value.number_of_computed_ingress_with_self, var.defaults.number_of_computed_ingress_with_self, 0)
62+
number_of_computed_ingress_with_source_security_group_id = try(each.value.number_of_computed_ingress_with_source_security_group_id, var.defaults.number_of_computed_ingress_with_source_security_group_id, 0)
63+
revoke_rules_on_delete = try(each.value.revoke_rules_on_delete, var.defaults.revoke_rules_on_delete, false)
64+
tags = try(each.value.tags, var.defaults.tags, {})
65+
use_name_prefix = try(each.value.use_name_prefix, var.defaults.use_name_prefix, true)
66+
vpc_id = try(each.value.vpc_id, var.defaults.vpc_id)
67+
}

wrappers/_templates/outputs.tf

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
output "wrapper" {
2+
description = "Map of outputs of a wrapper."
3+
value = module.wrapper
4+
# sensitive = false # No sensitive module output found
5+
}

wrappers/_templates/variables.tf

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
variable "defaults" {
2+
description = "Map of default values which will be used for each item."
3+
type = any
4+
default = {}
5+
}
6+
7+
variable "items" {
8+
description = "Maps of items to create a wrapper from. Values are passed through to the module."
9+
type = any
10+
default = {}
11+
}

wrappers/_templates/versions.tf

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
terraform {
2+
required_version = ">= 1.0"
3+
4+
required_providers {
5+
aws = {
6+
source = "hashicorp/aws"
7+
version = ">= 3.29"
8+
}
9+
}
10+
}

0 commit comments

Comments
 (0)