From 9a4e7b406afcea38b802a0ce4c5683d7ad0bb0d3 Mon Sep 17 00:00:00 2001 From: Dave Arnold Date: Wed, 18 Sep 2024 11:24:44 -0700 Subject: [PATCH] Refactor main.tf to add VPC endpoint for ECR and ECS cluster capacity providers --- main.tf | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/main.tf b/main.tf index eb41e30..492aa6b 100644 --- a/main.tf +++ b/main.tf @@ -31,6 +31,41 @@ resource "aws_ecs_cluster" "github-runner" { data "aws_region" "current" {} +data "aws_region" "current" {} + +resource "aws_vpc_endpoint" "ecr" { + for_each = var.create_vpc_endpoint ? toset([ + "com.amazonaws.${data.aws_region.current.name}.ecr.api", + "com.amazonaws.${data.aws_region.current.name}.ecr.dkr" + ]) : toset([]) + vpc_id = var.vpc_id + service_name = each.value + vpc_endpoint_type = "Interface" + + security_group_ids = var.security_groups + private_dns_enabled = true +} + +resource "aws_ecs_cluster_capacity_providers" "fargate" { + cluster_name = aws_ecs_cluster.github-runner.name + + capacity_providers = ["FARGATE"] + + default_capacity_provider_strategy { + base = 1 + weight = 100 + capacity_provider = "FARGATE" + } +} + +locals { + labels = [ + "self-hosted", + "ecs", + "github-runner" + ] +} + module "github-runner" { for_each = toset([for repo in local.all_repos : repo]) source = "HappyPathway/github-runner/ecs"