terraform-aws-ecs-codepipeline
terraform-aws-ecs-codepipeline copied to clipboard
Making Deploy Stage Optional
what
I create a new variable called deploy_stage_enabled, and then make dynamic the deploy stage of aws_codepipeline bitbucket and aws_codepipeline default
why
It allows you to create images without deploying them, which could be useful for creating dummy images. However, there's a catch-22 situation: when you create a service, you need an initial image that at least responds to the health path. But first, you need to run a pipeline, and the pipeline is not created before the service. Moreover, ECS (specially if you are using EC2) tends to cache images/references to those images, and if you always use the image with the 'latest' tag, you risk using an old image. To avoid this, it's good practice to tag your image twice (with 'latest' and a random tag). The idea behind this was to create a dummy image, pull it from my service module, and then push it with the correct tags to the ECR of the service (thereby making it the base image of the service). Then I would define my container as follows:
data "aws_ecr_image" "service_image" {
repository_name = module.ecr.repository_name
image_tag = "${var.environment}-latest"
depends_on = [
module.ecr
]
}
module "container_definition" {
source = "cloudposse/ecs-container-definition/aws"
version = "0.58.1"
container_name = var.container_name
container_image = "${var.aws_account_id}.dkr.ecr.${var.region}.amazonaws.com/${var.project_name}:${data.aws_ecr_image.service_image.image_tags[1]}"
#container_image = "${var.aws_account_id}.dkr.ecr.${var.region}.amazonaws.com/${var.project_name}:${var.environment}-latest"
container_memory = var.container_memory
container_memory_reservation = var.container_memory_reservation
docker_security_options = var.docker_security_options
container_cpu = var.container_cpu
essential = var.container_essential
readonly_root_filesystem = var.container_readonly_root_filesystem
environment = var.task_environment_variables
secrets = var.task_environment_secret_variables
port_mappings = var.container_port_mappings
log_configuration = {
"logDriver": "awslogs",
"options": {
"awslogs-group": "/ecs/${var.container_name}",
"awslogs-region": "${var.region}",
"awslogs-create-group": "true",
"awslogs-stream-prefix": "ecs"
}
secretOptions = []
}
depends_on = [
module.ecr
]
}
/terratest
@pcartas Hi, can you update the pr so that it passes the tests? otherwise, it is likely to be closed due to staleness.