-
Notifications
You must be signed in to change notification settings - Fork 4
Update vpc resource names inline with issue #89. #90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
JoeCSykes
wants to merge
10
commits into
main
Choose a base branch
from
update_vpc_resource_names
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+120
−82
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0e9310a
Update vpc resource names inline with issue #89.
JoeCSykes c41b327
terraform-docs: automated action
github-actions[bot] c47bbee
Update main.tf
chrisbloe e72e35e
Update locals.tf
chrisbloe 121a933
Update data.tf
chrisbloe c12366a
terraform-docs: automated action
github-actions[bot] fa9b380
Improving the names used
chrisbloe d59c462
terraform-docs: automated action
github-actions[bot] c2e8353
Just formatting
chrisbloe 025dc07
terraform-docs: automated action
github-actions[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| data "aws_availability_zones" "available" { | ||
| state = "available" | ||
| } | ||
|
|
||
| data "aws_region" "current" {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| module "vpc_subnet" { | ||
| source = "../." | ||
| owner = "joe_bloggs" | ||
| owner = "joe.blogs@answerdigital.com" | ||
| project_name = "test_person_name" | ||
| enable_vpc_flow_logs = true | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,37 +2,33 @@ terraform { | |
| required_version = "~> 1.3" | ||
|
|
||
| required_providers { | ||
| random = { | ||
| source = "hashicorp/random" | ||
| version = ">= 3.4.3" | ||
| } | ||
| aws = { | ||
| source = "hashicorp/aws" | ||
| version = ">= 4.0" | ||
| version = ">= 5.14.0" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| 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 | ||
| traffic_type = var.vpc_flow_logs_traffic_type | ||
| vpc_id = aws_vpc.vpc.id | ||
| count = var.enable_vpc_flow_logs ? 1 : 0 | ||
| } | ||
| resource "aws_flow_log" "this" { | ||
| count = var.enable_vpc_flow_logs ? 1 : 0 | ||
|
|
||
| resource "random_uuid" "log_group_guid_identifier" { | ||
| iam_role_arn = aws_iam_role.vpc_flow_logs[0].arn | ||
| log_destination = aws_cloudwatch_log_group.vpc_flow_logs[0].arn | ||
| traffic_type = var.vpc_flow_logs_traffic_type | ||
| vpc_id = aws_vpc.this.id | ||
| } | ||
|
|
||
| resource "aws_cloudwatch_log_group" "log_group" { | ||
| name = "${var.project_name}-vpc-flow-logs-${random_uuid.log_group_guid_identifier.result}" | ||
| resource "aws_cloudwatch_log_group" "vpc_flow_logs" { | ||
| count = var.enable_vpc_flow_logs ? 1 : 0 | ||
|
|
||
| name = "${replace("AWS::Logs::LogGroup", "::", "-")}-${var.project_name}-${var.environment}-${local.aws_region_short}-vpc_flow_logs" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there a reason to use |
||
| } | ||
|
|
||
| resource "aws_iam_role" "iam_role" { | ||
| name = "${var.project_name}-vpc-logs-iam" | ||
| resource "aws_iam_role" "vpc_flow_logs" { | ||
| count = var.enable_vpc_flow_logs ? 1 : 0 | ||
|
|
||
| name = "${replace("AWS::IAM::Role", "::", "-")}-${var.project_name}-${var.environment}-${local.aws_region_short}-vpc_flow_logs" | ||
|
|
||
| assume_role_policy = <<EOF | ||
| { | ||
| "Version": "2012-10-17", | ||
|
|
@@ -50,10 +46,12 @@ resource "aws_iam_role" "iam_role" { | |
| EOF | ||
| } | ||
|
|
||
| resource "aws_iam_role_policy" "iam_role_policy" { | ||
| name = "${var.project_name}-vpc-iam-logs-policy" | ||
| role = aws_iam_role.iam_role[0].id | ||
| count = var.enable_vpc_flow_logs ? 1 : 0 | ||
| resource "aws_iam_role_policy" "vpc_flow_logs" { | ||
| count = var.enable_vpc_flow_logs ? 1 : 0 | ||
|
|
||
| name = "${replace("AWS::IAM::RolePolicy", "::", "-")}-${var.project_name}-${var.environment}-${local.aws_region_short}-vpc_flow_logs" | ||
| role = aws_iam_role.vpc_flow_logs[0].id | ||
|
|
||
| policy = <<EOF | ||
| { | ||
| "Version": "2012-10-17", | ||
|
|
@@ -73,76 +71,80 @@ resource "aws_iam_role_policy" "iam_role_policy" { | |
| EOF | ||
| } | ||
|
|
||
JoeCSykes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| 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 | ||
|
|
||
| tags = { | ||
| Name = "${var.project_name}-vpc" | ||
| Name = "${replace("AWS::EC2::VPC", "::", "-")}-${var.project_name}-${var.environment}-${local.aws_region_short}" | ||
| Owner = var.owner | ||
| } | ||
| } | ||
|
|
||
| resource "aws_subnet" "public_subnets" { | ||
| count = length(local.public_subnet_cidrs) | ||
| vpc_id = aws_vpc.vpc.id | ||
| resource "aws_subnet" "public" { | ||
JoeCSykes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| count = length(local.public_subnet_cidrs) | ||
|
|
||
| vpc_id = aws_vpc.this.id | ||
| cidr_block = element(local.public_subnet_cidrs, count.index) | ||
| availability_zone = element(local.az_zones, count.index) | ||
|
|
||
| tags = { | ||
| Name = "${var.project_name}-public-subnet-${count.index + 1}" | ||
| Name = "${replace("AWS::EC2::Subnet", "::", "-")}-${var.project_name}-${var.environment}-${local.aws_region_short}-public_${count.index + 1}" | ||
| Zone = "Public" | ||
| Owner = var.owner | ||
| } | ||
| } | ||
|
|
||
| resource "aws_subnet" "private_subnets" { | ||
| count = length(local.private_subnet_cidrs) | ||
| vpc_id = aws_vpc.vpc.id | ||
| resource "aws_subnet" "private" { | ||
JoeCSykes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| count = length(local.private_subnet_cidrs) | ||
|
|
||
| vpc_id = aws_vpc.this.id | ||
| cidr_block = element(local.private_subnet_cidrs, count.index) | ||
| availability_zone = element(local.az_zones, count.index) | ||
|
|
||
| tags = { | ||
| Name = "${var.project_name}-private-subnet-${count.index + 1}" | ||
| Name = "${replace("AWS::EC2::Subnet", "::", "-")}-${var.project_name}-${var.environment}-${local.aws_region_short}-private_${count.index + 1}" | ||
| Zone = "Private" | ||
| Owner = var.owner | ||
| } | ||
| } | ||
|
|
||
| resource "aws_internet_gateway" "ig" { | ||
| count = length(local.public_subnet_cidrs) > 0 ? 1 : 0 | ||
| vpc_id = aws_vpc.vpc.id | ||
| resource "aws_internet_gateway" "this" { | ||
| count = length(local.public_subnet_cidrs) > 0 ? 1 : 0 | ||
|
|
||
| vpc_id = aws_vpc.this.id | ||
|
|
||
| tags = { | ||
| Name = "${var.project_name}-vpc-ig" | ||
| Name = "${replace("AWS::EC2::InternetGateway", "::", "-")}-${var.project_name}-${var.environment}-${local.aws_region_short}-${count.index + 1}" | ||
| Owner = var.owner | ||
| } | ||
| } | ||
|
|
||
| resource "aws_route_table" "route_table" { | ||
| count = length(local.public_subnet_cidrs) > 0 ? 1 : 0 | ||
| vpc_id = aws_vpc.vpc.id | ||
| resource "aws_route_table" "public" { | ||
| count = length(local.public_subnet_cidrs) > 0 ? 1 : 0 | ||
|
|
||
| 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 = { | ||
JoeCSykes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Name = "${var.project_name}-public-route-table" | ||
| Name = "${replace("AWS::EC2::RouteTable", "::", "-")}-${var.project_name}-${var.environment}-${local.aws_region_short}-public_${count.index + 1}" | ||
| Owner = var.owner | ||
| } | ||
| } | ||
|
|
||
| resource "aws_route_table_association" "public_subnet_rt_asso" { | ||
| 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 | ||
| resource "aws_route_table_association" "public" { | ||
| count = length(local.public_subnet_cidrs) | ||
|
|
||
| subnet_id = element(aws_subnet.public[*].id, count.index) | ||
| route_table_id = aws_route_table.public[0].id | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,19 @@ | ||
| output "vpc_id" { | ||
| value = aws_vpc.vpc.id | ||
| description = "The ID of the VPC that has been created. This output is of type `list(string)`." | ||
| value = aws_vpc.this.id | ||
| description = "The ID of the VPC that has been created. This output is of type `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)`." | ||
| } | ||
|
|
||
| output "az_zones" { | ||
| value = local.az_zones | ||
| description = "A list of the Availability Zones that have been used. This output is of type `string`." | ||
| description = "A list of the Availability Zones that have been used. This output is of type `list(string)`." | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we document (in code, or in wiki) the reasoning/requirement behind minimum versions of providers? It will make it easier to understand cross-module provider requirements