## Summary
This PR extends the Fleet ECS modules to support:
- configurable Fleet server private key delivery via ecs or iam
- optional fleet_config.command overrides for Fleet task definitions
- caller-managed Fleet server private key secrets via
fleet_config.private_key_secret_arn
It also updates the external vuln scans addon to follow the same
private-key delivery and command behavior, and refreshes the generated
module documentation.
## What changed
- Added fleet_config.private_key_delivery_method with supported values:
- ecs (default): inject the private key as FLEET_SERVER_PRIVATE_KEY
- iam: inject the secret ARN as FLEET_SERVER_PRIVATE_KEY_ARN
- Added validation so only ecs or iam are accepted
- Added fleet_config.command support so callers can override the Fleet
container command when needed
- Added fleet_config.private_key_secret_arn support so callers can
supply an existing Secrets Manager secret instead of having this module
create and populate one
- Updated IAM policy wiring so private-key secret access and private-key
KMS decrypt permissions are granted to the correct role based on the
selected delivery method
- Updated module outputs so fleet_server_private_key_secret_arn returns
the effective ARN whether the secret is module-managed or caller-managed
- Updated addons/external-vuln-scans to consume the same private-key
delivery mode and optional command behavior from the passed fleet_config
- Updated byo-ecs documentation and regenerated README files
## Behavior
### Private key delivery
- ecs mode injects the secret value into the container and uses the ECS
execution role for private-key secret access
- iam mode injects the secret ARN into the container environment and
uses the Fleet task role for private-key secret access
### Command override
- When fleet_config.command is unset, the task definition omits command
- When fleet_config.command is set, the provided command is passed
through to the Fleet container
- This behavior now applies consistently to both the main ECS service
and external vuln scans
### Caller-managed private key secret
- When fleet_config.private_key_secret_arn is unset, the module creates
and populates the Fleet private key secret
- When fleet_config.private_key_secret_arn is set, the module uses the
provided secret ARN and does not create the secret, secret version, or
generated random value
## KMS note for external secrets
If a caller-managed private-key secret uses a CMK, the caller must also
provide the existing private-key KMS ARN input so the correct role
receives decrypt permissions for the selected delivery mode.
## Validation
Validated successfully with:
- terraform validate -no-color at repo root
- terraform validate -no-color in byo-vpc
- terraform validate -no-color in byo-vpc/byo-db
- terraform validate -no-color in byo-vpc/byo-db/byo-ecs
Also verified that existing module-managed private-key resources plan as
non-destructive state-address moves when transitioning to the new
counted resources:
- 0 to add
- 0 to change
- 0 to destroy
55 lines
21 KiB
Markdown
55 lines
21 KiB
Markdown
## Requirements
|
|
|
|
| Name | Version |
|
|
|------|---------|
|
|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.12.0 |
|
|
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 6.37.0 |
|
|
|
|
## Providers
|
|
|
|
| Name | Version |
|
|
|------|---------|
|
|
| <a name="provider_aws"></a> [aws](#provider\_aws) | 6.38.0 |
|
|
|
|
## Modules
|
|
|
|
| Name | Source | Version |
|
|
|------|--------|---------|
|
|
| <a name="module_alb"></a> [alb](#module\_alb) | terraform-aws-modules/alb/aws | 9.17.0 |
|
|
| <a name="module_cluster"></a> [cluster](#module\_cluster) | terraform-aws-modules/ecs/aws | 7.4.0 |
|
|
| <a name="module_ecs"></a> [ecs](#module\_ecs) | ./byo-ecs | n/a |
|
|
|
|
## Resources
|
|
|
|
| Name | Type |
|
|
|------|------|
|
|
| [aws_kms_alias.cluster_cloudwatch_log_group](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/kms_alias) | resource |
|
|
| [aws_kms_alias.fargate_ephemeral_storage](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/kms_alias) | resource |
|
|
| [aws_kms_key.cluster_cloudwatch_log_group](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/kms_key) | resource |
|
|
| [aws_kms_key.fargate_ephemeral_storage](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/kms_key) | resource |
|
|
| [aws_security_group.alb](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group) | resource |
|
|
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
|
|
| [aws_iam_policy_document.cluster_cloudwatch_log_group_kms](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
|
|
| [aws_iam_policy_document.fargate_ephemeral_storage_kms](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
|
|
| [aws_partition.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/partition) | data source |
|
|
| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |
|
|
|
|
## Inputs
|
|
|
|
| Name | Description | Type | Default | Required |
|
|
|------|-------------|------|---------|:--------:|
|
|
| <a name="input_alb_config"></a> [alb\_config](#input\_alb\_config) | n/a | <pre>object({<br/> name = optional(string, "fleet")<br/> subnets = list(string)<br/> security_groups = optional(list(string), [])<br/> access_logs = optional(map(string), {})<br/> certificate_arn = string<br/> allowed_cidrs = optional(list(string), ["0.0.0.0/0"])<br/> allowed_ipv6_cidrs = optional(list(string), ["::/0"])<br/> egress_cidrs = optional(list(string), ["0.0.0.0/0"])<br/> egress_ipv6_cidrs = optional(list(string), ["::/0"])<br/> fleet_target_group = optional(object({<br/> protocol = optional(string, "HTTP")<br/> port = optional(number, 80)<br/> target_type = optional(string, "ip")<br/> create_attachment = optional(bool, false)<br/> health_check = optional(object({<br/> path = optional(string, "/healthz")<br/> matcher = optional(string, "200")<br/> port = optional(string)<br/> timeout = optional(number, 10)<br/> interval = optional(number, 15)<br/> healthy_threshold = optional(number, 5)<br/> unhealthy_threshold = optional(number, 5)<br/> }), {})<br/> }), {})<br/> extra_target_groups = optional(any, [])<br/> https_listener_rules = optional(any, [])<br/> https_overrides = optional(any, {})<br/> xff_header_processing_mode = optional(string, null)<br/> tls_policy = optional(string, "ELBSecurityPolicy-TLS13-1-2-2021-06")<br/> idle_timeout = optional(number, 905)<br/> internal = optional(bool, false)<br/> enable_deletion_protection = optional(bool, false)<br/> })</pre> | n/a | yes |
|
|
| <a name="input_ecs_cluster"></a> [ecs\_cluster](#input\_ecs\_cluster) | The config for the terraform-aws-modules/ecs/aws module. For published KMS blocks, legacy `enabled` is deprecated and still accepted; prefer `cmk_enabled`. | <pre>object({<br/> autoscaling_capacity_providers = optional(any, {})<br/> cluster_configuration = optional(any, {<br/> execute_command_configuration = {<br/> logging = "OVERRIDE"<br/> log_configuration = {<br/> cloud_watch_log_group_name = "/aws/ecs/aws-ec2"<br/> }<br/> }<br/> })<br/> cluster_name = optional(string, "fleet")<br/> cloudwatch_log_group = optional(object({<br/> create = optional(bool, true)<br/> retention_in_days = optional(number, 90)<br/> kms = optional(object({<br/> cmk_enabled = optional(bool, null)<br/> enabled = optional(bool, null)<br/> kms_key_arn = optional(string, null)<br/> kms_alias = optional(string, "fleet-ecs-cluster-logs")<br/> extra_kms_policies = optional(list(any), [])<br/> }), {<br/> cmk_enabled = null<br/> enabled = null<br/> kms_key_arn = null<br/> kms_alias = "fleet-ecs-cluster-logs"<br/> extra_kms_policies = []<br/> })<br/> }), {<br/> create = true<br/> retention_in_days = 90<br/> kms = {<br/> cmk_enabled = null<br/> enabled = null<br/> kms_key_arn = null<br/> kms_alias = "fleet-ecs-cluster-logs"<br/> extra_kms_policies = []<br/> }<br/> })<br/> cluster_settings = optional(any, {<br/> "name" : "containerInsights",<br/> "value" : "enabled",<br/> })<br/> create = optional(bool, true)<br/> default_capacity_provider_use_fargate = optional(bool, true)<br/> fargate_capacity_providers = optional(any, {<br/> FARGATE = {<br/> default_capacity_provider_strategy = {<br/> weight = 100<br/> }<br/> }<br/> FARGATE_SPOT = {<br/> default_capacity_provider_strategy = {<br/> weight = 0<br/> }<br/> }<br/> })<br/> tags = optional(map(string))<br/> })</pre> | <pre>{<br/> "autoscaling_capacity_providers": {},<br/> "cloudwatch_log_group": {<br/> "create": true,<br/> "kms": {<br/> "cmk_enabled": null,<br/> "enabled": null,<br/> "kms_alias": "fleet-ecs-cluster-logs",<br/> "kms_key_arn": null<br/> },<br/> "retention_in_days": 90<br/> },<br/> "cluster_configuration": {<br/> "execute_command_configuration": {<br/> "log_configuration": {<br/> "cloud_watch_log_group_name": "/aws/ecs/aws-ec2"<br/> },<br/> "logging": "OVERRIDE"<br/> }<br/> },<br/> "cluster_name": "fleet",<br/> "cluster_settings": {<br/> "name": "containerInsights",<br/> "value": "enabled"<br/> },<br/> "create": true,<br/> "default_capacity_provider_use_fargate": true,<br/> "fargate_capacity_providers": {<br/> "FARGATE": {<br/> "default_capacity_provider_strategy": {<br/> "weight": 100<br/> }<br/> },<br/> "FARGATE_SPOT": {<br/> "default_capacity_provider_strategy": {<br/> "weight": 0<br/> }<br/> }<br/> },<br/> "tags": {}<br/>}</pre> | no |
|
|
| <a name="input_fleet_config"></a> [fleet\_config](#input\_fleet\_config) | The configuration object for Fleet itself. Fields that default to null will have their respective resources created if not specified. For published KMS blocks, legacy `enabled` is deprecated and still accepted; prefer `cmk_enabled`. | <pre>object({<br/> task_mem = optional(number, null)<br/> task_cpu = optional(number, null)<br/> ephemeral_storage = optional(object({<br/> size_in_gib = number<br/> }), null)<br/> mem = optional(number, 4096)<br/> cpu = optional(number, 512)<br/> pid_mode = optional(string, null)<br/> command = optional(list(string), null)<br/> private_key_delivery_method = optional(string, "ecs")<br/> image = optional(string, "fleetdm/fleet:v4.83.0")<br/> family = optional(string, "fleet")<br/> sidecars = optional(list(any), [])<br/> depends_on = optional(list(any), [])<br/> mount_points = optional(list(any), [])<br/> volumes = optional(list(any), [])<br/> extra_environment_variables = optional(map(string), {})<br/> extra_iam_policies = optional(list(string), [])<br/> extra_execution_iam_policies = optional(list(string), [])<br/> extra_secrets = optional(map(string), {})<br/> security_group_name = optional(string, "fleet")<br/> iam_role_arn = optional(string, null)<br/> repository_credentials = optional(string, "")<br/> private_key_secret_arn = optional(string, null)<br/> private_key_secret_name = optional(string, "fleet-server-private-key")<br/> private_key_secret_kms = optional(object({<br/> cmk_enabled = optional(bool, null)<br/> enabled = optional(bool, null)<br/> kms_key_arn = optional(string, null)<br/> kms_alias = optional(string, "fleet-server-private-key")<br/> extra_kms_policies = optional(list(any), [])<br/> }), {<br/> cmk_enabled = null<br/> enabled = null<br/> kms_key_arn = null<br/> kms_alias = "fleet-server-private-key"<br/> extra_kms_policies = []<br/> })<br/> fargate_ephemeral_storage_kms = optional(object({<br/> cmk_enabled = optional(bool, null)<br/> enabled = optional(bool, null)<br/> kms_key_arn = optional(string, null)<br/> kms_alias = optional(string, "fleet-fargate-ephemeral-storage")<br/> extra_kms_policies = optional(list(any), [])<br/> }), {<br/> cmk_enabled = null<br/> enabled = null<br/> kms_key_arn = null<br/> kms_alias = "fleet-fargate-ephemeral-storage"<br/> extra_kms_policies = []<br/> })<br/> server_tls_enabled = optional(bool, false)<br/> service = optional(object({<br/> name = optional(string, "fleet")<br/> }), {<br/> name = "fleet"<br/> })<br/> database = optional(object({<br/> password_secret_arn = string<br/> password_secret_kms_key_arn = optional(string, null)<br/> user = string<br/> database = string<br/> address = string<br/> rr_address = optional(string, null)<br/> }), {<br/> password_secret_arn = null<br/> password_secret_kms_key_arn = null<br/> user = null<br/> database = null<br/> address = null<br/> rr_address = null<br/> })<br/> redis = optional(object({<br/> address = string<br/> use_tls = optional(bool, true)<br/> }), {<br/> address = null<br/> use_tls = true<br/> })<br/> awslogs = optional(object({<br/> name = optional(string, null)<br/> region = optional(string, null)<br/> create = optional(bool, true)<br/> prefix = optional(string, "fleet")<br/> retention = optional(number, 5)<br/> kms = optional(object({<br/> cmk_enabled = optional(bool, null)<br/> enabled = optional(bool, null)<br/> kms_key_arn = optional(string, null)<br/> kms_alias = optional(string, "fleet-application-logs")<br/> extra_kms_policies = optional(list(any), [])<br/> }), {<br/> cmk_enabled = null<br/> enabled = null<br/> kms_key_arn = null<br/> kms_alias = "fleet-application-logs"<br/> extra_kms_policies = []<br/> })<br/> }), {<br/> name = null<br/> region = null<br/> create = true<br/> prefix = "fleet"<br/> retention = 5<br/> kms = {<br/> cmk_enabled = null<br/> enabled = null<br/> kms_key_arn = null<br/> kms_alias = "fleet-application-logs"<br/> extra_kms_policies = []<br/> }<br/> })<br/> loadbalancer = optional(object({<br/> arn = string<br/> }), {<br/> arn = null<br/> })<br/> extra_load_balancers = optional(list(any), [])<br/> networking = optional(object({<br/> subnets = optional(list(string), null)<br/> security_groups = optional(list(string), null)<br/> ingress_sources = optional(object({<br/> cidr_blocks = optional(list(string), [])<br/> ipv6_cidr_blocks = optional(list(string), [])<br/> security_groups = optional(list(string), [])<br/> prefix_list_ids = optional(list(string), [])<br/> }), {<br/> cidr_blocks = []<br/> ipv6_cidr_blocks = []<br/> security_groups = []<br/> prefix_list_ids = []<br/> })<br/> assign_public_ip = optional(bool, false)<br/> }), {<br/> subnets = null<br/> security_groups = null<br/> ingress_sources = {<br/> cidr_blocks = []<br/> ipv6_cidr_blocks = []<br/> security_groups = []<br/> prefix_list_ids = []<br/> }<br/> assign_public_ip = false<br/> })<br/> autoscaling = optional(object({<br/> max_capacity = optional(number, 5)<br/> min_capacity = optional(number, 1)<br/> memory_tracking_target_value = optional(number, 80)<br/> cpu_tracking_target_value = optional(number, 80)<br/> }), {<br/> max_capacity = 5<br/> min_capacity = 1<br/> memory_tracking_target_value = 80<br/> cpu_tracking_target_value = 80<br/> })<br/> iam = optional(object({<br/> role = optional(object({<br/> name = optional(string, "fleet-role")<br/> policy_name = optional(string, "fleet-iam-policy")<br/> }), {<br/> name = "fleet-role"<br/> policy_name = "fleet-iam-policy"<br/> })<br/> execution = optional(object({<br/> name = optional(string, "fleet-execution-role")<br/> policy_name = optional(string, "fleet-execution-role")<br/> }), {<br/> name = "fleet-execution-role"<br/> policy_name = "fleet-iam-policy-execution"<br/> })<br/> }), {<br/> name = "fleetdm-execution-role"<br/> })<br/> software_installers = optional(object({<br/> create_bucket = optional(bool, true)<br/> bucket_name = optional(string, null)<br/> bucket_prefix = optional(string, "fleet-software-installers-")<br/> s3_object_prefix = optional(string, "")<br/> cloudfront_distribution_arn = optional(string, null)<br/> enable_bucket_versioning = optional(bool, false)<br/> expire_noncurrent_versions = optional(bool, true)<br/> noncurrent_version_expiration_days = optional(number, 30)<br/> create_kms_key = optional(bool, false)<br/> kms_key_arn = optional(string, null)<br/> kms_alias = optional(string, "fleet-software-installers")<br/> extra_kms_policies = optional(list(any), [])<br/> tags = optional(map(string), {})<br/> }), {<br/> create_bucket = true<br/> bucket_name = null<br/> bucket_prefix = "fleet-software-installers-"<br/> s3_object_prefix = ""<br/> cloudfront_distribution_arn = null<br/> enable_bucket_versioning = false<br/> expire_noncurrent_versions = true<br/> noncurrent_version_expiration_days = 30<br/> create_kms_key = false<br/> kms_key_arn = null<br/> kms_alias = "fleet-software-installers"<br/> extra_kms_policies = []<br/> tags = {}<br/> })<br/> })</pre> | <pre>{<br/> "autoscaling": {<br/> "cpu_tracking_target_value": 80,<br/> "max_capacity": 5,<br/> "memory_tracking_target_value": 80,<br/> "min_capacity": 1<br/> },<br/> "awslogs": {<br/> "create": true,<br/> "kms": {<br/> "cmk_enabled": null,<br/> "enabled": null,<br/> "extra_kms_policies": [],<br/> "kms_alias": "fleet-application-logs",<br/> "kms_key_arn": null<br/> },<br/> "name": null,<br/> "prefix": "fleet",<br/> "region": null,<br/> "retention": 5<br/> },<br/> "command": null,<br/> "cpu": 512,<br/> "database": {<br/> "address": null,<br/> "database": null,<br/> "password_secret_arn": null,<br/> "rr_address": null,<br/> "user": null<br/> },<br/> "depends_on": [],<br/> "ephemeral_storage": null,<br/> "extra_environment_variables": {},<br/> "extra_execution_iam_policies": [],<br/> "extra_iam_policies": [],<br/> "extra_load_balancers": [],<br/> "extra_secrets": {},<br/> "family": "fleet",<br/> "fargate_ephemeral_storage_kms": {<br/> "cmk_enabled": null,<br/> "enabled": null,<br/> "extra_kms_policies": [],<br/> "kms_alias": "fleet-fargate-ephemeral-storage",<br/> "kms_key_arn": null<br/> },<br/> "iam": {<br/> "execution": {<br/> "name": "fleet-execution-role",<br/> "policy_name": "fleet-iam-policy-execution"<br/> },<br/> "role": {<br/> "name": "fleet-role",<br/> "policy_name": "fleet-iam-policy"<br/> }<br/> },<br/> "iam_role_arn": null,<br/> "image": "fleetdm/fleet:v4.83.0",<br/> "loadbalancer": {<br/> "arn": null<br/> },<br/> "mem": 4096,<br/> "mount_points": [],<br/> "networking": {<br/> "assign_public_ip": false,<br/> "ingress_sources": {<br/> "cidr_blocks": [],<br/> "ipv6_cidr_blocks": [],<br/> "prefix_list_ids": [],<br/> "security_groups": []<br/> },<br/> "security_groups": null,<br/> "subnets": null<br/> },<br/> "pid_mode": null,<br/> "private_key_delivery_method": "ecs",<br/> "private_key_secret_arn": null,<br/> "private_key_secret_kms": {<br/> "cmk_enabled": null,<br/> "enabled": null,<br/> "extra_kms_policies": [],<br/> "kms_alias": "fleet-server-private-key",<br/> "kms_key_arn": null<br/> },<br/> "private_key_secret_name": "fleet-server-private-key",<br/> "redis": {<br/> "address": null,<br/> "use_tls": true<br/> },<br/> "repository_credentials": "",<br/> "security_group_name": "fleet",<br/> "server_tls_enabled": false,<br/> "service": {<br/> "name": "fleet"<br/> },<br/> "sidecars": [],<br/> "software_installers": {<br/> "bucket_name": null,<br/> "bucket_prefix": "fleet-software-installers-",<br/> "cloudfront_distribution_arn": null,<br/> "create_bucket": true,<br/> "create_kms_key": false,<br/> "enable_bucket_versioning": false,<br/> "expire_noncurrent_versions": true,<br/> "extra_kms_policies": [],<br/> "kms_alias": "fleet-software-installers",<br/> "kms_key_arn": null,<br/> "noncurrent_version_expiration_days": 30,<br/> "s3_object_prefix": "",<br/> "tags": {}<br/> },<br/> "task_cpu": null,<br/> "task_mem": null,<br/> "volumes": []<br/>}</pre> | no |
|
|
| <a name="input_kms_base_policy"></a> [kms\_base\_policy](#input\_kms\_base\_policy) | Optional base KMS key-policy statements to apply to module-created CMKs before module-required service access statements are merged in. If null, the module defaults to the historical root `kms:*` statement. | <pre>list(object({<br/> sid = string<br/> effect = string<br/> principals = object({<br/> type = string<br/> identifiers = list(string)<br/> })<br/> actions = list(string)<br/> resources = list(string)<br/> conditions = optional(list(object({<br/> test = string<br/> variable = string<br/> values = list(string)<br/> })), [])<br/> }))</pre> | `null` | no |
|
|
| <a name="input_migration_config"></a> [migration\_config](#input\_migration\_config) | The configuration object for Fleet's migration task. | <pre>object({<br/> mem = number<br/> cpu = number<br/> })</pre> | <pre>{<br/> "cpu": 1024,<br/> "mem": 2048<br/>}</pre> | no |
|
|
| <a name="input_vpc_id"></a> [vpc\_id](#input\_vpc\_id) | n/a | `string` | n/a | yes |
|
|
|
|
## Outputs
|
|
|
|
| Name | Description |
|
|
|------|-------------|
|
|
| <a name="output_alb"></a> [alb](#output\_alb) | n/a |
|
|
| <a name="output_byo-ecs"></a> [byo-ecs](#output\_byo-ecs) | n/a |
|
|
| <a name="output_cluster"></a> [cluster](#output\_cluster) | n/a |
|