diff --git a/README.md b/README.md index 2db6d0e..f768332 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,8 @@ Yet another serverless lambda redirect. This one accepts a list of domain names module "redirect" { source = "../lambda-redirect" + resource_suffix = "example.com" + domain_mapping = { "test.example.com": "https://example.com/test", "mail.example.com": "https://mailprovider.com", @@ -65,7 +67,7 @@ No modules. | [aws\_acm\_certificate](#input\_aws\_acm\_certificate) | ACM certificate to use with the source domains (must be in us-east-1!) |
object({| n/a | yes | | [domain\_mapping](#input\_domain\_mapping) | A key/value map of source domains -> target redirects. For example: domain\_mapping: {"test.example.com": "https://example.com/test"} | `map(string)` | n/a | yes | | [http\_redirect\_code](#input\_http\_redirect\_code) | Which HTTP redirect code to use (301 or 302) | `string` | `"301"` | no | - +| [resource\_suffix](#input\_resource\_suffix) | A suffix to append to resources so they don't clash | `string` | `""` | no | ## Outputs | Name | Description | diff --git a/main.tf b/main.tf index 2748adf..4974d81 100644 --- a/main.tf +++ b/main.tf @@ -1,5 +1,6 @@ locals { domains = keys(var.domain_mapping) + resource_suffix = var.resource_suffix != "" ? "-${var.resource_suffix}" : "" } data "archive_file" "redirect_lambda" { @@ -14,17 +15,17 @@ data "archive_file" "redirect_lambda" { filename = "index.py" } - output_path = "${path.module}/build/lambda_redirect.zip" + output_path = "${path.module}/build/lambda_redirect${local.resource_suffix}.zip" } resource "aws_cloudwatch_log_group" "redirect_lambda" { - name = "/aws/lambda/redirect_lambda" + name = "/aws/lambda/redirect_lambda${local.resource_suffix}" retention_in_days = 7 } resource "aws_lambda_function" "redirect_lambda" { filename = data.archive_file.redirect_lambda.output_path - function_name = "redirect_lambda" + function_name = "redirect_lambda${local.resource_suffix}" role = aws_iam_role.lambda_execution_role.arn handler = "index.handler" source_code_hash = data.archive_file.redirect_lambda.output_base64sha256 @@ -70,12 +71,12 @@ data "aws_iam_policy_document" "lambda_policy" { } resource "aws_iam_policy" "lambda_policy" { - name = "lambda-policy" + name = "lambda-policy${local.resource_suffix}" policy = data.aws_iam_policy_document.lambda_policy.json } resource "aws_iam_role" "lambda_execution_role" { - name = "redirect-lambda-execution-role" + name = "redirect-lambda-execution-role${local.resource_suffix}" assume_role_policy = data.aws_iam_policy_document.lambda_assume_role.json } diff --git a/variables.tf b/variables.tf index c4bb594..505c287 100644 --- a/variables.tf +++ b/variables.tf @@ -14,4 +14,10 @@ variable "http_redirect_code" { type = string description = "Which HTTP redirect code to use (301 or 302)" default = "301" +} + +variable "resource_suffix" { + type = string + description = "A suffix to append to resources so they don't clash" + default = "" } \ No newline at end of file
arn = string
})