Last active
March 16, 2020 10:17
-
-
Save AndrewBestbier/6c4c3ed9c273229d61405ab1001a40b0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
resource "aws_ecs_service" "my_first_service" { | |
name = "my-first-service" # Naming our first service | |
cluster = "${aws_ecs_cluster.my_cluster.id}" # Referencing our created Cluster | |
task_definition = "${aws_ecs_task_definition.my_first_task.arn}" # Referencing the task our service will spin up | |
launch_type = "FARGATE" | |
desired_count = 3 # Setting the number of containers to 3 | |
load_balancer { | |
target_group_arn = "${aws_lb_target_group.target_group.arn}" # Referencing our target group | |
container_name = "${aws_ecs_task_definition.my_first_task.family}" | |
container_port = 3000 # Specifying the container port | |
} | |
network_configuration { | |
subnets = ["${aws_default_subnet.default_subnet_a.id}", "${aws_default_subnet.default_subnet_b.id}", "${aws_default_subnet.default_subnet_c.id}"] | |
assign_public_ip = true # Providing our containers with public IPs | |
security_groups = ["${aws_security_group.service_security_group.id}"] # Setting the security group | |
} | |
} | |
resource "aws_security_group" "service_security_group" { | |
ingress { | |
from_port = 0 | |
to_port = 0 | |
protocol = "-1" | |
# Only allowing traffic in from the load balancer security group | |
security_groups = ["${aws_security_group.load_balancer_security_group.id}"] | |
} | |
egress { | |
from_port = 0 # Allowing any incoming port | |
to_port = 0 # Allowing any outgoing port | |
protocol = "-1" # Allowing any outgoing protocol | |
cidr_blocks = ["0.0.0.0/0"] # Allowing traffic out to all IP addresses | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment