Skip to content

Commit 7f84d15

Browse files
author
Kilian
committed
refa: removed name variable
1 parent 59fd938 commit 7f84d15

File tree

5 files changed

+26
-79
lines changed

5 files changed

+26
-79
lines changed

README.md

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,17 @@ This module provides a Lambda function which logs to CloudWatch. If no image URI
2121

2222
## Inputs
2323

24-
| Name | Description | Type | Default | Required |
25-
| ------------- | ----------------------------------------------------------------------------------------------------- | -------------- | ------- | :------: |
26-
| identifier | Unique identifier to differentiate global resources. | `string` | n/a | yes |
27-
| name | Name of this module, which is used as identifier on all resources. | `string` | "" | no |
28-
| policies | List of IAM policy ARNs for the Lambda's IAM role. | `list(string)` | [] | no |
29-
| vpc_config | Object to define the subnets and security groups for the Lambda function. | `object` | null | no |
30-
| log | A flag for make the Lambda function submit logs to CloudWatch. | `bool` | false | no |
31-
| image_uri | URI of the image which will be pulled by the Lambda function to execute. | `string` | "" | no |
32-
| memory_size | Amount of memory in MB the Lambda function can use at runtime. | `number` | 128 | no |
33-
| timeout | Amount of time the Lambda function has to run in seconds. | `number` | 3 | no |
34-
| env_variables | A map of environment variables for the Lambda function at runtime. | `map(string)` | {} | no |
35-
| tags | A map of tags to add to all resources. Name is always set as tag and the other tags will be appended. | `map(string)` | {} | no |
24+
| Name | Description | Type | Default | Required |
25+
| ------------- | ------------------------------------------------------------------------- | -------------- | ------- | :------: |
26+
| identifier | Unique identifier to differentiate global resources. | `string` | n/a | yes |
27+
| policies | List of IAM policy ARNs for the Lambda's IAM role. | `list(string)` | [] | no |
28+
| vpc_config | Object to define the subnets and security groups for the Lambda function. | `object` | null | no |
29+
| log | A flag for make the Lambda function submit logs to CloudWatch. | `bool` | false | no |
30+
| image_uri | URI of the image which will be pulled by the Lambda function to execute. | `string` | "" | no |
31+
| memory_size | Amount of memory in MB the Lambda function can use at runtime. | `number` | 128 | no |
32+
| timeout | Amount of time the Lambda function has to run in seconds. | `number` | 3 | no |
33+
| env_variables | A map of environment variables for the Lambda function at runtime. | `map(string)` | {} | no |
34+
| tags | A map of tags to add to all resources. | `map(string)` | {} | no |
3635

3736
### `vpc_config`
3837

