Skip to content

Commit 2403e4b

Browse files
committed
updated module reference
1 parent 5b02323 commit 2403e4b

File tree

2 files changed

+17
-60
lines changed

2 files changed

+17
-60
lines changed

elasticache.tf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
resource "aws_elasticache_subnet_group" "elasticache_subnet" {
2-
name = "app-4-cache-subnet"
3-
subnet_ids = [for subnet in aws_subnet.private : subnet.id]
2+
name = "${var.name}-cache-subnet"
3+
subnet_ids = [for subnet in module.vpc.private_subnets : subnet.id]
44
}
55

66
resource "aws_secretsmanager_secret" "elasticache_auth" {
7-
name = "app-4-elasticache-auth"
7+
name = "${var.name}-elasticache-auth"
88
recovery_window_in_days = 0
99
kms_key_id = aws_kms_key.encryption_secret.id
1010
#checkov:skip=CKV2_AWS_57: Disabled Secrets Manager secrets automatic rotation
@@ -18,8 +18,8 @@ resource "aws_secretsmanager_secret_version" "auth" {
1818
resource "aws_elasticache_replication_group" "app4" {
1919
automatic_failover_enabled = true
2020
subnet_group_name = aws_elasticache_subnet_group.elasticache_subnet.name
21-
replication_group_id = var.replication_group_id
22-
description = "ElastiCache cluster for app4"
21+
replication_group_id = var.name
22+
description = "ElastiCache cluster for ${var.name}"
2323
node_type = "cache.t2.small"
2424
parameter_group_name = "default.redis7.cluster.on"
2525
port = 6379

network.tf

Lines changed: 12 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,13 @@
1-
# https://docs.aws.amazon.com/glue/latest/dg/set-up-vpc-dns.html
2-
resource "aws_vpc" "this" {
3-
cidr_block = var.vpc_cidr
4-
# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc#enable_dns_support
5-
enable_dns_support = true
6-
# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc#enable_dns_hostnames
7-
enable_dns_hostnames = true
8-
#checkov:skip=CKV2_AWS_11: Not creating a flow log for this VPC
9-
tags = {
10-
"Name" = "app-4"
11-
}
12-
}
13-
data "aws_availability_zones" "available" {
14-
state = "available"
15-
}
16-
resource "aws_subnet" "private" {
17-
count = length(var.subnet_cidr_private)
18-
vpc_id = aws_vpc.this.id
19-
cidr_block = var.subnet_cidr_private[count.index]
20-
availability_zone = data.aws_availability_zones.available.names[(count.index) % length(data.aws_availability_zones.available.names)]
21-
tags = {
22-
"Name" = "app-4-private-${count.index + 1}"
23-
}
24-
}
25-
resource "aws_subnet" "public" {
26-
count = length(var.subnet_cidr_public)
27-
vpc_id = aws_vpc.this.id
28-
cidr_block = var.subnet_cidr_public[count.index]
29-
availability_zone = data.aws_availability_zones.available.names[(count.index) % length(data.aws_availability_zones.available.names)]
30-
tags = {
31-
"Name" = "app-4-public-${count.index + 1}"
32-
}
33-
}
34-
resource "aws_route_table" "private" {
35-
count = length(var.subnet_cidr_private)
36-
vpc_id = aws_vpc.this.id
37-
tags = {
38-
"Name" = "app-4-private-route-table-${count.index + 1}"
39-
}
40-
}
41-
resource "aws_route_table" "public" {
42-
vpc_id = aws_vpc.this.id
43-
tags = {
44-
"Name" = "app-4-public"
45-
}
46-
}
47-
resource "aws_route_table_association" "private" {
48-
count = length(var.subnet_cidr_private)
49-
subnet_id = element(aws_subnet.private.*.id, count.index)
50-
route_table_id = aws_route_table.private[count.index].id
51-
}
52-
resource "aws_route_table_association" "public" {
53-
count = length(var.subnet_cidr_public)
54-
subnet_id = element(aws_subnet.public.*.id, count.index)
55-
route_table_id = aws_route_table.public.id
1+
module "vpc" {
2+
#CKV_TF_1: Ensure Terraform module sources use a commit hash
3+
#checkov:skip=CKV_TF_1: This is a self hosted module where the version number is tagged rather than the commit hash.
4+
source = "github.com/kunduso/terraform-aws-vpc?ref=v1.0.1"
5+
region = var.region
6+
vpc_cidr = var.vpc_cidr
7+
enable_dns_support = "true"
8+
enable_dns_hostnames = "true"
9+
vpc_name = "app-4"
10+
subnet_cidr_private = var.subnet_cidr_private
11+
subnet_cidr_public = var.subnet_cidr_public
12+
enable_flow_log = "true"
5613
}

0 commit comments

Comments
 (0)