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

Update EFS & ECS components to allow using EFS in ECS #979

Merged
merged 3 commits into from
Feb 20, 2024
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
4 changes: 3 additions & 1 deletion modules/ecs-service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ This will create a CNAME record in the `acme.com` hosted zone that points `echo.

### EFS

EFS is supported by `ecs-service`. You can use either `efs_volumes` or `efs_component_volumes` in your task definition.
EFS is supported by this ecs service, you can use either `efs_volumes` or `efs_component_volumes` in your task definition.


This example shows how to use `efs_component_volumes` which remote looks up efs component and uses the `efs_id` to mount the volume.
And how to use `efs_volumes`
Expand Down Expand Up @@ -407,6 +408,7 @@ components:
| <a name="input_tags"></a> [tags](#input\_tags) | Additional tags (e.g. `{'BusinessUnit': 'XYZ'}`).<br>Neither the tag keys nor the tag values will be modified by this module. | `map(string)` | `{}` | no |
| <a name="input_task"></a> [task](#input\_task) | Feed inputs into ecs\_alb\_service\_task module | <pre>object({<br> task_cpu = optional(number)<br> task_memory = optional(number)<br> task_role_arn = optional(string, "")<br> pid_mode = optional(string, null)<br> ipc_mode = optional(string, null)<br> network_mode = optional(string)<br> propagate_tags = optional(string)<br> assign_public_ip = optional(bool, false)<br> use_alb_security_groups = optional(bool, true)<br> launch_type = optional(string, "FARGATE")<br> scheduling_strategy = optional(string, "REPLICA")<br> capacity_provider_strategies = optional(list(object({<br> capacity_provider = string<br> weight = number<br> base = number<br> })), [])<br><br> deployment_minimum_healthy_percent = optional(number, null)<br> deployment_maximum_percent = optional(number, null)<br> desired_count = optional(number, 0)<br> min_capacity = optional(number, 1)<br> max_capacity = optional(number, 2)<br> wait_for_steady_state = optional(bool, true)<br> circuit_breaker_deployment_enabled = optional(bool, true)<br> circuit_breaker_rollback_enabled = optional(bool, true)<br><br> ecs_service_enabled = optional(bool, true)<br> bind_mount_volumes = optional(list(object({<br> name = string<br> host_path = string<br> })), [])<br> efs_volumes = optional(list(object({<br> host_path = string<br> name = string<br> efs_volume_configuration = list(object({<br> file_system_id = string<br> root_directory = string<br> transit_encryption = string<br> transit_encryption_port = string<br> authorization_config = list(object({<br> access_point_id = string<br> iam = string<br> }))<br> }))<br> })), [])<br> efs_component_volumes = optional(list(object({<br> host_path = string<br> name = string<br> efs_volume_configuration = list(object({<br> component = optional(string, "efs")<br> tenant = optional(string, null)<br> environment = optional(string, null)<br> stage = optional(string, null)<br><br> root_directory = string<br> transit_encryption = string<br> transit_encryption_port = string<br> authorization_config = list(object({<br> access_point_id = string<br> iam = string<br> }))<br> }))<br> })), [])<br> docker_volumes = optional(list(object({<br> host_path = string<br> name = string<br> docker_volume_configuration = list(object({<br> autoprovision = bool<br> driver = string<br> driver_opts = map(string)<br> labels = map(string)<br> scope = string<br> }))<br> })), [])<br> fsx_volumes = optional(list(object({<br> host_path = string<br> name = string<br> fsx_windows_file_server_volume_configuration = list(object({<br> file_system_id = string<br> root_directory = string<br> authorization_config = list(object({<br> credentials_parameter = string<br> domain = string<br> }))<br> }))<br> })), [])<br> })</pre> | `{}` | no |
| <a name="input_task_enabled"></a> [task\_enabled](#input\_task\_enabled) | Whether or not to use the ECS task module | `bool` | `true` | no |
| <a name="input_task_exec_policy_arns_map"></a> [task\_exec\_policy\_arns\_map](#input\_task\_exec\_policy\_arns\_map) | A map of name to IAM Policy ARNs to attach to the generated task execution role.<br>The names are arbitrary, but must be known at plan time. The purpose of the name<br>is so that changes to one ARN do not cause a ripple effect on the other ARNs.<br>If you cannot provide unique names known at plan time, use `task_exec_policy_arns` instead. | `map(string)` | `{}` | no |
| <a name="input_task_iam_role_component"></a> [task\_iam\_role\_component](#input\_task\_iam\_role\_component) | A component that outputs an iam\_role module as 'role' for adding to the service as a whole. | `string` | `null` | no |
| <a name="input_task_policy_arns"></a> [task\_policy\_arns](#input\_task\_policy\_arns) | The IAM policy ARNs to attach to the ECS task IAM role | `list(string)` | <pre>[<br> "arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly",<br> "arn:aws:iam::aws:policy/AmazonSSMReadOnlyAccess"<br>]</pre> | no |
| <a name="input_task_security_group_component"></a> [task\_security\_group\_component](#input\_task\_security\_group\_component) | A component that outputs security\_group\_id for adding to the service as a whole. | `string` | `null` | no |
Expand Down
4 changes: 3 additions & 1 deletion modules/ecs-service/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ module "container_definition" {
options = tomap({
awslogs-region = var.region,
awslogs-group = local.awslogs_group,
awslogs-stream-prefix = var.name,
awslogs-stream-prefix = coalesce(each.value["name"], each.key),
})
# if we are not using awslogs, we execute this line, which if we have dd enabled, means we are using firelens, so merge that config in.
}) : merge(lookup(each.value, "log_configuration", {}), local.datadog_logconfiguration_firelens)
Expand Down Expand Up @@ -290,6 +290,8 @@ module "ecs_alb_service_task" {
task_role_arn = lookup(local.task, "task_role_arn", one(module.iam_role[*]["outputs"]["role"]["arn"]))
capacity_provider_strategies = lookup(local.task, "capacity_provider_strategies")

task_exec_policy_arns_map = var.task_exec_policy_arns_map

efs_volumes = local.efs_volumes
docker_volumes = lookup(local.task, "docker_volumes", [])
fsx_volumes = lookup(local.task, "fsx_volumes", [])
Expand Down
11 changes: 11 additions & 0 deletions modules/ecs-service/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -568,3 +568,14 @@ variable "task_iam_role_component" {
description = "A component that outputs an iam_role module as 'role' for adding to the service as a whole."
default = null
}

variable "task_exec_policy_arns_map" {
type = map(string)
description = <<-EOT
A map of name to IAM Policy ARNs to attach to the generated task execution role.
The names are arbitrary, but must be known at plan time. The purpose of the name
is so that changes to one ARN do not cause a ripple effect on the other ARNs.
If you cannot provide unique names known at plan time, use `task_exec_policy_arns` instead.
EOT
default = {}
}
11 changes: 10 additions & 1 deletion modules/efs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ components:
name: shared-files
dns_name: shared-files
provisioned_throughput_in_mibps: 10
# additional_security_group_rules:
# - key: "fargate_efs"
# type: "ingress"
# from_port: 2049
# to_port: 2049
# protocol: "tcp"
# description: "Allow Fargate EFS Volume mounts"
# cidr_blocks: ["0.0.0.0/0"]
```

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
Expand All @@ -37,7 +45,7 @@ components:

