Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added container_memory_reservation config and extended container_definitions #37

Merged
merged 2 commits into from
Feb 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,11 @@ If all provided subnets are public (no NAT gateway) then `ecs_service_assign_pub
| certificate\_arn | ARN of certificate issued by AWS ACM. If empty, a new ACM certificate will be created and validated using Route53 DNS | string | `""` | no |
| cidr | The CIDR block for the VPC which will be created if `vpc_id` is not specified | string | `""` | no |
| cloudwatch\_log\_retention\_in\_days | Retention period of Atlantis CloudWatch logs | string | `"7"` | no |
| container\_memory\_reservation | The amount of memory (in MiB) to reserve for the container | string | `"128"` | no |
| create\_route53\_record | Whether to create Route53 record for Atlantis | string | `"true"` | no |
| custom\_container\_definitions | A list of valid container definitions provided as a single valid JSON document. By default, the standard container definition is used. | string | `""` | no |
| custom\_environment\_secrets | List of additional secrets the container will use (list should contain maps with `name` and `valueFrom`) | list | `[]` | no |
| custom\_environment\_variables | List of additional environment variables the container will use (list should contain maps with `name` and `value`) | list | `[]` | no |
| ecs\_service\_assign\_public\_ip | Should be true, if ECS service is using public subnets (more info: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_cannot_pull_image.html) | string | `"false"` | no |
| ecs\_service\_deployment\_maximum\_percent | The upper limit (as a percentage of the service's desiredCount) of the number of running tasks that can be running in a service during a deployment | string | `"200"` | no |
| ecs\_service\_deployment\_minimum\_healthy\_percent | The lower limit (as a percentage of the service's desiredCount) of the number of running tasks that must remain running and healthy in a service during a deployment | string | `"50"` | no |
Expand Down
102 changes: 54 additions & 48 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,52 @@ locals {
# Container definitions
container_definitions = "${var.custom_container_definitions == "" ? module.container_definition.json : var.custom_container_definitions}"

container_definition_environment = [
{
name = "ATLANTIS_ALLOW_REPO_CONFIG"
value = "${var.allow_repo_config}"
},
{
name = "ATLANTIS_GITLAB_HOSTNAME"
value = "${var.atlantis_gitlab_hostname}"
},
{
name = "ATLANTIS_LOG_LEVEL"
value = "debug"
},
{
name = "ATLANTIS_PORT"
value = "${var.atlantis_port}"
},
{
name = "ATLANTIS_ATLANTIS_URL"
value = "${local.atlantis_url}"
},
{
name = "ATLANTIS_GH_USER"
value = "${var.atlantis_github_user}"
},
{
name = "ATLANTIS_GITLAB_USER"
value = "${var.atlantis_gitlab_user}"
},
{
name = "ATLANTIS_REPO_WHITELIST"
value = "${join(",", var.atlantis_repo_whitelist)}"
},
]

container_definition_secrets = [
{
name = "${local.secret_name_key}"
valueFrom = "${local.secret_name_value_from}"
},
{
name = "${local.secret_webhook_key}"
valueFrom = "${var.webhook_ssm_parameter_name}"
},
]

tags = "${merge(map("Name", var.name), var.tags)}"
}

Expand Down Expand Up @@ -315,10 +361,9 @@ module "container_definition" {
container_name = "${var.name}"
container_image = "${local.atlantis_image}"

container_cpu = "${var.ecs_task_cpu}"
container_memory = "${var.ecs_task_memory}"

// container_memory_reservation = "${var.ecs_task_memory_reservation}"
container_cpu = "${var.ecs_task_cpu}"
container_memory = "${var.ecs_task_memory}"
container_memory_reservation = "${var.container_memory_reservation}"

port_mappings = [
{
Expand All @@ -327,57 +372,18 @@ module "container_definition" {
protocol = "tcp"
},
]

log_options = [
{
"awslogs-region" = "${data.aws_region.current.name}"
"awslogs-group" = "${aws_cloudwatch_log_group.atlantis.name}"
"awslogs-stream-prefix" = "ecs"
},
]
environment = [
{
name = "ATLANTIS_ALLOW_REPO_CONFIG"
value = "${var.allow_repo_config}"
},
{
name = "ATLANTIS_GITLAB_HOSTNAME"
value = "${var.atlantis_gitlab_hostname}"
},
{
name = "ATLANTIS_LOG_LEVEL"
value = "debug"
},
{
name = "ATLANTIS_PORT"
value = "${var.atlantis_port}"
},
{
name = "ATLANTIS_ATLANTIS_URL"
value = "${local.atlantis_url}"
},
{
name = "ATLANTIS_GH_USER"
value = "${var.atlantis_github_user}"
},
{
name = "ATLANTIS_GITLAB_USER"
value = "${var.atlantis_gitlab_user}"
},
{
name = "ATLANTIS_REPO_WHITELIST"
value = "${join(",", var.atlantis_repo_whitelist)}"
},
]
secrets = [
{
name = "${local.secret_name_key}"
valueFrom = "${local.secret_name_value_from}"
},
{
name = "${local.secret_webhook_key}"
valueFrom = "${var.webhook_ssm_parameter_name}"
},
]

environment = ["${concat(local.container_definition_environment, var.custom_environment_variables)}"]

secrets = ["${concat(local.container_definition_secrets, var.custom_environment_secrets)}"]
}

resource "aws_ecs_task_definition" "atlantis" {
Expand Down
15 changes: 15 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ variable "ecs_task_memory" {
default = 512
}

variable "container_memory_reservation" {
description = "The amount of memory (in MiB) to reserve for the container"
default = 128
}

variable "custom_container_definitions" {
description = "A list of valid container definitions provided as a single valid JSON document. By default, the standard container definition is used."
default = ""
Expand Down Expand Up @@ -206,3 +211,13 @@ variable "atlantis_gitlab_hostname" {
description = "Gitlab server hostname, defaults to gitlab.com"
default = "gitlab.com"
}

variable "custom_environment_secrets" {
description = "List of additional secrets the container will use (list should contain maps with `name` and `valueFrom`)"
default = []
}

variable "custom_environment_variables" {
description = "List of additional environment variables the container will use (list should contain maps with `name` and `value`)"
default = []
}