Skip to content

Commit

Permalink
Update vpc resource names inline with issue #89.
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeCSykes authored and chrisbloe committed Aug 31, 2023
1 parent 9139b74 commit 0e9310a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
44 changes: 22 additions & 22 deletions modules/aws/vpc/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,23 @@ terraform {
}
}

resource "aws_flow_log" "flow_log" {
iam_role_arn = aws_iam_role.iam_role[0].arn
log_destination = aws_cloudwatch_log_group.log_group[0].arn
resource "aws_flow_log" "this" {
iam_role_arn = aws_iam_role.this[0].arn
log_destination = aws_cloudwatch_log_group.this[0].arn
traffic_type = var.vpc_flow_logs_traffic_type
vpc_id = aws_vpc.vpc.id
vpc_id = aws_vpc.this.id
count = var.enable_vpc_flow_logs ? 1 : 0
}

resource "random_uuid" "log_group_guid_identifier" {
}

resource "aws_cloudwatch_log_group" "log_group" {
resource "aws_cloudwatch_log_group" "this" {
name = "${var.project_name}-vpc-flow-logs-${random_uuid.log_group_guid_identifier.result}"
count = var.enable_vpc_flow_logs ? 1 : 0
}

resource "aws_iam_role" "iam_role" {
resource "aws_iam_role" "this" {
name = "${var.project_name}-vpc-logs-iam"
count = var.enable_vpc_flow_logs ? 1 : 0

Expand All @@ -50,9 +50,9 @@ resource "aws_iam_role" "iam_role" {
EOF
}

resource "aws_iam_role_policy" "iam_role_policy" {
resource "aws_iam_role_policy" "this" {
name = "${var.project_name}-vpc-iam-logs-policy"
role = aws_iam_role.iam_role[0].id
role = aws_iam_role.this[0].id
count = var.enable_vpc_flow_logs ? 1 : 0
policy = <<EOF
{
Expand All @@ -74,7 +74,7 @@ EOF
}


resource "aws_vpc" "vpc" {
resource "aws_vpc" "this" {
cidr_block = var.vpc_cidr
enable_dns_support = var.enable_dns_support
enable_dns_hostnames = var.enable_dns_hostnames
Expand All @@ -85,9 +85,9 @@ resource "aws_vpc" "vpc" {
}
}

resource "aws_subnet" "public_subnets" {
resource "aws_subnet" "public" {
count = length(local.public_subnet_cidrs)
vpc_id = aws_vpc.vpc.id
vpc_id = aws_vpc.this.id
cidr_block = element(local.public_subnet_cidrs, count.index)
availability_zone = element(local.az_zones, count.index)

Expand All @@ -98,9 +98,9 @@ resource "aws_subnet" "public_subnets" {
}
}

resource "aws_subnet" "private_subnets" {
resource "aws_subnet" "private" {
count = length(local.private_subnet_cidrs)
vpc_id = aws_vpc.vpc.id
vpc_id = aws_vpc.this.id
cidr_block = element(local.private_subnet_cidrs, count.index)
availability_zone = element(local.az_zones, count.index)

Expand All @@ -111,28 +111,28 @@ resource "aws_subnet" "private_subnets" {
}
}

resource "aws_internet_gateway" "ig" {
resource "aws_internet_gateway" "this" {
count = length(local.public_subnet_cidrs) > 0 ? 1 : 0
vpc_id = aws_vpc.vpc.id
vpc_id = aws_vpc.this.id

tags = {
Name = "${var.project_name}-vpc-ig"
Owner = var.owner
}
}

resource "aws_route_table" "route_table" {
resource "aws_route_table" "this" {
count = length(local.public_subnet_cidrs) > 0 ? 1 : 0
vpc_id = aws_vpc.vpc.id
vpc_id = aws_vpc.this.id

route {
cidr_block = var.ig_cidr
gateway_id = aws_internet_gateway.ig[0].id
gateway_id = aws_internet_gateway.this[0].id
}

route {
ipv6_cidr_block = var.ig_ipv6_cidr
gateway_id = aws_internet_gateway.ig[0].id
gateway_id = aws_internet_gateway.this[0].id
}

tags = {
Expand All @@ -141,8 +141,8 @@ resource "aws_route_table" "route_table" {
}
}

resource "aws_route_table_association" "public_subnet_rt_asso" {
resource "aws_route_table_association" "public" {
count = length(local.public_subnet_cidrs)
subnet_id = element(aws_subnet.public_subnets[*].id, count.index)
route_table_id = aws_route_table.route_table[0].id
subnet_id = element(aws_subnet.public[*].id, count.index)
route_table_id = aws_route_table.this[0].id
}
6 changes: 3 additions & 3 deletions modules/aws/vpc/output.tf
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
output "vpc_id" {
value = aws_vpc.vpc.id
value = aws_vpc.this.id
description = "The ID of the VPC that has been created. This output is of type `list(string)`."
}

output "public_subnet_ids" {
value = aws_subnet.public_subnets[*].id
value = aws_subnet.public[*].id
description = "A list of the public subnet IDs that have been created. This output is of type `list(string)`."
}

output "private_subnet_ids" {
value = aws_subnet.private_subnets[*].id
value = aws_subnet.private[*].id
description = "A list of the private subnet IDs that have been created. This output is of type `list(string)`."
}

Expand Down

0 comments on commit 0e9310a

Please sign in to comment.