Skip to content

Commit b855a44

Browse files
authored
Feat/initial netwokr (#1)
2 parents ddef22f + ab97517 commit b855a44

File tree

10 files changed

+317
-0
lines changed

10 files changed

+317
-0
lines changed

.github/workflows/main.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Terraform Apply
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
workflow_dispatch:
8+
9+
jobs:
10+
terraform_apply:
11+
name: Terraform Apply
12+
uses: soat-tech-challenge/github-workflows/.github/workflows/terraform-apply.yml@main
13+
secrets: inherit
14+
with:
15+
cloud_workspace: ${{ vars.TF_WORKSPACE }}

.github/workflows/pull-request.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Pull Request
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
workflow_dispatch:
8+
9+
jobs:
10+
tflint:
11+
name: TFLint
12+
uses: soat-tech-challenge/github-workflows/.github/workflows/tflint.yml@main
13+
14+
tfsec:
15+
uses: soat-tech-challenge/github-workflows/.github/workflows/tfsec.yml@main
16+
17+
permissions:
18+
contents: read
19+
pull-requests: write
20+
21+
terraform-plan:
22+
name: Terraform Plan
23+
uses: soat-tech-challenge/github-workflows/.github/workflows/terraform-plan.yml@main
24+
secrets: inherit
25+
with:
26+
cloud_workspace: ${{ vars.TF_WORKSPACE }}
27+
28+
permissions:
29+
contents: read
30+
pull-requests: write
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: Terraform Destroy
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
terraform_destroy:
8+
uses: soat-tech-challenge/github-workflows/.github/workflows/terraform-destroy.yml@main
9+
secrets: inherit
10+
with:
11+
cloud_workspace: ${{ vars.TF_WORKSPACE }}

.terraform.lock.hcl

Lines changed: 45 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

datasources.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

main.tf

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#tfsec:ignore:aws-ec2-require-vpc-flow-logs-for-all-vpcs
2+
resource "aws_vpc" "main" {
3+
cidr_block = "10.0.0.0/16"
4+
5+
tags = {
6+
Name = "SOAT Tech Challenge VPC"
7+
}
8+
}
9+
10+
resource "aws_subnet" "public_subnets" {
11+
count = length(var.private_subnet_cidrs)
12+
13+
vpc_id = aws_vpc.main.id
14+
cidr_block = element(var.public_subnet_cidrs, count.index)
15+
availability_zone = element(local.azs, count.index)
16+
17+
tags = {
18+
Name = "SOAT-TC Public Subnet ${count.index + 1}"
19+
}
20+
}
21+
22+
resource "aws_subnet" "private_subnets" {
23+
count = length(var.private_subnet_cidrs)
24+
25+
vpc_id = aws_vpc.main.id
26+
cidr_block = element(var.private_subnet_cidrs, count.index)
27+
availability_zone = element(local.azs, count.index)
28+
29+
tags = {
30+
Name = "SOAT-TC Private Subnet ${count.index + 1}"
31+
}
32+
}
33+
34+
35+
resource "aws_internet_gateway" "main" {
36+
vpc_id = aws_vpc.main.id
37+
38+
tags = {
39+
Name = "SOAT-TC Internet Gateway"
40+
}
41+
}
42+
43+
resource "aws_route_table" "public_rt" {
44+
vpc_id = aws_vpc.main.id
45+
46+
47+
route {
48+
cidr_block = "0.0.0.0/0"
49+
gateway_id = aws_internet_gateway.main.id
50+
}
51+
52+
tags = {
53+
Name = "SOAT-TC Public Route Table"
54+
}
55+
}
56+
57+
resource "aws_route_table" "private_rt" {
58+
vpc_id = aws_vpc.main.id
59+
60+
tags = {
61+
Name = "SOAT-TC Private Route Table"
62+
}
63+
}
64+
65+
resource "aws_route_table_association" "public_rt_association" {
66+
count = length(var.public_subnet_cidrs)
67+
subnet_id = element(aws_subnet.public_subnets[*].id, count.index)
68+
route_table_id = aws_route_table.public_rt.id
69+
}
70+
71+
resource "aws_route_table_association" "private_rt_association" {
72+
count = length(var.private_subnet_cidrs)
73+
subnet_id = element(aws_subnet.private_subnets[*].id, count.index)
74+
route_table_id = aws_route_table.private_rt.id
75+
}

outputs.tf

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
output "vpc" {
2+
description = "VPC"
3+
value = {
4+
"arn" : aws_vpc.main.arn,
5+
"cidr_block" : aws_vpc.main.cidr_block,
6+
"default_network_acl_id" : aws_vpc.main.default_network_acl_id,
7+
"default_route_table_id" : aws_vpc.main.default_route_table_id,
8+
"default_security_group_id" : aws_vpc.main.default_security_group_id,
9+
"id" : aws_vpc.main.id
10+
"main_route_table_id" : aws_vpc.main.main_route_table_id
11+
"tags" : aws_vpc.main.tags
12+
}
13+
}
14+
15+
output "public_subnets" {
16+
description = "Public Subnets"
17+
value = [for sub in aws_subnet.public_subnets : {
18+
"arn" : sub.arn,
19+
"availability_zone" : sub.availability_zone,
20+
"availability_zone_id" : sub.availability_zone_id,
21+
"cidr_block" : sub.cidr_block,
22+
"id" : sub.id,
23+
"tags" : sub.tags
24+
"vpc_id" : sub.vpc_id,
25+
}]
26+
}
27+
28+
output "private_subnets" {
29+
description = "Private Subnets"
30+
value = [for sub in aws_subnet.private_subnets : {
31+
"arn" : sub.arn,
32+
"availability_zone" : sub.availability_zone,
33+
"availability_zone_id" : sub.availability_zone_id,
34+
"cidr_block" : sub.cidr_block,
35+
"id" : sub.id,
36+
"tags" : sub.tags
37+
"vpc_id" : sub.vpc_id,
38+
}]
39+
}
40+
41+
output "public_rt" {
42+
description = "Public Route Tables"
43+
value = {
44+
"arn" : aws_route_table.public_rt.arn,
45+
"id" : aws_route_table.public_rt.id,
46+
"route" : aws_route_table.public_rt.route,
47+
"vpc_id" : aws_route_table.public_rt.vpc_id
48+
}
49+
}
50+
output "private_rt" {
51+
description = "Private Route Tables"
52+
value = {
53+
"arn" : aws_route_table.private_rt.arn,
54+
"id" : aws_route_table.private_rt.id,
55+
"route" : aws_route_table.private_rt.route,
56+
"vpc_id" : aws_route_table.private_rt.vpc_id
57+
}
58+
}

providers.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
provider "aws" {
2+
region = var.aws_region
3+
4+
access_key = var.aws_access_key
5+
secret_key = var.aws_secret_key
6+
token = var.aws_session_token
7+
8+
default_tags {
9+
tags = {
10+
Organization = "soat-tech-challenge"
11+
Workspace = "network-staging"
12+
}
13+
}
14+
}
15+

variables.tf

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Variable sets
2+
3+
variable "aws_region" {
4+
description = "AWS Region to create resources on"
5+
type = string
6+
default = "us-east-1"
7+
}
8+
9+
variable "aws_access_key" {
10+
description = "AWS Access Key"
11+
type = string
12+
}
13+
14+
variable "aws_secret_key" {
15+
description = "AWS Secret Key"
16+
type = string
17+
}
18+
19+
variable "aws_session_token" {
20+
description = "AWS Secret Key"
21+
type = string
22+
}
23+
24+
// Workspace variables
25+
26+
locals {
27+
// Availability Zones
28+
azs = ["${var.aws_region}a", "${var.aws_region}b"]
29+
}
30+
31+
variable "public_subnet_cidrs" {
32+
type = list(string)
33+
description = "Public Subnet CIDR values"
34+
default = ["10.0.10.0/24", "10.0.11.0/24"]
35+
}
36+
37+
variable "private_subnet_cidrs" {
38+
type = list(string)
39+
description = "Private Subnet CIDR values"
40+
default = ["10.0.20.0/24", "10.0.21.0/24"]
41+
}
42+

versions.tf

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
terraform {
2+
required_version = ">= 0.12.26"
3+
4+
cloud {
5+
organization = "soat-tech-challenge"
6+
7+
workspaces {
8+
name = "network-staging"
9+
}
10+
}
11+
12+
required_providers {
13+
aws = {
14+
source = "hashicorp/aws"
15+
version = "4.67.0"
16+
}
17+
18+
tfe = {
19+
source = "hashicorp/tfe"
20+
version = "~> 0.49.2"
21+
}
22+
}
23+
}
24+
25+

0 commit comments

Comments
 (0)