## 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
388 lines
14 KiB
Terraform
388 lines
14 KiB
Terraform
variable "ecs_cluster" {
|
|
type = string
|
|
description = "The name of the ECS cluster to use"
|
|
nullable = false
|
|
}
|
|
|
|
variable "vpc_id" {
|
|
type = string
|
|
default = null
|
|
}
|
|
|
|
variable "kms_base_policy" {
|
|
type = list(object({
|
|
sid = string
|
|
effect = string
|
|
principals = object({
|
|
type = string
|
|
identifiers = list(string)
|
|
})
|
|
actions = list(string)
|
|
resources = list(string)
|
|
conditions = optional(list(object({
|
|
test = string
|
|
variable = string
|
|
values = list(string)
|
|
})), [])
|
|
}))
|
|
default = null
|
|
description = "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."
|
|
}
|
|
|
|
variable "fleet_config" {
|
|
type = object({
|
|
task_mem = optional(number, null)
|
|
task_cpu = optional(number, null)
|
|
ephemeral_storage = optional(object({
|
|
size_in_gib = number
|
|
}), null)
|
|
mem = optional(number, 4096)
|
|
cpu = optional(number, 512)
|
|
pid_mode = optional(string, null)
|
|
command = optional(list(string), null)
|
|
private_key_delivery_method = optional(string, "ecs")
|
|
image = optional(string, "fleetdm/fleet:v4.83.0")
|
|
family = optional(string, "fleet")
|
|
sidecars = optional(list(any), [])
|
|
depends_on = optional(list(any), [])
|
|
mount_points = optional(list(any), [])
|
|
volumes = optional(list(any), [])
|
|
extra_environment_variables = optional(map(string), {})
|
|
extra_iam_policies = optional(list(string), [])
|
|
extra_execution_iam_policies = optional(list(string), [])
|
|
extra_secrets = optional(map(string), {})
|
|
security_group_name = optional(string, "fleet")
|
|
iam_role_arn = optional(string, null)
|
|
repository_credentials = optional(string, "")
|
|
private_key_secret_arn = optional(string, null)
|
|
private_key_secret_name = optional(string, "fleet-server-private-key")
|
|
private_key_secret_kms = optional(object({
|
|
cmk_enabled = optional(bool, null)
|
|
enabled = optional(bool, null)
|
|
kms_key_arn = optional(string, null)
|
|
kms_alias = optional(string, "fleet-server-private-key")
|
|
extra_kms_policies = optional(list(any), [])
|
|
}), {
|
|
cmk_enabled = null
|
|
enabled = null
|
|
kms_key_arn = null
|
|
kms_alias = "fleet-server-private-key"
|
|
extra_kms_policies = []
|
|
})
|
|
server_tls_enabled = optional(bool, false)
|
|
service = optional(object({
|
|
name = optional(string, "fleet")
|
|
}), {
|
|
name = "fleet"
|
|
})
|
|
database = object({
|
|
password_secret_arn = string
|
|
password_secret_kms_key_arn = optional(string, null)
|
|
user = string
|
|
database = string
|
|
address = string
|
|
rr_address = optional(string, null)
|
|
})
|
|
redis = object({
|
|
address = string
|
|
use_tls = optional(bool, true)
|
|
})
|
|
awslogs = optional(object({
|
|
name = optional(string, null)
|
|
region = optional(string, null)
|
|
create = optional(bool, true)
|
|
prefix = optional(string, "fleet")
|
|
retention = optional(number, 5)
|
|
kms = optional(object({
|
|
cmk_enabled = optional(bool, null)
|
|
enabled = optional(bool, null)
|
|
kms_key_arn = optional(string, null)
|
|
kms_alias = optional(string, "fleet-application-logs")
|
|
extra_kms_policies = optional(list(any), [])
|
|
}), {
|
|
cmk_enabled = null
|
|
enabled = null
|
|
kms_key_arn = null
|
|
kms_alias = "fleet-application-logs"
|
|
extra_kms_policies = []
|
|
})
|
|
}), {
|
|
name = null
|
|
region = null
|
|
create = true
|
|
prefix = "fleet"
|
|
retention = 5
|
|
kms = {
|
|
cmk_enabled = null
|
|
enabled = null
|
|
kms_key_arn = null
|
|
kms_alias = "fleet-application-logs"
|
|
extra_kms_policies = []
|
|
}
|
|
})
|
|
loadbalancer = object({
|
|
arn = string
|
|
})
|
|
extra_load_balancers = optional(list(any), [])
|
|
networking = object({
|
|
subnets = optional(list(string), null)
|
|
security_groups = optional(list(string), null)
|
|
ingress_sources = object({
|
|
cidr_blocks = optional(list(string), [])
|
|
ipv6_cidr_blocks = optional(list(string), [])
|
|
security_groups = optional(list(string), [])
|
|
prefix_list_ids = optional(list(string), [])
|
|
})
|
|
assign_public_ip = optional(bool, false)
|
|
})
|
|
autoscaling = optional(object({
|
|
max_capacity = optional(number, 5)
|
|
min_capacity = optional(number, 1)
|
|
memory_tracking_target_value = optional(number, 80)
|
|
cpu_tracking_target_value = optional(number, 80)
|
|
}), {
|
|
max_capacity = 5
|
|
min_capacity = 1
|
|
memory_tracking_target_value = 80
|
|
cpu_tracking_target_value = 80
|
|
})
|
|
iam = optional(object({
|
|
role = optional(object({
|
|
name = optional(string, "fleet-role")
|
|
policy_name = optional(string, "fleet-iam-policy")
|
|
}), {
|
|
name = "fleet-role"
|
|
policy_name = "fleet-iam-policy"
|
|
})
|
|
execution = optional(object({
|
|
name = optional(string, "fleet-execution-role")
|
|
policy_name = optional(string, "fleet-execution-role")
|
|
}), {
|
|
name = "fleet-execution-role"
|
|
policy_name = "fleet-iam-policy-execution"
|
|
})
|
|
}), {
|
|
name = "fleetdm-execution-role"
|
|
})
|
|
software_installers = optional(object({
|
|
create_bucket = optional(bool, true)
|
|
bucket_name = optional(string, null)
|
|
bucket_prefix = optional(string, "fleet-software-installers-")
|
|
s3_object_prefix = optional(string, "")
|
|
cloudfront_distribution_arn = optional(string, null)
|
|
enable_bucket_versioning = optional(bool, false)
|
|
expire_noncurrent_versions = optional(bool, true)
|
|
noncurrent_version_expiration_days = optional(number, 30)
|
|
create_kms_key = optional(bool, false)
|
|
kms_key_arn = optional(string, null)
|
|
kms_alias = optional(string, "fleet-software-installers")
|
|
extra_kms_policies = optional(list(any), [])
|
|
tags = optional(map(string), {})
|
|
}), {
|
|
create_bucket = true
|
|
bucket_name = null
|
|
bucket_prefix = "fleet-software-installers-"
|
|
s3_object_prefix = ""
|
|
cloudfront_distribution_arn = null
|
|
enable_bucket_versioning = false
|
|
expire_noncurrent_versions = true
|
|
noncurrent_version_expiration_days = 30
|
|
create_kms_key = false
|
|
kms_key_arn = null
|
|
kms_alias = "fleet-software-installers"
|
|
extra_kms_policies = []
|
|
tags = {}
|
|
})
|
|
})
|
|
default = {
|
|
task_mem = null
|
|
task_cpu = null
|
|
ephemeral_storage = null
|
|
mem = 512
|
|
cpu = 256
|
|
pid_mode = null
|
|
command = null
|
|
private_key_delivery_method = "ecs"
|
|
image = "fleetdm/fleet:v4.83.0"
|
|
family = "fleet"
|
|
sidecars = []
|
|
depends_on = []
|
|
mount_points = []
|
|
volumes = []
|
|
extra_environment_variables = {}
|
|
extra_iam_policies = []
|
|
extra_execution_iam_policies = []
|
|
extra_secrets = {}
|
|
security_group_name = "fleet"
|
|
iam_role_arn = null
|
|
repository_credentials = ""
|
|
private_key_secret_arn = null
|
|
private_key_secret_name = "fleet-server-private-key"
|
|
private_key_secret_kms = {
|
|
cmk_enabled = null
|
|
enabled = null
|
|
kms_key_arn = null
|
|
kms_alias = "fleet-server-private-key"
|
|
extra_kms_policies = []
|
|
}
|
|
server_tls_enabled = false
|
|
service = {
|
|
name = "fleet"
|
|
}
|
|
database = {
|
|
password_secret_arn = null
|
|
user = null
|
|
database = null
|
|
address = null
|
|
rr_address = null
|
|
}
|
|
redis = {
|
|
address = null
|
|
use_tls = true
|
|
}
|
|
awslogs = {
|
|
name = null
|
|
region = null
|
|
create = true
|
|
prefix = "fleet"
|
|
retention = 5
|
|
kms = {
|
|
cmk_enabled = null
|
|
enabled = null
|
|
kms_key_arn = null
|
|
kms_alias = "fleet-application-logs"
|
|
extra_kms_policies = []
|
|
}
|
|
}
|
|
loadbalancer = {
|
|
arn = null
|
|
}
|
|
extra_load_balancers = []
|
|
networking = {
|
|
subnets = null
|
|
security_groups = null
|
|
ingress_sources = {
|
|
cidr_blocks = []
|
|
ipv6_cidr_blocks = []
|
|
security_groups = []
|
|
prefix_list_ids = []
|
|
}
|
|
assign_public_ip = false
|
|
}
|
|
autoscaling = {
|
|
max_capacity = 5
|
|
min_capacity = 1
|
|
memory_tracking_target_value = 80
|
|
cpu_tracking_target_value = 80
|
|
}
|
|
iam = {
|
|
role = {
|
|
name = "fleet-role"
|
|
policy_name = "fleet-iam-policy"
|
|
}
|
|
execution = {
|
|
name = "fleet-execution-role"
|
|
policy_name = "fleet-iam-policy-execution"
|
|
}
|
|
}
|
|
software_installers = {
|
|
create_bucket = true
|
|
bucket_name = null
|
|
bucket_prefix = "fleet-software-installers-"
|
|
s3_object_prefix = ""
|
|
cloudfront_distribution_arn = null
|
|
enable_bucket_versioning = false
|
|
expire_noncurrent_versions = true
|
|
noncurrent_version_expiration_days = 30
|
|
create_kms_key = false
|
|
kms_key_arn = null
|
|
kms_alias = "fleet-software-installers"
|
|
extra_kms_policies = []
|
|
tags = {}
|
|
}
|
|
}
|
|
description = "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`."
|
|
nullable = false
|
|
validation {
|
|
condition = contains(["ecs", "iam"], var.fleet_config.private_key_delivery_method)
|
|
error_message = "fleet_config.private_key_delivery_method must be either \"ecs\" or \"iam\"."
|
|
}
|
|
|
|
validation {
|
|
condition = var.fleet_config.ephemeral_storage == null ? true : (var.fleet_config.ephemeral_storage.size_in_gib >= 21 && var.fleet_config.ephemeral_storage.size_in_gib <= 200)
|
|
error_message = "fleet_config.ephemeral_storage.size_in_gib must be between 21 and 200 GiB when set."
|
|
}
|
|
|
|
validation {
|
|
condition = (
|
|
var.fleet_config.private_key_secret_kms.kms_key_arn == null ||
|
|
coalesce(var.fleet_config.private_key_secret_kms.cmk_enabled, var.fleet_config.private_key_secret_kms.enabled, false)
|
|
)
|
|
error_message = "fleet_config.private_key_secret_kms.kms_key_arn requires fleet_config.private_key_secret_kms.cmk_enabled = true (or legacy enabled = true)."
|
|
}
|
|
|
|
validation {
|
|
condition = (
|
|
length(var.fleet_config.private_key_secret_kms.extra_kms_policies) == 0 ||
|
|
(
|
|
var.fleet_config.private_key_secret_arn == null &&
|
|
coalesce(var.fleet_config.private_key_secret_kms.cmk_enabled, var.fleet_config.private_key_secret_kms.enabled, false) &&
|
|
var.fleet_config.private_key_secret_kms.kms_key_arn == null
|
|
)
|
|
)
|
|
error_message = "fleet_config.private_key_secret_kms.extra_kms_policies can be set only when byo-ecs is creating the private key secret CMK."
|
|
}
|
|
|
|
validation {
|
|
condition = (
|
|
var.fleet_config.awslogs.kms.kms_key_arn == null ||
|
|
(
|
|
var.fleet_config.awslogs.create == true &&
|
|
coalesce(var.fleet_config.awslogs.kms.cmk_enabled, var.fleet_config.awslogs.kms.enabled, false)
|
|
)
|
|
)
|
|
error_message = "fleet_config.awslogs.kms.kms_key_arn requires fleet_config.awslogs.create = true and fleet_config.awslogs.kms.cmk_enabled = true (or legacy enabled = true)."
|
|
}
|
|
|
|
validation {
|
|
condition = (
|
|
length(var.fleet_config.awslogs.kms.extra_kms_policies) == 0 ||
|
|
(
|
|
var.fleet_config.awslogs.create == true &&
|
|
coalesce(var.fleet_config.awslogs.kms.cmk_enabled, var.fleet_config.awslogs.kms.enabled, false) &&
|
|
var.fleet_config.awslogs.kms.kms_key_arn == null
|
|
)
|
|
)
|
|
error_message = "fleet_config.awslogs.kms.extra_kms_policies can be set only when byo-ecs is creating the application logs CMK."
|
|
}
|
|
|
|
validation {
|
|
condition = !(var.fleet_config.software_installers.kms_key_arn != null && var.fleet_config.software_installers.create_kms_key == true)
|
|
error_message = "fleet_config.software_installers.kms_key_arn and fleet_config.software_installers.create_kms_key are mutually exclusive; set one or the other, not both."
|
|
}
|
|
|
|
validation {
|
|
condition = (
|
|
length(var.fleet_config.software_installers.extra_kms_policies) == 0 ||
|
|
(
|
|
var.fleet_config.software_installers.create_kms_key == true &&
|
|
var.fleet_config.software_installers.kms_key_arn == null
|
|
)
|
|
)
|
|
error_message = "fleet_config.software_installers.extra_kms_policies can be set only when byo-ecs is creating the software installers CMK."
|
|
}
|
|
}
|
|
|
|
variable "migration_config" {
|
|
type = object({
|
|
mem = number
|
|
cpu = number
|
|
})
|
|
default = {
|
|
mem = 2048
|
|
cpu = 1024
|
|
}
|
|
description = "The configuration object for Fleet's migration task."
|
|
nullable = false
|
|
}
|