|
| 1 | +# Wrapper for module: `modules/deploy` |
| 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/lambda/aws//wrappers/deploy" |
| 16 | + # Alternative source: |
| 17 | + # source = "git::git@github.com:terraform-aws-modules/terraform-aws-lambda.git//wrappers/deploy?ref=master" |
| 18 | +} |
| 19 | +
|
| 20 | +inputs = { |
| 21 | + defaults = { # Default values |
| 22 | + create_app = 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/lambda/aws//wrappers/deploy" |
| 46 | +
|
| 47 | + defaults = { # Default values |
| 48 | + create_app = 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 deployment via AWS CodeDeploy in one Terragrunt layer |
| 68 | + |
| 69 | +`eu-west-1/lambda-deploys/terragrunt.hcl`: |
| 70 | + |
| 71 | +```hcl |
| 72 | +terraform { |
| 73 | + source = "tfr:///terraform-aws-modules/lambda/aws//wrappers/deploy" |
| 74 | + # Alternative source: |
| 75 | + # source = "git::git@github.com:terraform-aws-modules/terraform-aws-lambda.git//wrappers/deploy?ref=master" |
| 76 | +} |
| 77 | +
|
| 78 | +dependency "aliases" { |
| 79 | + config_path = "../lambdas-aliases/" |
| 80 | +} |
| 81 | +dependency "lambda1" { |
| 82 | + config_path = "../lambdas/lambda1" |
| 83 | +} |
| 84 | +dependency "lambda2" { |
| 85 | + config_path = "../lambdas/lambda2" |
| 86 | +} |
| 87 | +
|
| 88 | +inputs = { |
| 89 | + defaults = { |
| 90 | + create_app = true |
| 91 | + reate_deployment_group = true |
| 92 | + create_deployment = true |
| 93 | + run_deployment = true |
| 94 | + wait_deployment_completion = true |
| 95 | +
|
| 96 | + triggers = { |
| 97 | + start = { |
| 98 | + events = ["DeploymentStart"] |
| 99 | + name = "DeploymentStart" |
| 100 | + target_arn = "arn:aws:sns:eu-west-1:135367859851:sns1" |
| 101 | + } |
| 102 | + success = { |
| 103 | + events = ["DeploymentSuccess"] |
| 104 | + name = "DeploymentSuccess" |
| 105 | + target_arn = "arn:aws:sns:eu-west-1:135367859851:sns2" |
| 106 | + } |
| 107 | + } |
| 108 | +
|
| 109 | + tags = { |
| 110 | + Terraform = "true" |
| 111 | + Environment = "dev" |
| 112 | + } |
| 113 | + } |
| 114 | +
|
| 115 | + items = { |
| 116 | + deploy1 = { |
| 117 | + app_name = "my-random-app-1" |
| 118 | + deployment_group_name = "something1" |
| 119 | +
|
| 120 | + alias_name = dependency.aliases.outputs.wrapper.alias1.lambda_alias_name |
| 121 | + function_name = dependency.lambda1.outputs.lambda_function_name |
| 122 | + target_version = dependency.lambda1.outputs.lambda_function_version |
| 123 | + } |
| 124 | + deploy2 = { |
| 125 | + app_name = "my-random-app-2" |
| 126 | + deployment_group_name = "something2" |
| 127 | +
|
| 128 | + alias_name = dependency.aliases.outputs.wrapper.alias2.lambda_alias_name |
| 129 | + function_name = dependency.lambda2.outputs.lambda_function_name |
| 130 | + target_version = dependency.lambda2.outputs.lambda_function_version |
| 131 | + } |
| 132 | + } |
| 133 | +} |
| 134 | +``` |
0 commit comments