@@ -54,7 +53,6 @@ module "function" {
5453
source = "github.com/custom-terraform-aws-modules/function"
5554
5655
identifier = "example-function-dev"
57-
name = "example-function"
5856
policies = [
5957
"arn:aws:iam::aws:policy/aws-service-role/AccessAnalyzerServiceRolePolicy",
6058
"arn:aws:iam::aws:policy/AdministratorAccess-Amplify"

main.tf

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ resource "aws_iam_role" "main" {
1717
name = "${var.identifier}-ServiceRoleForLambda"
1818
assume_role_policy = data.aws_iam_policy_document.assume_role.json
1919

20-
tags = merge(
21-
{ "Name" = var.name },
22-
var.tags
23-
)
20+
tags = var.tags
2421
}
2522

2623
resource "aws_iam_role_policy_attachment" "import" {
@@ -50,10 +47,7 @@ resource "aws_iam_policy" "vpc" {
5047
name = "${var.identifier}-AssignSelfToVPC"
5148
policy = data.aws_iam_policy_document.vpc[0].json
5249

53-
tags = merge(
54-
{ "Name" = var.name },
55-
var.tags
56-
)
50+
tags = var.tags
5751
}
5852

5953
resource "aws_iam_role_policy_attachment" "vpc" {
@@ -81,10 +75,7 @@ resource "aws_iam_policy" "log" {
8175
name = "${var.identifier}-CloudWatchCreateLog"
8276
policy = data.aws_iam_policy_document.log[0].json
8377

84-
tags = merge(
85-
{ "Name" = var.name },
86-
var.tags
87-
)
78+
tags = var.tags
8879
}
8980

9081
resource "aws_iam_role_policy_attachment" "log" {
@@ -103,10 +94,7 @@ resource "aws_ecr_repository" "main" {
10394
image_tag_mutability = "MUTABLE"
10495
force_delete = true
10596

106-
tags = merge(
107-
{ "Name" = var.name },
108-
var.tags
109-
)
97+
tags = var.tags
11098
}
11199

112100
################################
@@ -133,8 +121,5 @@ resource "aws_lambda_function" "main" {
133121
}
134122
}
135123

136-
tags = merge(
137-
{ "Name" = var.name },
138-
var.tags
139-
)
124+
tags = var.tags
140125
}

outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
output "arn" {
2-
description = "ARN of the Lambda function"
2+
description = "ARN of the Lambda function."
33
value = aws_lambda_function.main.arn
44
}

tests/lambda.tftest.hcl

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -64,29 +64,3 @@ run "valid_vpc_config" {
6464
}
6565
}
6666
}
67-
68-
run "invalid_tags" {
69-
command = plan
70-
71-
variables {
72-
identifier = "test"
73-
74-
tags = {
75-
Name = "Foo"
76-
}
77-
}
78-
79-
expect_failures = [var.tags]
80-
}
81-
82-
run "valid_tags" {
83-
command = plan
84-
85-
variables {
86-
identifier = "test"
87-
88-
tags = {
89-
Project = "Foo"
90-
}
91-
}
92-
}

variables.tf

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,20 @@
11
variable "identifier" {
2-
description = "Unique identifier to differentiate global resources"
2+
description = "Unique identifier to differentiate global resources."
33
type = string
44
validation {
55
condition = length(var.identifier) > 2
66
error_message = "Identifier must be at least 3 characters"
77
}
88
}
99

10-
variable "name" {
11-
description = "Name of this module which is used as identifier on all resources"
12-
type = string
13-
default = ""
14-
}
15-
1610
variable "policies" {
17-
description = "List of IAM policy ARNs for the Lambda's IAM role"
11+
description = "List of IAM policy ARNs for the Lambda's IAM role."
1812
type = list(string)
1913
default = []
2014
}
2115

2216
variable "vpc_config" {
23-
description = "Object to define the subnets and security groups for the Lambda function"
17+
description = "Object to define the subnets and security groups for the Lambda function."
2418
type = object({
2519
subnets = list(string)
2620
security_groups = list(string)
@@ -37,25 +31,25 @@ variable "vpc_config" {
3731
}
3832

3933
variable "log" {
40-
description = "A flag for make the Lambda function submit logs to CloudWatch"
34+
description = "A flag for make the Lambda function submit logs to CloudWatch."
4135
type = bool
4236
default = false
4337
}
4438

4539
variable "image_uri" {
46-
description = "URI of the image which will be pulled by the Lambda function to execute"
40+
description = "URI of the image which will be pulled by the Lambda function to execute."
4741
type = string
4842
default = ""
4943
}
5044

5145
variable "memory_size" {
52-
description = "Amount of memory in MB the Lambda function can use at runtime"
46+
description = "Amount of memory in MB the Lambda function can use at runtime."
5347
type = number
5448
default = 128
5549
}
5650

5751
variable "timeout" {
58-
description = "Amount of time the Lambda function has to run in seconds"
52+
description = "Amount of time the Lambda function has to run in seconds."
5953
type = number
6054
default = 3
6155
validation {
@@ -65,17 +59,13 @@ variable "timeout" {
6559
}
6660

6761
variable "env_variables" {
68-
description = "A map of environment variables for the Lambda function at runtime"
62+
description = "A map of environment variables for the Lambda function at runtime."
6963
type = map(string)
7064
default = {}
7165
}
7266

7367
variable "tags" {
74-
description = "A map of tags to add to all resources"
68+
description = "A map of tags to add to all resources."
7569
type = map(string)
7670
default = {}
77-
validation {
78-
condition = !contains(keys(var.tags), "Name")
79-
error_message = "Name tag is reserved and will be used automatically"
80-
}
8171
}

0 commit comments

Comments
 (0)