Commit 95bc9f7e authored by Anton Babenko's avatar Anton Babenko Committed by GitHub

feat: Add module wrappers (#92)

parent e5b3f1af
repos:
# - repo: local # @todo: move to pre-commit-terraform, add support for multiple module dirs, and run before terraform_docs
# hooks:
# - id: terraform_wrapper
# name: "Terraform module wrapper - root"
# entry: /Users/Bob/Sites/terraform-aws-modules/scripts/generate-terraform-wrappers.sh --overwrite
# language: system
# pass_filenames: false
# - id: terraform_wrapper
# name: "Terraform module wrapper - object"
# entry: /Users/Bob/Sites/terraform-aws-modules/scripts/generate-terraform-wrappers.sh --module-dir modules/object --overwrite
# language: system
# pass_filenames: false
# - id: terraform_wrapper
# name: "Terraform module wrapper - notification"
# entry: /Users/Bob/Sites/terraform-aws-modules/scripts/generate-terraform-wrappers.sh --module-dir modules/notification --overwrite
# language: system
# pass_filenames: false
- repo: git://github.com/antonbabenko/pre-commit-terraform
rev: v1.50.0
hooks:
......
# Wrapper for the root module
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).
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.
This wrapper does not implement any extra functionality.
# Usage with Terragrunt
`terragrunt.hcl`:
```hcl
terraform {
source = "git::git@github.com:terraform-aws-modules/terraform-aws-s3-bucket.git?ref=master//wrappers"
}
inputs = {
items = {
my-item = {
# omitted... can be any argument supported by the module
}
my-second-item = {
# omitted... can be any argument supported by the module
}
# omitted...
}
}
```
## Usage with Terraform:
```hcl
module "wrapper" {
source = "terraform-aws-modules/s3-bucket/aws//wrappers"
items = {
my-item = {
# omitted... can be any argument supported by the module
}
my-second-item = {
# omitted... can be any argument supported by the module
}
# omitted...
}
}
```
## Example: Manage multiple S3 buckets in one Terragrunt layer
`eu-west-1/s3-buckets/terragrunt.hcl`:
```hcl
terraform {
source = "git::git@github.com:terraform-aws-modules/terraform-aws-s3-bucket.git?ref=master//wrappers"
}
inputs = {
items = {
bucket1 = {
bucket = "my-random-bucket-1"
force_destroy = true
}
bucket2 = {
bucket = "my-random-bucket-2"
force_destroy = true
}
}
}
```
module "wrapper" {
source = "../"
for_each = var.items
create_bucket = lookup(each.value, "create_bucket", true)
attach_elb_log_delivery_policy = lookup(each.value, "attach_elb_log_delivery_policy", false)
attach_deny_insecure_transport_policy = lookup(each.value, "attach_deny_insecure_transport_policy", false)
attach_policy = lookup(each.value, "attach_policy", false)
attach_public_policy = lookup(each.value, "attach_public_policy", true)
bucket = lookup(each.value, "bucket", null)
bucket_prefix = lookup(each.value, "bucket_prefix", null)
acl = lookup(each.value, "acl", "private")
policy = lookup(each.value, "policy", null)
tags = lookup(each.value, "tags", {})
force_destroy = lookup(each.value, "force_destroy", false)
acceleration_status = lookup(each.value, "acceleration_status", null)
request_payer = lookup(each.value, "request_payer", null)
website = lookup(each.value, "website", {})
cors_rule = lookup(each.value, "cors_rule", [])
versioning = lookup(each.value, "versioning", {})
logging = lookup(each.value, "logging", {})
grant = lookup(each.value, "grant", [])
lifecycle_rule = lookup(each.value, "lifecycle_rule", [])
replication_configuration = lookup(each.value, "replication_configuration", {})
server_side_encryption_configuration = lookup(each.value, "server_side_encryption_configuration", {})
object_lock_configuration = lookup(each.value, "object_lock_configuration", {})
block_public_acls = lookup(each.value, "block_public_acls", false)
block_public_policy = lookup(each.value, "block_public_policy", false)
ignore_public_acls = lookup(each.value, "ignore_public_acls", false)
restrict_public_buckets = lookup(each.value, "restrict_public_buckets", false)
}
# Wrapper for module: `modules/notification`
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).
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.
This wrapper does not implement any extra functionality.
# Usage with Terragrunt
`terragrunt.hcl`:
```hcl
terraform {
source = "git::git@github.com:terraform-aws-modules/terraform-aws-s3-bucket.git?ref=master//wrappers/notification"
}
inputs = {
items = {
my-item = {
# omitted... can be any argument supported by the module
}
my-second-item = {
# omitted... can be any argument supported by the module
}
# omitted...
}
}
```
## Usage with Terraform:
```hcl
module "wrapper" {
source = "terraform-aws-modules/s3-bucket/aws//wrappers/notification"
items = {
my-item = {
# omitted... can be any argument supported by the module
}
my-second-item = {
# omitted... can be any argument supported by the module
}
# omitted...
}
}
```
## Example: Manage multiple S3 buckets in one Terragrunt layer
`eu-west-1/s3-buckets/terragrunt.hcl`:
```hcl
terraform {
source = "git::git@github.com:terraform-aws-modules/terraform-aws-s3-bucket.git?ref=master//wrappers"
}
inputs = {
items = {
bucket1 = {
bucket = "my-random-bucket-1"
force_destroy = true
}
bucket2 = {
bucket = "my-random-bucket-2"
force_destroy = true
}
}
}
```
module "wrapper" {
source = "../../modules/notification"
for_each = var.items
create = lookup(each.value, "create", true)
create_sns_policy = lookup(each.value, "create_sns_policy", true)
create_sqs_policy = lookup(each.value, "create_sqs_policy", true)
bucket = lookup(each.value, "bucket", "")
bucket_arn = lookup(each.value, "bucket_arn", null)
lambda_notifications = lookup(each.value, "lambda_notifications", {})
sqs_notifications = lookup(each.value, "sqs_notifications", {})
sns_notifications = lookup(each.value, "sns_notifications", {})
}
output "wrapper" {
description = "Map of outputs of a wrapper."
value = module.wrapper
}
variable "items" {
description = "Maps of items to create a wrapper from. Values are passed through to the module."
type = any
default = {}
}
terraform {
required_version = ">= 0.13"
}
# Wrapper for module: `modules/object`
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).
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.
This wrapper does not implement any extra functionality.
# Usage with Terragrunt
`terragrunt.hcl`:
```hcl
terraform {
source = "git::git@github.com:terraform-aws-modules/terraform-aws-s3-bucket.git?ref=master//wrappers/object"
}
inputs = {
items = {
my-item = {
# omitted... can be any argument supported by the module
}
my-second-item = {
# omitted... can be any argument supported by the module
}
# omitted...
}
}
```
## Usage with Terraform:
```hcl
module "wrapper" {
source = "terraform-aws-modules/s3-bucket/aws//wrappers/object"
items = {
my-item = {
# omitted... can be any argument supported by the module
}
my-second-item = {
# omitted... can be any argument supported by the module
}
# omitted...
}
}
```
## Example: Manage multiple S3 buckets in one Terragrunt layer
`eu-west-1/s3-buckets/terragrunt.hcl`:
```hcl
terraform {
source = "git::git@github.com:terraform-aws-modules/terraform-aws-s3-bucket.git?ref=master//wrappers"
}
inputs = {
items = {
bucket1 = {
bucket = "my-random-bucket-1"
force_destroy = true
}
bucket2 = {
bucket = "my-random-bucket-2"
force_destroy = true
}
}
}
```
module "wrapper" {
source = "../../modules/object"
for_each = var.items
create = lookup(each.value, "create", true)
bucket = lookup(each.value, "bucket", "")
key = lookup(each.value, "key", "")
file_source = lookup(each.value, "file_source", null)
content = lookup(each.value, "content", null)
content_base64 = lookup(each.value, "content_base64", null)
acl = lookup(each.value, "acl", null)
cache_control = lookup(each.value, "cache_control", null)
content_disposition = lookup(each.value, "content_disposition", null)
content_encoding = lookup(each.value, "content_encoding", null)
content_language = lookup(each.value, "content_language", null)
content_type = lookup(each.value, "content_type", null)
website_redirect = lookup(each.value, "website_redirect", null)
storage_class = lookup(each.value, "storage_class", null)
etag = lookup(each.value, "etag", null)
server_side_encryption = lookup(each.value, "server_side_encryption", null)
kms_key_id = lookup(each.value, "kms_key_id", null)
bucket_key_enabled = lookup(each.value, "bucket_key_enabled", null)
metadata = lookup(each.value, "metadata", {})
tags = lookup(each.value, "tags", {})
force_destroy = lookup(each.value, "force_destroy", false)
object_lock_legal_hold_status = lookup(each.value, "object_lock_legal_hold_status", null)
object_lock_mode = lookup(each.value, "object_lock_mode", null)
object_lock_retain_until_date = lookup(each.value, "object_lock_retain_until_date", null)
}
output "wrapper" {
description = "Map of outputs of a wrapper."
value = module.wrapper
}
variable "items" {
description = "Maps of items to create a wrapper from. Values are passed through to the module."
type = any
default = {}
}
terraform {
required_version = ">= 0.13"
}
output "wrapper" {
description = "Map of outputs of a wrapper."
value = module.wrapper
}
variable "items" {
description = "Maps of items to create a wrapper from. Values are passed through to the module."
type = any
default = {}
}
terraform {
required_version = ">= 0.13"
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment