diff --git a/wrappers/README.md b/wrappers/README.md new file mode 100644 index 00000000..9100f135 --- /dev/null +++ b/wrappers/README.md @@ -0,0 +1,106 @@ +# 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 = "tfr:///terraform-aws-modules/lambda/aws//wrappers" + # Alternative source: + # source = "git::git@github.com:terraform-aws-modules/terraform-aws-lambda.git//wrappers?ref=master" +} + +inputs = { + defaults = { # Default values + create = true + handler = "index.lambda_handler" + runtime = "python3.8" + tags = { + Terraform = "true" + Environment = "dev" + } + } + + 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/lambda/aws//wrappers" + + defaults = { # Default values + create = true + handler = "index.lambda_handler" + runtime = "python3.8" + tags = { + Terraform = "true" + Environment = "dev" + } + } + + 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 Lambdas in one Terragrunt layer + +`eu-west-1/lambdas/terragrunt.hcl`: + +```hcl +terraform { + source = "tfr:///terraform-aws-modules/lambda/aws//wrappers" + # Alternative source: + # source = "git::git@github.com:terraform-aws-modules/terraform-aws-lambda.git//wrappers?ref=master" +} + +inputs = { + defaults = { + create = true + handler = "index.lambda_handler" + runtime = "python3.8" + tags = { + Terraform = "true" + Environment = "dev" + } + } + + items = { + lambda1 = { + function_name = "my-lambda1" + description = "My awesome lambda function"\ + source_path = "../src/lambda-function1" + } + lambda2 = { + function_name = "my-lambda2" + description = "My second awesome lambda function" + source_path = "../src/lambda-function2" + } + } +} +``` diff --git a/wrappers/alias/README.md b/wrappers/alias/README.md new file mode 100644 index 00000000..3f2b5013 --- /dev/null +++ b/wrappers/alias/README.md @@ -0,0 +1,103 @@ +# Wrapper for module: `modules/alias` + +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 = "tfr:///terraform-aws-modules/lambda/aws" + # Alternative source: + # source = "git::git@github.com:terraform-aws-modules/terraform-aws-lambda.git//wrappers/alias?ref=master" +} + +inputs = { + defaults = { # Default values + create = true + refresh_alias = true + } + + 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/lambda/aws//wrappers/alias" + + defaults = { # Default values + create = true + refresh_alias = true + } + + 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 aliases in one Terragrunt layer + +`eu-west-1/lambda-aliases/terragrunt.hcl`: + +```hcl +terraform { + source = "tfr:///terraform-aws-modules/lambda/aws//wrappers/alias" + # Alternative source: + # source = "git::git@github.com:terraform-aws-modules/terraform-aws-lambda.git//wrappers/alias?ref=master" +} + +dependency "lambda1" { + config_path = "../lambdas/lambda1" +} +dependency "lambda2" { + config_path = "../lambdas/lambda2" +} + +inputs = { + defaults = { + refresh_alias = true + allowed_triggers = { + AnotherAPIGatewayAny = { + service = "apigateway" + source_arn = "arn:aws:execute-api:eu-west-1:135367859851:abcdedfgse/*/*/*" + } + } + } + + items = { + alias1 = { + name = "my-random-alias-1" + function_name = dependency.lambda1.outputs.lambda_function_name + function_version = dependency.lambda1.outputs.lambda_function_version + } + alias2 = { + name = "my-random-alias-2" + function_name = dependency.lambda2.outputs.lambda_function_name + function_version = dependency.lambda2.outputs.lambda_function_version + } + } +} +``` diff --git a/wrappers/alias/main.tf b/wrappers/alias/main.tf new file mode 100644 index 00000000..983e3797 --- /dev/null +++ b/wrappers/alias/main.tf @@ -0,0 +1,26 @@ +module "wrapper" { + source = "../../modules/alias" + + for_each = var.items + + create = try(each.value.create, var.defaults.create, true) + use_existing_alias = try(each.value.use_existing_alias, var.defaults.use_existing_alias, false) + refresh_alias = try(each.value.refresh_alias, var.defaults.refresh_alias, true) + create_async_event_config = try(each.value.create_async_event_config, var.defaults.create_async_event_config, false) + create_version_async_event_config = try(each.value.create_version_async_event_config, var.defaults.create_version_async_event_config, true) + create_qualified_alias_async_event_config = try(each.value.create_qualified_alias_async_event_config, var.defaults.create_qualified_alias_async_event_config, true) + create_version_allowed_triggers = try(each.value.create_version_allowed_triggers, var.defaults.create_version_allowed_triggers, true) + create_qualified_alias_allowed_triggers = try(each.value.create_qualified_alias_allowed_triggers, var.defaults.create_qualified_alias_allowed_triggers, true) + name = try(each.value.name, var.defaults.name, null) + description = try(each.value.description, var.defaults.description, null) + function_name = try(each.value.function_name, var.defaults.function_name, null) + function_version = try(each.value.function_version, var.defaults.function_version, null) + routing_additional_version_weights = try(each.value.routing_additional_version_weights, var.defaults.routing_additional_version_weights, {}) + maximum_event_age_in_seconds = try(each.value.maximum_event_age_in_seconds, var.defaults.maximum_event_age_in_seconds, null) + maximum_retry_attempts = try(each.value.maximum_retry_attempts, var.defaults.maximum_retry_attempts, null) + destination_on_failure = try(each.value.destination_on_failure, var.defaults.destination_on_failure, null) + destination_on_success = try(each.value.destination_on_success, var.defaults.destination_on_success, null) + allowed_triggers = try(each.value.allowed_triggers, var.defaults.allowed_triggers, {}) + event_source_mapping = try(each.value.event_source_mapping, var.defaults.event_source_mapping, {}) + +} diff --git a/wrappers/alias/outputs.tf b/wrappers/alias/outputs.tf new file mode 100644 index 00000000..ec6da5f4 --- /dev/null +++ b/wrappers/alias/outputs.tf @@ -0,0 +1,5 @@ +output "wrapper" { + description = "Map of outputs of a wrapper." + value = module.wrapper + # sensitive = false # No sensitive module output found +} diff --git a/wrappers/alias/variables.tf b/wrappers/alias/variables.tf new file mode 100644 index 00000000..a6ea0962 --- /dev/null +++ b/wrappers/alias/variables.tf @@ -0,0 +1,11 @@ +variable "defaults" { + description = "Map of default values which will be used for each item." + type = any + default = {} +} + +variable "items" { + description = "Maps of items to create a wrapper from. Values are passed through to the module." + type = any + default = {} +} diff --git a/wrappers/alias/versions.tf b/wrappers/alias/versions.tf new file mode 100644 index 00000000..6b6318de --- /dev/null +++ b/wrappers/alias/versions.tf @@ -0,0 +1,3 @@ +terraform { + required_version = ">= 0.13" +} diff --git a/wrappers/deploy/README.md b/wrappers/deploy/README.md new file mode 100644 index 00000000..699ae062 --- /dev/null +++ b/wrappers/deploy/README.md @@ -0,0 +1,134 @@ +# Wrapper for module: `modules/deploy` + +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 = "tfr:///terraform-aws-modules/lambda/aws//wrappers/deploy" + # Alternative source: + # source = "git::git@github.com:terraform-aws-modules/terraform-aws-lambda.git//wrappers/deploy?ref=master" +} + +inputs = { + defaults = { # Default values + create_app = true + tags = { + Terraform = "true" + Environment = "dev" + } + } + + 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/lambda/aws//wrappers/deploy" + + defaults = { # Default values + create_app = true + tags = { + Terraform = "true" + Environment = "dev" + } + } + + 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 deployment via AWS CodeDeploy in one Terragrunt layer + +`eu-west-1/lambda-deploys/terragrunt.hcl`: + +```hcl +terraform { + source = "tfr:///terraform-aws-modules/lambda/aws//wrappers/deploy" + # Alternative source: + # source = "git::git@github.com:terraform-aws-modules/terraform-aws-lambda.git//wrappers/deploy?ref=master" +} + +dependency "aliases" { + config_path = "../lambdas-aliases/" +} +dependency "lambda1" { + config_path = "../lambdas/lambda1" +} +dependency "lambda2" { + config_path = "../lambdas/lambda2" +} + +inputs = { + defaults = { + create_app = true + reate_deployment_group = true + create_deployment = true + run_deployment = true + wait_deployment_completion = true + + triggers = { + start = { + events = ["DeploymentStart"] + name = "DeploymentStart" + target_arn = "arn:aws:sns:eu-west-1:135367859851:sns1" + } + success = { + events = ["DeploymentSuccess"] + name = "DeploymentSuccess" + target_arn = "arn:aws:sns:eu-west-1:135367859851:sns2" + } + } + + tags = { + Terraform = "true" + Environment = "dev" + } + } + + items = { + deploy1 = { + app_name = "my-random-app-1" + deployment_group_name = "something1" + + alias_name = dependency.aliases.outputs.wrapper.alias1.lambda_alias_name + function_name = dependency.lambda1.outputs.lambda_function_name + target_version = dependency.lambda1.outputs.lambda_function_version + } + deploy2 = { + app_name = "my-random-app-2" + deployment_group_name = "something2" + + alias_name = dependency.aliases.outputs.wrapper.alias2.lambda_alias_name + function_name = dependency.lambda2.outputs.lambda_function_name + target_version = dependency.lambda2.outputs.lambda_function_version + } + } +} +``` diff --git a/wrappers/deploy/main.tf b/wrappers/deploy/main.tf new file mode 100644 index 00000000..cf6c773a --- /dev/null +++ b/wrappers/deploy/main.tf @@ -0,0 +1,41 @@ +module "wrapper" { + source = "../../modules/deploy" + + for_each = var.items + create = try(each.value.create, var.defaults.create, true) + tags = try(each.value.tags, var.defaults.tags, {}) + alias_name = try(each.value.alias_name, var.defaults.alias_name, null) + function_name = try(each.value.function_name, var.defaults.function_name, null) + current_version = try(each.value.current_version, var.defaults.current_version, null) + target_version = try(each.value.target_version, var.defaults.target_version, null) + before_allow_traffic_hook_arn = try(each.value.before_allow_traffic_hook_arn, var.defaults.before_allow_traffic_hook_arn, null) + after_allow_traffic_hook_arn = try(each.value.after_allow_traffic_hook_arn, var.defaults.after_allow_traffic_hook_arn, null) + interpreter = try(each.value.interpreter, var.defaults.interpreter, ["/bin/bash", "-c"]) + description = try(each.value.description, var.defaults.description, null) + create_app = try(each.value.create_app, var.defaults.create_app, false) + use_existing_app = try(each.value.use_existing_app, var.defaults.use_existing_app, false) + app_name = try(each.value.app_name, var.defaults.app_name, null) + create_deployment_group = try(each.value.create_deployment_group, var.defaults.create_deployment_group, false) + use_existing_deployment_group = try(each.value.use_existing_deployment_group, var.defaults.use_existing_deployment_group, false) + deployment_group_name = try(each.value.deployment_group_name, var.defaults.deployment_group_name, null) + deployment_config_name = try(each.value.deployment_config_name, var.defaults.deployment_config_name, "CodeDeployDefault.LambdaAllAtOnce") + auto_rollback_enabled = try(each.value.auto_rollback_enabled, var.defaults.auto_rollback_enabled, true) + auto_rollback_events = try(each.value.auto_rollback_events, var.defaults.auto_rollback_events, ["DEPLOYMENT_STOP_ON_ALARM"]) + alarm_enabled = try(each.value.alarm_enabled, var.defaults.alarm_enabled, false) + alarms = try(each.value.alarms, var.defaults.alarms, []) + alarm_ignore_poll_alarm_failure = try(each.value.alarm_ignore_poll_alarm_failure, var.defaults.alarm_ignore_poll_alarm_failure, false) + triggers = try(each.value.triggers, var.defaults.triggers, {}) + aws_cli_command = try(each.value.aws_cli_command, var.defaults.aws_cli_command, "aws") + save_deploy_script = try(each.value.save_deploy_script, var.defaults.save_deploy_script, false) + create_deployment = try(each.value.create_deployment, var.defaults.create_deployment, false) + run_deployment = try(each.value.run_deployment, var.defaults.run_deployment, false) + force_deploy = try(each.value.force_deploy, var.defaults.force_deploy, false) + wait_deployment_completion = try(each.value.wait_deployment_completion, var.defaults.wait_deployment_completion, false) + create_codedeploy_role = try(each.value.create_codedeploy_role, var.defaults.create_codedeploy_role, true) + codedeploy_role_name = try(each.value.codedeploy_role_name, var.defaults.codedeploy_role_name, null) + codedeploy_principals = try(each.value.codedeploy_principals, var.defaults.codedeploy_principals, ["codedeploy.amazonaws.com"]) + attach_hooks_policy = try(each.value.attach_hooks_policy, var.defaults.attach_hooks_policy, true) + attach_triggers_policy = try(each.value.attach_triggers_policy, var.defaults.attach_triggers_policy, false) + get_deployment_sleep_timer = try(each.value.get_deployment_sleep_timer, var.defaults.get_deployment_sleep_timer, 5) + +} diff --git a/wrappers/deploy/outputs.tf b/wrappers/deploy/outputs.tf new file mode 100644 index 00000000..ec6da5f4 --- /dev/null +++ b/wrappers/deploy/outputs.tf @@ -0,0 +1,5 @@ +output "wrapper" { + description = "Map of outputs of a wrapper." + value = module.wrapper + # sensitive = false # No sensitive module output found +} diff --git a/wrappers/deploy/variables.tf b/wrappers/deploy/variables.tf new file mode 100644 index 00000000..a6ea0962 --- /dev/null +++ b/wrappers/deploy/variables.tf @@ -0,0 +1,11 @@ +variable "defaults" { + description = "Map of default values which will be used for each item." + type = any + default = {} +} + +variable "items" { + description = "Maps of items to create a wrapper from. Values are passed through to the module." + type = any + default = {} +} diff --git a/wrappers/deploy/versions.tf b/wrappers/deploy/versions.tf new file mode 100644 index 00000000..6b6318de --- /dev/null +++ b/wrappers/deploy/versions.tf @@ -0,0 +1,3 @@ +terraform { + required_version = ">= 0.13" +} diff --git a/wrappers/docker-build/README.md b/wrappers/docker-build/README.md new file mode 100644 index 00000000..8d55dd6a --- /dev/null +++ b/wrappers/docker-build/README.md @@ -0,0 +1,109 @@ +# Wrapper for module: `modules/docker-build` + +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 = "tfr:///terraform-aws-modules/lambda/aws//wrappers/docker-build" + # Alternative source: + # source = "git::git@github.com:terraform-aws-modules/terraform-aws-lambda.git//wrappers/docker-build?ref=master" +} + +inputs = { + defaults = { # Default values + create_ecr_repo = true + } + + 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/lambda/aws//wrappers/docker-build" + + defaults = { # Default values + create_ecr_repo = true + } + + 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 Docker Container Image in one Terragrunt layer + +`eu-west-1/docker-builds/terragrunt.hcl`: + +```hcl +terraform { + source = "tfr:///terraform-aws-modules/lambda/aws//wrappers" + # Alternative source: + # source = "git::git@github.com:terraform-aws-modules/terraform-aws-lambda.git//wrappers?ref=master" +} + +# Generate an Docker provider block +generate "provider" { + path = "provider.tf" + if_exists = "overwrite" + contents = <