Created
December 7, 2018 14:00
-
-
Save jmlrt/180bde0ab1a1ce239a642b94ffd707e6 to your computer and use it in GitHub Desktop.
ECS Fargate sample topology
This file contains 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
provider "aws" { | |
region = "${var.region}" | |
} | |
resource "aws_ecs_cluster" "ecs_cluster" { | |
name = "${var.cluster_name}" | |
} | |
resource "aws_ecs_task_definition" "task" { | |
family = "${var.service_name}" | |
container_definitions = "${data.template_file.task_def.rendered}" | |
cpu = "${var.cpu}" | |
memory = "${var.memory}" | |
requires_compatibilities = ["FARGATE"] | |
network_mode = "awsvpc" | |
execution_role_arn = "${var.iam_role_arn}" | |
} | |
resource "aws_ecs_service" "service" { | |
name = "${var.service_name}" | |
cluster = "${aws_ecs_cluster.ecs_cluster.name}" | |
task_definition = "${aws_ecs_task_definition.task.arn}" | |
desired_count = 1 | |
launch_type = "FARGATE" | |
network_configuration { | |
assign_public_ip = "true" | |
security_groups = ["${var.security_group}"] | |
subnets = ["${var.subnet}"] | |
} | |
} | |
data "template_file" "task_def" { | |
template = "${file("task_def.json")}" | |
vars { | |
name = "${var.service_name}" | |
image = "${var.image}" | |
port = "${var.port}" | |
} | |
} |
This file contains 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
[ | |
{ | |
"name": "${name}", | |
"image": "${image}", | |
"networkMode": "awsvpc", | |
"portMappings": [ | |
{ | |
"containerPort": ${port}, | |
"hostPort": ${port} | |
} | |
] | |
} | |
] |
This file contains 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
variable "region" { | |
default = "us-east-1" | |
} | |
variable "cluster_name" { | |
default = "test" | |
} | |
variable "service_name" { | |
default = "test" | |
} | |
variable "cpu" { | |
default = 256 | |
} | |
variable "memory" { | |
default = 512 | |
} | |
variable "image" {} | |
variable "port" {} | |
# AWS REQUIRED RESOURCES | |
variable "iam_role_arn" {} | |
variable "security_group" {} | |
variable "subnet" {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment