Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Maintain and tear down the AWS deployment

The terraform-aws-n8n module manages encryption keys and database protection settings that matter most when you upgrade, recover from an incident, or decommission a deployment. This page covers those settings. For step-by-step upgrade and destroy troubleshooting, see the module's upgrade guide and destroy checklist on GitHub.

Bring your own KMS key

By default, the module creates and manages its own KMS key to encrypt the RDS instance and the S3 bucket. To encrypt with a key you already own instead, for example one a central security team controls:

create_db_kms_key = false
db_kms_key_arn    = "arn:aws:kms:eu-west-1:123456789012:key/1a2b3c4d-..."

create_s3_kms_key = false
s3_kms_key_arn    = "arn:aws:kms:eu-west-1:123456789012:key/1a2b3c4d-..."

Set both the boolean and the ARN together: the boolean alone stops the module creating its own key, and the ARN alone is ignored.

The CloudWatch Logs group needs its own key policy statement

RDS can use your key through a grant, but CloudWatch Logs rejects a key that doesn't explicitly name the regional Logs service principal in its key policy. Without that statement, the module's postgresql log group falls back to CloudWatch's own managed key instead of yours. Add a statement granting kms:Encrypt, kms:Decrypt, kms:ReEncrypt*, kms:GenerateDataKey*, and kms:DescribeKey to the logs.<region>.amazonaws.com principal, then set db_logs_kms_key_enabled = true and db_logs_kms_key_arn to the same key.

Verify the PostgreSQL TLS certificate

By default, the connection between n8n and the module's RDS instance is encrypted but unverified (DB_POSTGRESDB_SSL_REJECT_UNAUTHORIZED=false), because the RDS server certificate chains to Amazon's own certificate authority, which Node.js doesn't trust by default. To verify the server identity as well as encrypt the connection:

db_postgresdb_ssl_reject_unauthorized = true
db_postgresdb_ssl_ca_pem              = file("${path.module}/global-bundle.pem")

Download the combined CA bundle from AWS's trust store at https://truststore.pki.rds.amazonaws.com. The module mounts it read-only on every n8n pod and points DB_POSTGRESDB_SSL_CA_FILE at it.

KMS keys after terraform destroy

The module schedules its managed KMS keys for deletion seven days after a terraform destroy, rather than deleting them immediately. A key becomes unusable as soon as deletion is scheduled, even though permanent loss only occurs once the seven-day window completes. To reuse a key after a completed destroy, cancel its deletion, enable it, and import it back into Terraform state before re-applying:

Deletion protection and teardown

The module defaults to teardown-friendly settings, so example deployments can be destroyed cleanly:

Setting
Default
Production value

db_deletion_protection

false

true

db_skip_final_snapshot

true

false (also set db_final_snapshot_identifier)

db_delete_automated_backups

true

false

s3_force_destroy

true

false

All four are in-place changes on an existing deployment and don't force replacement. Apply these settings before running terraform destroy. Terraform uses the values in state, not un-applied configuration. Editing a .tfvars file and immediately running destroy therefore still uses the old values.

Last updated

Was this helpful?