Skip to content

geekcell/terraform-aws-ecs-codedeploy-appspec

Repository files navigation

Geek Cell GmbH

Code Quality

License GitHub release (latest tag) Release Validate Lint

Security

Infrastructure Tests

Cloud

Infrastructure Tests Infrastructure Tests Infrastructure Tests Infrastructure Tests Infrastructure Tests

Container

Infrastructure Tests Infrastructure Tests Infrastructure Tests Infrastructure Tests

Data protection

Infrastructure Tests Infrastructure Tests Infrastructure Tests Infrastructure Tests Infrastructure Tests Infrastructure Tests Infrastructure Tests

Terraform AWS ECS CodeDeploy AppSpec Module

Terraform module which renders a valid AppSpec file from a aws_ecs_service and, optionally, stores it in the SSM Parameter store. Why?

For deployments with CODE_DEPLOY, an AppSpec file with the LoadBalancer info is required. The file is stored in the SSM Parameter Store and can be fetched during the deployment to allow us to change these parameters after the service has already been created. Structure is defined here:

https://docs.aws.amazon.com/codedeploy/latest/userguide/reference-appspec-file-example.html#appspec-file-example-ecs

Inputs

Name Description Type Default Required
aws_ecs_service A complete aws_ecs_service resource to extract the inputs from. any n/a yes
description Description of the SSM Parameter. string null no
enable_ssm_parameter Create an AWS SSM Parameter for the rendered AppSpec. bool true no
name Name of the SSM Parameter. string null no
ssm_parameter_format The output format for rendered AppSpec file to write to SSM. Can be json or yaml. string "json" no
tags Tags to add to the SSM Parameter. map(any) {} no

Outputs

Name Description
appspec The AppSpec definition as HCL object.
appspec_json The AppSpec definition as JSON string.
appspec_yaml The AppSpec definition as YAML string.
ssm_parameter_arn The ARN of the SSM parameter containing the AppSpec definition.

Providers

Name Version
aws >= 4.36

Resources

  • resource.aws_ssm_parameter.main (main.tf#44)

Examples

Min

resource "aws_ecs_service" "example" {
  name             = "example"
  task_definition  = "some-task-definition:1"
  platform_version = "LATEST"

  load_balancer {
    container_name = "app"
    container_port = 80
  }

  network_configuration {
    subnets          = ["subnet-12345678", "subnet-87654321"]
    security_groups  = ["sg-12345678"]
    assign_public_ip = false
  }
}

module "example" {
  source = "../../"

  aws_ecs_service = aws_ecs_service.example
}