Skip to content

Commit 460a275

Browse files
authored
feat: reorganize resources by services (#2)
2 parents b855a44 + f4407ae commit 460a275

13 files changed

+226
-179
lines changed

api-gateway.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
resource "aws_apigatewayv2_api" "main" {
2+
name = "SOAT Tech Challenge API"
3+
description = "API for SOAT Tech Challenge HTTP communication"
4+
protocol_type = "HTTP"
5+
}
6+
7+
resource "aws_apigatewayv2_stage" "main" {
8+
api_id = aws_apigatewayv2_api.main.id
9+
name = "$default"
10+
auto_deploy = true
11+
12+
tags = {
13+
Name = "SOAT-TC API Default Stage"
14+
}
15+
}

api_gateway_integrations.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
resource "aws_apigatewayv2_integration" "debug_integration" {
2+
api_id = aws_apigatewayv2_api.main.id
3+
integration_type = "HTTP_PROXY"
4+
5+
integration_method = "ANY"
6+
integration_uri = "https://example.com/"
7+
}

api_gateway_outputs.tf

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
output "api_gateway_api" {
2+
description = "HTTP API"
3+
value = {
4+
"api_endpoint" : aws_apigatewayv2_api.main.api_endpoint
5+
"arn" : aws_apigatewayv2_api.main.arn
6+
"execution_arn" : aws_apigatewayv2_api.main.execution_arn
7+
"id" : aws_apigatewayv2_api.main.id
8+
"name" : aws_apigatewayv2_api.main.name
9+
"tags" : aws_apigatewayv2_api.main.tags
10+
"version" : aws_apigatewayv2_api.main.version
11+
}
12+
}
13+
14+
output "api_gateway_stage" {
15+
description = "Default Stage"
16+
value = {
17+
"api_id" : aws_apigatewayv2_stage.main.api_id
18+
"arn" : aws_apigatewayv2_stage.main.arn
19+
"execution_arn" : aws_apigatewayv2_stage.main.execution_arn
20+
"id" : aws_apigatewayv2_stage.main.id
21+
"tags" : aws_apigatewayv2_stage.main.tags
22+
}
23+
}

api_gateway_routes.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
resource "aws_apigatewayv2_route" "debug_route" {
2+
api_id = aws_apigatewayv2_api.main.id
3+
route_key = "GET /debug"
4+
5+
target = "integrations/${aws_apigatewayv2_integration.debug_integration.id}"
6+
}

main.tf

Lines changed: 1 addition & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1 @@
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-
}
1+
// modules here

outputs.tf

Lines changed: 0 additions & 58 deletions
This file was deleted.

providers.tf

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
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+
125
provider "aws" {
226
region = var.aws_region
327

@@ -12,4 +36,3 @@ provider "aws" {
1236
}
1337
}
1438
}
15-

variables.tf

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,3 @@ variable "aws_session_token" {
2020
description = "AWS Secret Key"
2121
type = string
2222
}
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: 0 additions & 25 deletions
This file was deleted.

vpc.tf

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

0 commit comments

Comments
 (0)