Skip to content

Commit 620510c

Browse files
authored
Merge pull request #165 from infrablocks/support_fargat
Add fargate support
2 parents ee8374f + f54550e commit 620510c

21 files changed

+795
-594
lines changed

config/roles/fargate.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
configuration_directory: "%{cwd}/examples/fargate"
3+
state_file: "%{cwd}/state/fargate.tfstate"
4+
vars:
5+
region: "%{hiera('region')}"
6+
7+
vpc_cidr: "%{hiera('vpc_cidr')}"
8+
availability_zones: "%{hiera('availability_zones')}"
9+
private_network_cidr: "%{hiera('private_network_cidr')}"
10+
11+
component: "%{hiera('component')}"
12+
deployment_identifier: "%{hiera('deployment_identifier')}"
13+
14+
domain_name: "%{hiera('domain_name')}"
15+
public_zone_id: "%{hiera('public_zone_id')}"
16+
private_zone_id: "%{hiera('private_zone_id')}"
17+
18+
cluster_name: "%{hiera('cluster_name')}"
19+
cluster_instance_ssh_public_key_path: "%{hiera('cluster_instance_ssh_public_key_path')}"
20+
cluster_instance_type: "%{hiera('cluster_instance_type')}"
21+
22+
cluster_minimum_size: "%{hiera('cluster_minimum_size')}"
23+
cluster_maximum_size: "%{hiera('cluster_maximum_size')}"
24+
cluster_desired_capacity: "%{hiera('cluster_desired_capacity')}"

examples/fargate/.terraform.lock.hcl

Lines changed: 46 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[
2+
{
3+
"name": "${name}",
4+
"image": "${image}",
5+
"memory": 200,
6+
"essential": true,
7+
"command": ${command},
8+
"portMappings": [
9+
{
10+
"containerPort": ${port},
11+
"hostPort": ${port}
12+
}
13+
],
14+
"logConfiguration": {
15+
"logDriver": "awslogs",
16+
"options": {
17+
"awslogs-group": "${log_group}",
18+
"awslogs-region": "${region}",
19+
"awslogs-stream-prefix": "prefix"
20+
}
21+
}
22+
}
23+
]

examples/fargate/ecs-service.tf

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
module "ecs_service" {
2+
source = "./../../"
3+
4+
component = var.component
5+
deployment_identifier = var.deployment_identifier
6+
7+
service_task_container_definitions = file("${path.module}/container-definitions/service.json.tpl")
8+
9+
region = var.region
10+
11+
subnet_ids = module.base_network.private_subnet_ids
12+
13+
service_name = "web-proxy"
14+
service_image = "nginx"
15+
service_command = ["nginx", "-g", "daemon off;"]
16+
service_port = 80
17+
18+
use_fargate = true
19+
service_task_cpu = "256"
20+
service_task_memory = "512"
21+
service_task_operating_system_family = "LINUX"
22+
23+
attach_to_load_balancer = false
24+
# service_elb_name = module.ecs_load_balancer.name
25+
26+
ecs_cluster_id = module.ecs_cluster.cluster_id
27+
ecs_cluster_service_role_arn = module.ecs_cluster.service_role_arn
28+
}

examples/fargate/outputs.tf

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
output "vpc_id" {
2+
value = module.base_network.vpc_id
3+
}
4+
5+
output "vpc_cidr" {
6+
value = module.base_network.vpc_cidr
7+
}
8+
9+
output "public_subnet_ids" {
10+
value = module.base_network.public_subnet_ids
11+
}
12+
13+
output "private_subnet_ids" {
14+
value = module.base_network.private_subnet_ids
15+
}
16+
17+
output "load_balancer_name" {
18+
value = module.ecs_load_balancer.name
19+
}
20+
21+
output "cluster_id" {
22+
value = module.ecs_cluster.cluster_id
23+
}
24+
25+
output "cluster_name" {
26+
value = module.ecs_cluster.cluster_name
27+
}
28+
29+
output "autoscaling_group_name" {
30+
value = module.ecs_cluster.autoscaling_group_name
31+
}
32+
33+
output "instance_role_arn" {
34+
value = module.ecs_cluster.instance_role_arn
35+
}
36+
37+
output "instance_role_id" {
38+
value = module.ecs_cluster.instance_role_id
39+
}
40+
41+
output "service_role_arn" {
42+
value = module.ecs_cluster.service_role_arn
43+
}
44+
45+
output "service_role_id" {
46+
value = module.ecs_cluster.service_role_id
47+
}
48+
49+
output "task_definition_arn" {
50+
value = module.ecs_service.task_definition_arn
51+
}
52+
53+
output "log_group" {
54+
value = module.ecs_service.log_group
55+
}
56+
57+
output "security_group_id" {
58+
value = module.ecs_service.security_group_id
59+
}

