Skip to content

Commit 90ae2cd

Browse files
linnhegemhd999
authored andcommitted
Changed random string in names to be optional (#3)
* changed random string in names to be optional
1 parent bf0f541 commit 90ae2cd

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed

example/default/main.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ module "lambda-slack" {
55

66
name_prefix = "name-prefix"
77

8+
has_random_postfix = false
9+
810
handler = "bin/main"
911

1012
slack_hook = "https://hooks.slack.com/services/Secret"

iam.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
resource "aws_iam_role" "lambda_role" {
2-
name = "${var.name_prefix}_lambda_role_${random_string.lambda_postfix_generator.result}"
2+
name = "${var.name_prefix}_lambda_role${var.has_random_postfix ? "_${random_string.lambda_postfix_generator.result}" : ""}"
33
assume_role_policy = "${data.aws_iam_policy_document.lambda_assume.json}"
44
}
55

@@ -22,7 +22,7 @@ data "aws_iam_policy_document" "lambda_assume" {
2222
}
2323

2424
resource "aws_iam_role_policy" "lambda_main" {
25-
name = "${var.name_prefix}_lambda_policy_${random_string.lambda_postfix_generator.result}"
25+
name = "${var.name_prefix}_lambda_policy${var.has_random_postfix ? "_${random_string.lambda_postfix_generator.result}" : ""}"
2626
role = "${aws_iam_role.lambda_role.name}"
2727
policy = "${data.aws_iam_policy_document.lambda_services_dashboard.json}"
2828
}

main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ resource "random_string" "lambda_postfix_generator" {
77
}
88

99
resource "aws_sns_topic" "alarm_topic" {
10-
name = "${var.topic_name}-${random_string.lambda_postfix_generator.result}"
10+
name = "${var.topic_name}${var.has_random_postfix ? "-${random_string.lambda_postfix_generator.result}" : ""}"
1111
}
1212

1313
resource "aws_lambda_function" "notify_slack" {
1414
s3_bucket = "${var.lambda_s3_bucket}"
1515
s3_key = "${var.s3_key}"
16-
function_name = "${var.name_prefix}-slack-notify-${random_string.lambda_postfix_generator.result}"
16+
function_name = "${var.name_prefix}-slack-notify${var.has_random_postfix ? "-${random_string.lambda_postfix_generator.result}" : ""}"
1717
handler = "${var.handler}"
1818
runtime = "go1.x"
1919
timeout = "${var.timeout}"

variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ variable "topic_name" {
66
description = "A prefix that will be added to resources so that they are unique."
77
}
88

9+
variable "has_random_postfix" {
10+
description = "Boolean for adding a random string to the end of the iam role, iam policy, topic and function names"
11+
default = true
12+
}
13+
914
variable "handler" {
1015
description = "The function entrypoint in the code."
1116
default = "main"

0 commit comments

Comments
 (0)