Skip to content

Commit a8cb33f

Browse files
authored
Remove random IDs from resources (#227)
1 parent 385edb9 commit a8cb33f

File tree

14 files changed

+29
-57
lines changed

14 files changed

+29
-57
lines changed

examples/complete/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ provider "aws" {
2323
module "tf_next" {
2424
source = "milliHQ/next-js/aws"
2525

26-
deployment_name = "terraform-next-js-example-complete"
26+
deployment_name = "tf-next-example-complete"
2727

2828
providers = {
2929
aws.global_region = aws.global_region

examples/next-image/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ provider "aws" {
2323
module "tf_next" {
2424
source = "milliHQ/next-js/aws"
2525

26-
deployment_name = "terraform-next-js-example-image"
26+
deployment_name = "tf-next-example-image"
2727

2828
providers = {
2929
aws.global_region = aws.global_region

examples/static/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ provider "aws" {
2323
module "tf_next" {
2424
source = "milliHQ/next-js/aws"
2525

26-
deployment_name = "terraform-next-js-example-static"
26+
deployment_name = "tf-next-example-static"
2727

2828
providers = {
2929
aws.global_region = aws.global_region

examples/with-custom-domain/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ module "tf_next" {
107107
cloudfront_aliases = local.aliases
108108
cloudfront_acm_certificate_arn = module.cloudfront_cert.acm_certificate_arn
109109

110-
deployment_name = "terraform-next-js-example-custom-domain"
110+
deployment_name = "tf-next-example-custom-domain"
111111
providers = {
112112
aws.global_region = aws.global_region
113113
}

examples/with-existing-cloudfront/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ module "tf_next" {
3232
cloudfront_external_id = aws_cloudfront_distribution.distribution.id
3333
cloudfront_external_arn = aws_cloudfront_distribution.distribution.arn
3434

35-
deployment_name = "terraform-next-js-existing-cloudfront"
35+
deployment_name = "tf-next-existing-cloudfront"
3636

3737
providers = {
3838
aws.global_region = aws.global_region

iam.tf

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ data "aws_iam_policy_document" "assume_role" {
1717
resource "aws_iam_role" "lambda" {
1818
for_each = local.lambdas
1919

20-
name = random_id.function_name[each.key].hex
20+
name = "${var.deployment_name}_${each.key}"
2121
description = "Managed by Terraform Next.js"
2222

2323
permissions_boundary = var.lambda_role_permissions_boundary
@@ -34,7 +34,7 @@ resource "aws_iam_role" "lambda" {
3434
resource "aws_cloudwatch_log_group" "this" {
3535
for_each = local.lambdas
3636

37-
name = "/aws/lambda/${random_id.function_name[each.key].hex}"
37+
name = "/aws/lambda/${var.deployment_name}_${each.key}"
3838
retention_in_days = 14
3939

4040
tags = var.tags
@@ -59,6 +59,8 @@ resource "aws_iam_policy" "lambda_logging" {
5959
description = "Managed by Terraform Next.js"
6060

6161
policy = data.aws_iam_policy_document.lambda_logging.json
62+
63+
tags = var.tags
6264
}
6365

6466
resource "aws_iam_role_policy_attachment" "lambda_logs" {
@@ -85,6 +87,8 @@ resource "aws_iam_policy" "additional_json" {
8587

8688
description = "Managed by Terraform Next.js"
8789
policy = var.lambda_policy_json
90+
91+
tags = var.tags
8892
}
8993

9094
resource "aws_iam_role_policy_attachment" "additional_json" {

main.tf

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,6 @@ locals {
2424
})
2525
}
2626

27-
# Generates for each function a unique function name
28-
resource "random_id" "function_name" {
29-
for_each = local.lambdas
30-
31-
prefix = "${each.key}-"
32-
byte_length = 4
33-
}
34-
3527
#########
3628
# Lambdas
3729
#########
@@ -61,8 +53,8 @@ module "statics_deploy" {
6153
resource "aws_lambda_function" "this" {
6254
for_each = local.lambdas
6355

64-
function_name = random_id.function_name[each.key].hex
65-
description = "Managed by Terraform-next.js"
56+
function_name = "${var.deployment_name}_${each.key}"
57+
description = "Managed by Terraform Next.js"
6658
role = aws_iam_role.lambda[each.key].arn
6759
handler = lookup(each.value, "handler", "")
6860
runtime = lookup(each.value, "runtime", var.lambda_runtime)
@@ -98,7 +90,7 @@ resource "aws_lambda_permission" "current_version_triggers" {
9890

9991
statement_id = "AllowInvokeFromApiGateway"
10092
action = "lambda:InvokeFunction"
101-
function_name = random_id.function_name[each.key].hex
93+
function_name = "${var.deployment_name}_${each.key}"
10294
principal = "apigateway.amazonaws.com"
10395

10496
source_arn = "${module.api_gateway.apigatewayv2_api_execution_arn}/*/*/*"
@@ -129,7 +121,7 @@ module "api_gateway" {
129121
version = "1.1.0"
130122

131123
name = var.deployment_name
132-
description = "Managed by Terraform-next.js"
124+
description = "Managed by Terraform Next.js"
133125
protocol_type = "HTTP"
134126

135127
create_api_domain_name = false
@@ -176,7 +168,7 @@ module "next_image" {
176168
lambda_policy_json = data.aws_iam_policy_document.access_static_deployment.json
177169
lambda_role_permissions_boundary = var.lambda_role_permissions_boundary
178170

179-
deployment_name = var.deployment_name
171+
deployment_name = "${var.deployment_name}_tfn-image"
180172
tags = var.tags
181173
}
182174

@@ -199,11 +191,6 @@ module "proxy_config" {
199191
# Proxy (Lambda@Edge)
200192
#####################
201193

202-
resource "random_id" "policy_name" {
203-
prefix = "${var.deployment_name}-"
204-
byte_length = 4
205-
}
206-
207194
module "proxy" {
208195
source = "./modules/proxy"
209196

@@ -255,7 +242,7 @@ locals {
255242
}
256243

257244
resource "aws_cloudfront_cache_policy" "this" {
258-
name = "${random_id.policy_name.hex}-cache"
245+
name = "${var.deployment_name}_tfn-cache"
259246
comment = "Managed by Terraform Next.js"
260247

261248
# Default values (Should be provided by origin)

modules/cloudfront-proxy-config/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ locals {
99
########
1010

1111
resource "aws_s3_bucket" "proxy_config_store" {
12-
bucket_prefix = "next-tf-proxy-config"
12+
bucket_prefix = "${var.deployment_name}-tfn-config"
1313
acl = "private"
1414
force_destroy = true
1515
tags = var.tags

modules/proxy/main.tf

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,13 @@ module "proxy_package" {
1313
# Lambda@Edge
1414
#############
1515

16-
resource "random_id" "function_name" {
17-
prefix = "next-tf-proxy-"
18-
byte_length = 4
19-
}
20-
2116
module "edge_proxy" {
2217
source = "terraform-aws-modules/lambda/aws"
2318
version = "2.4.0"
2419

2520
lambda_at_edge = true
2621

27-
function_name = random_id.function_name.hex
22+
function_name = "${var.deployment_name}_tfn-proxy"
2823
description = "Managed by Terraform Next.js"
2924
handler = "handler.handler"
3025
runtime = var.lambda_default_runtime

modules/proxy/versions.tf

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,5 @@ terraform {
77
version = ">= 3.0"
88
configuration_aliases = [aws.global_region]
99
}
10-
11-
random = {
12-
source = "hashicorp/random"
13-
version = ">= 2.3.0"
14-
}
1510
}
1611
}

0 commit comments

Comments
 (0)