Skip to content
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

feat: setup aws integration for flint.cloud #211

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions provider/aws/rest_api_flint.example/fargate.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
resource "aws_ecs_task_definition" "backend_flint_example_task" {
family = "backend_flint_example_app_family"

requires_compatibilities = ["FARGATE"]
network_mode = "awsvpc"

memory = "512"
cpu = "256"

execution_role_arn = aws_iam_role.ecs_role.arn

container_definitions = <<EOT
[
{
"name": "flint_example_app_container",
"image": "<your_ecr_repo_url>:latest",
"memory": 512,
"essential": true,
"portMappings": [
{
"containerPort": 8080,
"hostPort": 8080
}
]
}
]
EOT
}

resource "aws_ecs_cluster" "backend_flint_example_cluster" {
name = "backend_flint_example_cluster_flint_example_app"
}

resource "aws_ecs_service" "backend_flint_example_service" {
name = "backend_flint_example_service"

cluster = aws_ecs_cluster.backend_flint_example_cluster.id
task_definition = aws_ecs_task_definition.backend_flint_example_task.arn

launch_type = "FARGATE"
desired_count = 1

network_configuration {
subnets = ["${aws_subnet.public_a.id}", "${aws_subnet.public_b.id}"]
security_groups = ["${aws_security_group.security_group_flint_example_app.id}"]
assign_public_ip = true
}
}
24 changes: 24 additions & 0 deletions provider/aws/rest_api_flint.example/iam.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
resource "aws_iam_role" "ecs_role" {
name = "ecs_role_flint_example_app"

assume_role_policy = <<POLICY
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Principal": {
"Service": "ecs-tasks.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
POLICY
}

resource "aws_iam_role_policy_attachment" "ecs_policy_attachment" {
role = aws_iam_role.ecs_role.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy"
}
47 changes: 47 additions & 0 deletions provider/aws/rest_api_flint.example/network.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
resource "aws_vpc" "vpc_flint_example_app" {
cidr_block = "10.0.0.0/16"
enable_dns_hostnames = true
enable_dns_support = true
}

resource "aws_subnet" "public_a" {
vpc_id = aws_vpc.vpc_flint_example_app.id
cidr_block = "10.0.1.0/24"
availability_zone = "${var.aws_region}a"
}

resource "aws_subnet" "public_b" {
vpc_id = aws_vpc.vpc_flint_example_app.id
cidr_block = "10.0.2.0/24"
availability_zone = "${var.aws_region}b"
}

resource "aws_internet_gateway" "internet_gateway" {
vpc_id = aws_vpc.vpc_flint_example_app.id
}

resource "aws_route" "internet_access" {
route_table_id = aws_vpc.vpc_flint_example_app.main_route_table_id
destination_cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.internet_gateway.id
}

resource "aws_security_group" "security_group_flint_example_app" {
name = "security_group_flint_example_app"
description = "Allow TLS inbound traffic on port 80 (http)"
vpc_id = aws_vpc.vpc_flint_example_app.id

ingress {
from_port = 80
to_port = 3000
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}

egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
8 changes: 8 additions & 0 deletions provider/aws/rest_api_flint.example/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
variable "aws_region" {
default = "eu-west-1"
description = "Which region should the resources be deployed into?"
}

provider "aws" {
region = var.aws_region
}
48 changes: 48 additions & 0 deletions provider/aws/rest_api_gcbm/fargate.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
resource "aws_ecs_task_definition" "backend_gcbm_api_task" {
family = "backend_gcbm_api_app_family"

requires_compatibilities = ["FARGATE"]
network_mode = "awsvpc"

memory = "512"
cpu = "256"

execution_role_arn = aws_iam_role.ecs_role.arn

container_definitions = <<EOT
[
{
"name": "gcbm_api_app_container",
"image": "<your_ecr_repo_url>:latest",
"memory": 512,
"essential": true,
"portMappings": [
{
"containerPort": 8080,
"hostPort": 8080
}
]
}
]
EOT
}

resource "aws_ecs_cluster" "backend_gcbm_api_cluster" {
name = "backend_gcbm_api_cluster_gcbm_api_app"
}

resource "aws_ecs_service" "backend_gcbm_api_service" {
name = "backend_gcbm_api_service"

cluster = aws_ecs_cluster.backend_gcbm_api_cluster.id
task_definition = aws_ecs_task_definition.backend_gcbm_api_task.arn

launch_type = "FARGATE"
desired_count = 1

network_configuration {
subnets = ["${aws_subnet.public_a.id}", "${aws_subnet.public_b.id}"]
security_groups = ["${aws_security_group.security_group_gcbm_api_app.id}"]
assign_public_ip = true
}
}
24 changes: 24 additions & 0 deletions provider/aws/rest_api_gcbm/iam.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
resource "aws_iam_role" "ecs_role" {
name = "ecs_role_gcbm_api_app"

assume_role_policy = <<POLICY
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Principal": {
"Service": "ecs-tasks.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
POLICY
}

resource "aws_iam_role_policy_attachment" "ecs_policy_attachment" {
role = aws_iam_role.ecs_role.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy"
}
47 changes: 47 additions & 0 deletions provider/aws/rest_api_gcbm/network.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
resource "aws_vpc" "vpc_gcbm_api_app" {
cidr_block = "10.0.0.0/16"
enable_dns_hostnames = true
enable_dns_support = true
}

resource "aws_subnet" "public_a" {
vpc_id = aws_vpc.vpc_gcbm_api_app.id
cidr_block = "10.0.1.0/24"
availability_zone = "${var.aws_region}a"
}

resource "aws_subnet" "public_b" {
vpc_id = aws_vpc.vpc_gcbm_api_app.id
cidr_block = "10.0.2.0/24"
availability_zone = "${var.aws_region}b"
}

resource "aws_internet_gateway" "internet_gateway" {
vpc_id = aws_vpc.vpc_gcbm_api_app.id
}

resource "aws_route" "internet_access" {
route_table_id = aws_vpc.vpc_gcbm_api_app.main_route_table_id
destination_cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.internet_gateway.id
}

resource "aws_security_group" "security_group_gcbm_api_app" {
name = "security_group_gcbm_api_app"
description = "Allow TLS inbound traffic on port 80 (http)"
vpc_id = aws_vpc.vpc_gcbm_api_app.id

ingress {
from_port = 80
to_port = 3000
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}

egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
8 changes: 8 additions & 0 deletions provider/aws/rest_api_gcbm/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
variable "aws_region" {
default = "eu-west-1"
description = "Which region should the resources be deployed into?"
}

provider "aws" {
region = var.aws_region
}