mirror of
https://github.com/farcasclaudiu/terraform-course.git
synced 2026-06-28 21:01:57 +03:00
+29
-27
@@ -1,33 +1,35 @@
|
||||
# app
|
||||
|
||||
data "template_file" "myapp-task-definition-template" {
|
||||
template = "${file("templates/app.json.tpl")}"
|
||||
vars {
|
||||
REPOSITORY_URL = "${replace("${aws_ecr_repository.myapp.repository_url}", "https://", "")}"
|
||||
APP_VERSION = "${var.MYAPP_VERSION}"
|
||||
template = file("templates/app.json.tpl")
|
||||
vars = {
|
||||
REPOSITORY_URL = replace(aws_ecr_repository.myapp.repository_url, "https://", "")
|
||||
APP_VERSION = var.MYAPP_VERSION
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_ecs_task_definition" "myapp-task-definition" {
|
||||
family = "myapp"
|
||||
container_definitions = "${data.template_file.myapp-task-definition-template.rendered}"
|
||||
container_definitions = data.template_file.myapp-task-definition-template.rendered
|
||||
}
|
||||
|
||||
resource "aws_ecs_service" "myapp-service" {
|
||||
count = "${var.MYAPP_SERVICE_ENABLE}"
|
||||
name = "myapp"
|
||||
cluster = "${aws_ecs_cluster.example-cluster.id}"
|
||||
task_definition = "${aws_ecs_task_definition.myapp-task-definition.arn}"
|
||||
desired_count = 1
|
||||
iam_role = "${aws_iam_role.ecs-service-role.arn}"
|
||||
depends_on = ["aws_iam_policy_attachment.ecs-service-attach1"]
|
||||
count = var.MYAPP_SERVICE_ENABLE
|
||||
name = "myapp"
|
||||
cluster = aws_ecs_cluster.example-cluster.id
|
||||
task_definition = aws_ecs_task_definition.myapp-task-definition.arn
|
||||
desired_count = 1
|
||||
iam_role = aws_iam_role.ecs-service-role.arn
|
||||
depends_on = [aws_iam_policy_attachment.ecs-service-attach1]
|
||||
|
||||
load_balancer {
|
||||
elb_name = "${aws_elb.myapp-elb.name}"
|
||||
elb_name = aws_elb.myapp-elb.name
|
||||
container_name = "myapp"
|
||||
container_port = 3000
|
||||
}
|
||||
lifecycle { ignore_changes = ["task_definition"] }
|
||||
lifecycle {
|
||||
ignore_changes = [task_definition]
|
||||
}
|
||||
}
|
||||
|
||||
# load balancer
|
||||
@@ -35,29 +37,29 @@ resource "aws_elb" "myapp-elb" {
|
||||
name = "myapp-elb"
|
||||
|
||||
listener {
|
||||
instance_port = 3000
|
||||
instance_port = 3000
|
||||
instance_protocol = "http"
|
||||
lb_port = 80
|
||||
lb_protocol = "http"
|
||||
lb_port = 80
|
||||
lb_protocol = "http"
|
||||
}
|
||||
|
||||
health_check {
|
||||
healthy_threshold = 3
|
||||
healthy_threshold = 3
|
||||
unhealthy_threshold = 3
|
||||
timeout = 30
|
||||
target = "HTTP:3000/"
|
||||
interval = 60
|
||||
timeout = 30
|
||||
target = "HTTP:3000/"
|
||||
interval = 60
|
||||
}
|
||||
|
||||
cross_zone_load_balancing = true
|
||||
idle_timeout = 400
|
||||
connection_draining = true
|
||||
cross_zone_load_balancing = true
|
||||
idle_timeout = 400
|
||||
connection_draining = true
|
||||
connection_draining_timeout = 400
|
||||
|
||||
subnets = ["${aws_subnet.main-public-1.id}","${aws_subnet.main-public-2.id}"]
|
||||
security_groups = ["${aws_security_group.myapp-elb-securitygroup.id}"]
|
||||
subnets = [aws_subnet.main-public-1.id, aws_subnet.main-public-2.id]
|
||||
security_groups = [aws_security_group.myapp-elb-securitygroup.id]
|
||||
|
||||
tags {
|
||||
tags = {
|
||||
Name = "myapp-elb"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user