Skip to content

Commit 28fa4a1

Browse files
committed
simplify terraform setup for now
1 parent 3f9cd4c commit 28fa4a1

10 files changed

Lines changed: 157 additions & 77 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ node_modules
22
package-lock.json
33
coverage
44
junit.xml
5-
terraform/.terraform*
5+
**/.terraform*
66
*tfstate*
77
*.pem

terraform/db/main.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
resource "aws_docdb_cluster" "graphql-example-docdb" {
2+
cluster_identifier = "graphql-example-docdb-cluster"
3+
engine = "docdb"
4+
master_username = "${var.DocDbUser}"
5+
master_password = "${var.DocDbPass}"
6+
backup_retention_period = 5
7+
preferred_backup_window = "07:00-09:00"
8+
skip_final_snapshot = true
9+
}
10+
11+
resource "aws_docdb_cluster_instance" "graphql-example-docdb-instance" {
12+
count = 0
13+
identifier = "graphql-example-docdb-${count.index + 1}"
14+
cluster_identifier = "${aws_docdb_cluster.graphql-example-docdb.id}"
15+
apply_immediately = true
16+
instance_class = "db.t3.medium"
17+
engine = "docdb"
18+
ca_cert_identifier = null
19+
}

terraform/db/outputs.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
output "cluster_name" {
2+
value = try(aws_docdb_cluster.graphql-example-docdb.cluster_identifier, null)
3+
description = "Cluster Identifier."
4+
}
5+
6+
output "arn" {
7+
value = try(aws_docdb_cluster.graphql-example-docdb.arn, null)
8+
description = "Amazon Resource Name (ARN) of the cluster."
9+
}
10+
11+
output "writer_endpoint" {
12+
value = try(aws_docdb_cluster.graphql-example-docdb.endpoint, null)
13+
description = "Endpoint of the DocumentDB cluster."
14+
}
15+
16+
output "reader_endpoint" {
17+
value = try(aws_docdb_cluster.graphql-example-docdb.reader_endpoint, null)
18+
description = "A read-only endpoint of the DocumentDB cluster"
19+
}

terraform/db/provider.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
provider "aws" {
2+
region = "us-east-2"
3+
}

terraform/db/variables.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
variable "DocDbUser" {
2+
type = string
3+
}
4+
5+
variable "DocDbPass" {
6+
type = string
7+
}

terraform/ecs.tf

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,71 @@
11
resource "aws_ecs_task_definition" "graphql_server_task" {
2-
family = "graphql_server_example_family"
3-
requires_compatibilities = ["FARGATE"]
4-
network_mode = "awsvpc"
5-
memory = "512"
6-
cpu = "256"
7-
execution_role_arn = "${aws_iam_role.ecs_role.arn}"
8-
9-
container_definitions = <<EOT
2+
family = "graphql_server_example_family"
3+
requires_compatibilities = ["FARGATE"]
4+
network_mode = "awsvpc"
5+
memory = "512"
6+
cpu = "256"
7+
execution_role_arn = aws_iam_role.ecs_role.arn
8+
9+
container_definitions = <<EOT
1010
[
1111
{
1212
"name": "${var.ecr_app_name}",
1313
"image": "${var.ecr_repo_uri}:${var.ecr_container_tag}",
1414
"memory": 512,
1515
"essential": true,
16+
"logConfiguration": {
17+
"logDriver": "awslogs",
18+
"options": {
19+
"awslogs-group": "awslog-${var.ecr_app_name}",
20+
"awslogs-region": "${var.aws_region}",
21+
"awslogs-stream-prefix": "${var.ecr_app_name}"
22+
}
23+
},
1624
"portMappings": [
1725
{
1826
"containerPort": ${var.ecr_container_port},
1927
"hostPort": ${var.ecr_host_port}
2028
}
29+
],
30+
"environment": [
31+
{
32+
"name": "MONGODB_HOST",
33+
"value": "${var.DocDbHost}"
34+
},
35+
{
36+
"name": "MONGODB_USERNAME",
37+
"value": "${var.DocDbUser}"
38+
},
39+
{
40+
"name": "MONGODB_PASSWORD",
41+
"value": "${var.DocDbPass}"
42+
}
2143
]
2244
}
2345
]
2446
EOT
2547
}
2648

2749
resource "aws_ecs_cluster" "graphql_server_cluster" {
28-
name = "graphql_server_example_app"
50+
name = "graphql_server_example_app"
2951
}
3052

3153
resource "aws_ecs_service" "graphql_server_service" {
32-
name = "graphql_server_service"
54+
name = "graphql_server_service"
3355

34-
cluster = "${aws_ecs_cluster.graphql_server_cluster.id}"
35-
task_definition = "${aws_ecs_task_definition.graphql_server_task.arn}"
56+
cluster = aws_ecs_cluster.graphql_server_cluster.id
57+
task_definition = aws_ecs_task_definition.graphql_server_task.arn
3658

37-
launch_type = "FARGATE"
38-
desired_count = 1
59+
launch_type = "FARGATE"
60+
desired_count = 1
3961

40-
network_configuration {
41-
subnets = ["${aws_subnet.public_a.id}"]
42-
security_groups = ["${aws_security_group.security_group_graphql_server_example.id}"]
43-
assign_public_ip = true
44-
}
45-
enable_ecs_managed_tags = true
46-
wait_for_steady_state = true
62+
network_configuration {
63+
subnets = ["${aws_default_subnet.public_a.id}"]
64+
security_groups = ["${aws_security_group.security_group_graphql_server_example.id}"]
65+
assign_public_ip = true
66+
}
67+
enable_ecs_managed_tags = true
68+
wait_for_steady_state = true
4769
}
4870

4971
data "aws_network_interface" "interface_tags" {

terraform/main.tf

Lines changed: 46 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,60 @@
1-
# resource "aws_instance" "ubuntu_graphql_server" {
2-
# ami = "ami-097a2df4ac947655f"
3-
# instance_type = "t2.micro"
4-
# vpc_security_group_ids = [aws_security_group.security_group_graphql_server_example.id]
5-
# subnet_id = aws_subnet.public_a.id
6-
# key_name = "aws-key"
7-
8-
# user_data = file("../scripts/apache-mkdocs.yaml")
9-
10-
# tags = {
11-
# Name = "terraform-aws-ubuntu"
12-
# }
1+
# resource "aws_vpc" "vpc_graphql_server_example" {
2+
# cidr_block = "10.0.0.0/16"
3+
# enable_dns_hostnames = true
4+
# enable_dns_support = true
135
# }
146

15-
resource "aws_vpc" "vpc_graphql_server_example" {
16-
cidr_block = "10.0.0.0/16"
17-
enable_dns_hostnames = true
18-
enable_dns_support = true
7+
resource "aws_default_vpc" "vpc_graphql_server_example" {
8+
tags = {
9+
Name = "Default VPC"
10+
}
1911
}
2012

21-
resource "aws_subnet" "public_a" {
22-
vpc_id = "${aws_vpc.vpc_graphql_server_example.id}"
23-
cidr_block = "10.0.1.0/24"
24-
availability_zone = "${var.aws_region}a"
13+
# resource "aws_subnet" "public_a" {
14+
# vpc_id = "${aws_default_vpc.vpc_graphql_server_example.id}"
15+
# cidr_block = "10.0.1.0/24"
16+
# availability_zone = "${var.aws_region}a"
17+
# }
18+
19+
resource "aws_default_subnet" "public_a" {
20+
availability_zone = "${var.aws_region}a"
21+
tags = {
22+
Name = "Default subnet for ${var.aws_region}a"
23+
}
2524
}
2625

2726
resource "aws_internet_gateway" "internet_gateway" {
28-
vpc_id = "${aws_vpc.vpc_graphql_server_example.id}"
27+
tags = {
28+
Name = "graphql_server_example"
29+
}
2930
}
3031

31-
resource "aws_route" "internet_access" {
32-
route_table_id = "${aws_vpc.vpc_graphql_server_example.main_route_table_id}"
33-
destination_cidr_block = "0.0.0.0/0"
34-
gateway_id = "${aws_internet_gateway.internet_gateway.id}"
35-
}
32+
# resource "aws_route" "internet_access" {
33+
# route_table_id = "${aws_default_vpc.vpc_graphql_server_example.main_route_table_id}"
34+
# destination_cidr_block = "0.0.0.0/0"
35+
# gateway_id = "${aws_internet_gateway.internet_gateway.id}"
36+
# }
3637

3738
resource "aws_security_group" "security_group_graphql_server_example" {
38-
name = "security_group_example_app"
39-
description = "Allow TLS inbound traffic on port 80 (http)"
40-
vpc_id = "${aws_vpc.vpc_graphql_server_example.id}"
41-
42-
ingress {
43-
from_port = 80
44-
to_port = 8080
45-
protocol = "tcp"
46-
cidr_blocks = ["0.0.0.0/0"]
47-
}
48-
49-
egress {
50-
from_port = 0
51-
to_port = 0
52-
protocol = "-1"
53-
cidr_blocks = ["0.0.0.0/0"]
54-
}
55-
56-
tags = {
39+
name = "security_group_example_app"
40+
description = "Allow TLS inbound traffic on port 80 (http)"
41+
vpc_id = aws_default_vpc.vpc_graphql_server_example.id
42+
43+
ingress {
44+
from_port = 80
45+
to_port = 8080
46+
protocol = "tcp"
47+
cidr_blocks = ["0.0.0.0/0"]
48+
}
49+
50+
egress {
51+
from_port = 0
52+
to_port = 0
53+
protocol = "-1"
54+
cidr_blocks = ["0.0.0.0/0"]
55+
}
56+
57+
tags = {
5758
Name = "terraform-aws-${var.ecr_app_name}-sg"
5859
}
5960
}

terraform/provider.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
provider "aws" {
2-
region = "us-east-2"
2+
region = "us-east-2"
33
}

terraform/roles.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ POLICY
1919
}
2020

2121
resource "aws_iam_role_policy_attachment" "ecs_policy_attachment" {
22-
role = "${aws_iam_role.ecs_role.name}"
22+
role = aws_iam_role.ecs_role.name
2323
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy"
2424
}

terraform/variables.tf

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,36 @@
11
variable "aws_region" {
2-
default = "us-east-2"
2+
default = "us-east-2"
33
}
44

55
variable "ecr_repo_uri" {
6-
default = "440744247014.dkr.ecr.us-east-2.amazonaws.com/test/graphql-server-example"
6+
default = "440744247014.dkr.ecr.us-east-2.amazonaws.com/test/graphql-server-example"
77
}
88

99
variable "ecr_container_tag" {
10-
default = "latest"
10+
default = "latest"
1111
}
1212

1313
variable "ecr_app_name" {
14-
default = "graphql-server-example"
14+
default = "graphql-server-example"
1515
}
1616

1717
variable "ecr_container_port" {
18-
default = 8080
18+
default = 8080
1919
}
2020

2121
variable "ecr_host_port" {
22-
default = 8080
22+
default = 8080
2323
}
2424

25-
variable "mongodb_uri" {
26-
default = "mongodb://localhost:27017"
25+
variable "DocDbHost" {
26+
type = string
27+
default = "mongodb://localhost:27017"
28+
}
29+
30+
variable "DocDbUser" {
31+
type = string
32+
}
33+
34+
variable "DocDbPass" {
35+
type = string
2736
}

0 commit comments

Comments
 (0)