| Name | Source | Version |
|------|--------|---------|
| <a name="module_efs"></a> [efs](#module\_efs) | cloudposse/efs/aws | 0.32.7 |
| <a name="module_efs"></a> [efs](#module\_efs) | cloudposse/efs/aws | 0.35.0 |
| <a name="module_eks"></a> [eks](#module\_eks) | cloudposse/stack-config/yaml//modules/remote-state | 1.5.0 |
| <a name="module_gbl_dns_delegated"></a> [gbl\_dns\_delegated](#module\_gbl\_dns\_delegated) | cloudposse/stack-config/yaml//modules/remote-state | 1.5.0 |
| <a name="module_iam_roles"></a> [iam\_roles](#module\_iam\_roles) | ../account-map/modules/iam-roles | n/a |
Expand All @@ -57,6 +65,7 @@ components:

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_additional_security_group_rules"></a> [additional\_security\_group\_rules](#input\_additional\_security\_group\_rules) | A list of Security Group rule objects to add to the created security group, in addition to the ones<br>this module normally creates. (To suppress the module's rules, set `create_security_group` to false<br>and supply your own security group via `associated_security_group_ids`.)<br>The keys and values of the objects are fully compatible with the `aws_security_group_rule` resource, except<br>for `security_group_id` which will be ignored, and the optional "key" which, if provided, must be unique and known at "plan" time.<br>To get more info see https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule . | `list(any)` | `[]` | no |
| <a name="input_additional_tag_map"></a> [additional\_tag\_map](#input\_additional\_tag\_map) | Additional key-value pairs to add to each map in `tags_as_list_of_maps`. Not added to `tags` or `id`.<br>This is for some rare cases where resources want additional configuration of tags<br>and therefore take a list of maps with tag key, value, and additional configuration. | `map(string)` | `{}` | no |
| <a name="input_attributes"></a> [attributes](#input\_attributes) | ID element. Additional attributes (e.g. `workers` or `cluster`) to add to `id`,<br>in the order they appear in the list. New attributes are appended to the<br>end of the list. The elements of the list are joined by the `delimiter`<br>and treated as a single ID element. | `list(string)` | `[]` | no |
| <a name="input_context"></a> [context](#input\_context) | Single object for setting entire context at once.<br>See description of individual variables for details.<br>Leave string and numeric variables as `null` to use default value.<br>Individual variable settings (non-null) override settings in context object,<br>except for attributes, tags, and additional\_tag\_map, which are merged. | `any` | <pre>{<br> "additional_tag_map": {},<br> "attributes": [],<br> "delimiter": null,<br> "descriptor_formats": {},<br> "enabled": true,<br> "environment": null,<br> "id_length_limit": null,<br> "label_key_case": null,<br> "label_order": [],<br> "label_value_case": null,<br> "labels_as_tags": [<br> "unset"<br> ],<br> "name": null,<br> "namespace": null,<br> "regex_replace_chars": null,<br> "stage": null,<br> "tags": {},<br> "tenant": null<br>}</pre> | no |
Expand Down
3 changes: 2 additions & 1 deletion modules/efs/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ locals {

module "efs" {
source = "cloudposse/efs/aws"
version = "0.32.7"
version = "0.35.0"

region = var.region
vpc_id = local.vpc_id
subnets = local.private_subnet_ids
allowed_security_group_ids = local.allowed_security_groups
additional_security_group_rules = var.additional_security_group_rules
performance_mode = var.performance_mode
provisioned_throughput_in_mibps = var.provisioned_throughput_in_mibps
throughput_mode = var.throughput_mode
Expand Down
13 changes: 13 additions & 0 deletions modules/efs/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,16 @@ variable "eks_component_names" {
description = "The names of the eks components"
default = ["eks/cluster"]
}

variable "additional_security_group_rules" {
type = list(any)
default = []
description = <<-EOT
A list of Security Group rule objects to add to the created security group, in addition to the ones
this module normally creates. (To suppress the module's rules, set `create_security_group` to false
and supply your own security group via `associated_security_group_ids`.)
The keys and values of the objects are fully compatible with the `aws_security_group_rule` resource, except
for `security_group_id` which will be ignored, and the optional "key" which, if provided, must be unique and known at "plan" time.
To get more info see https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule .
EOT
}
Loading