examples/fargate/prerequisites.tf

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
module "base_network" {
2+
source = "infrablocks/base-networking/aws"
3+
version = "4.1.0-rc.5"
4+
5+
region = var.region
6+
vpc_cidr = var.vpc_cidr
7+
availability_zones = var.availability_zones
8+
9+
component = var.component
10+
deployment_identifier = var.deployment_identifier
11+
12+
private_zone_id = var.private_zone_id
13+
14+
include_nat_gateways = "no"
15+
}
16+
17+
module "acm_certificate" {
18+
source = "infrablocks/acm-certificate/aws"
19+
version = "1.2.0-rc.1"
20+
21+
domain_name = "*.${var.domain_name}"
22+
domain_zone_id = var.public_zone_id
23+
subject_alternative_name_zone_id = var.public_zone_id
24+
25+
providers = {
26+
aws.certificate = aws
27+
aws.domain_validation = aws
28+
aws.san_validation = aws
29+
}
30+
}
31+
32+
module "ecs_cluster" {
33+
source = "infrablocks/ecs-cluster/aws"
34+
version = "6.1.0-rc.11"
35+
36+
region = var.region
37+
vpc_id = module.base_network.vpc_id
38+
subnet_ids = module.base_network.private_subnet_ids
39+
default_ingress_cidrs = [var.private_network_cidr]
40+
41+
component = var.component
42+
deployment_identifier = var.deployment_identifier
43+
44+
cluster_name = var.cluster_name
45+
cluster_instance_ssh_public_key_path = var.cluster_instance_ssh_public_key_path
46+
cluster_instance_type = var.cluster_instance_type
47+
48+
cluster_minimum_size = var.cluster_minimum_size
49+
cluster_maximum_size = var.cluster_maximum_size
50+
cluster_desired_capacity = var.cluster_desired_capacity
51+
52+
additional_capacity_providers = ["FARGATE"]
53+
}
54+
55+
module "ecs_load_balancer" {
56+
source = "infrablocks/ecs-load-balancer/aws"
57+
version = "3.1.0-rc.7"
58+
59+
component = var.component
60+
deployment_identifier = var.deployment_identifier
61+
62+
region = var.region
63+
vpc_id = module.base_network.vpc_id
64+
subnet_ids = module.base_network.public_subnet_ids
65+
66+
service_name = "web-proxy"
67+
service_port = 80
68+
69+
service_certificate_arn = module.acm_certificate.certificate_arn
70+
71+
domain_name = var.domain_name
72+
public_zone_id = var.public_zone_id
73+
private_zone_id = var.private_zone_id
74+
75+
allow_cidrs = ["0.0.0.0/0"]
76+
77+
expose_to_public_internet = "yes"
78+
include_public_dns_record = "yes"
79+
}

examples/fargate/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 = var.region
3+
}

examples/fargate/terraform.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
terraform {
2+
required_version = ">= 1.1"
3+
4+
required_providers {
5+
aws = {
6+
source = "hashicorp/aws"
7+
version = "4.59"
8+
}
9+
}
10+
}

examples/fargate/variables.tf

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
variable "region" {}
2+
variable "vpc_cidr" {}
3+
variable "availability_zones" {
4+
type = list(string)
5+
}
6+
variable "private_network_cidr" {}
7+
8+
variable "component" {}
9+
variable "deployment_identifier" {}
10+
11+
variable "domain_name" {}
12+
variable "public_zone_id" {}
13+
variable "private_zone_id" {}
14+
15+
variable "cluster_name" {}
16+
variable "cluster_instance_ssh_public_key_path" {}
17+
variable "cluster_instance_type" {}
18+
19+
variable "cluster_minimum_size" {}
20+
variable "cluster_maximum_size" {}
21+
variable "cluster_desired_capacity" {}

service.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ resource "aws_ecs_service" "service" {
33
cluster = var.ecs_cluster_id
44
task_definition = var.always_use_latest_task_definition ? aws_ecs_task_definition.service.arn_without_revision : aws_ecs_task_definition.service.arn
55
desired_count = var.service_desired_count
6-
iam_role = (var.attach_to_load_balancer && var.service_task_network_mode != "awsvpc") ? var.ecs_cluster_service_role_arn : null
6+
iam_role = (!var.use_fargate && var.attach_to_load_balancer && var.service_task_network_mode != "awsvpc") ? var.ecs_cluster_service_role_arn : null
77

88
deployment_maximum_percent = var.service_deployment_maximum_percent
99
deployment_minimum_healthy_percent = var.service_deployment_minimum_healthy_percent
@@ -17,7 +17,7 @@ resource "aws_ecs_service" "service" {
1717
wait_for_steady_state = var.wait_for_steady_state
1818

1919
dynamic "network_configuration" {
20-
for_each = var.service_task_network_mode == "awsvpc" ? [var.subnet_ids] : []
20+
for_each = var.use_fargate || var.service_task_network_mode == "awsvpc" ? [var.subnet_ids] : []
2121

2222
content {
2323
subnets = network_configuration.value

spec/integration/full_spec.rb renamed to spec/integration/basic_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
require 'spec_helper'
44

5-
describe 'full' do
5+
describe 'basic' do
66
let(:component) do
77
var(role: :basic, name: 'component')
88
end

0 commit comments

Comments
 (0)