Skip to content

Commit 88418a7

Browse files
authored
fix: Fixed example of cross-region replica where KMS key was missing (#428)
1 parent 8812527 commit 88418a7

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

examples/cross-region-replica-postgres/README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,15 @@ Note that this example may create resources which cost money. Run `terraform des
2424

2525
## Providers
2626

27-
No providers.
27+
| Name | Version |
28+
|------|---------|
29+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.6 |
2830

2931
## Modules
3032

3133
| Name | Source | Version |
3234
|------|--------|---------|
35+
| <a name="module_kms"></a> [kms](#module\_kms) | terraform-aws-modules/kms/aws | ~> 1.0 |
3336
| <a name="module_master"></a> [master](#module\_master) | ../../ | n/a |
3437
| <a name="module_replica"></a> [replica](#module\_replica) | ../../ | n/a |
3538
| <a name="module_security_group_region1"></a> [security\_group\_region1](#module\_security\_group\_region1) | terraform-aws-modules/security-group/aws | ~> 4.0 |
@@ -39,7 +42,9 @@ No providers.
3942

4043
## Resources
4144

42-
No resources.
45+
| Name | Type |
46+
|------|------|
47+
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
4348

4449
## Inputs
4550

examples/cross-region-replica-postgres/main.tf

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@ provider "aws" {
77
region = local.region2
88
}
99

10+
data "aws_caller_identity" "current" {}
11+
1012
locals {
11-
name = "replica-postgresql"
12-
region1 = "eu-west-1"
13-
region2 = "eu-central-1"
13+
name = "replica-postgresql"
14+
region1 = "eu-west-1"
15+
region2 = "eu-central-1"
16+
current_identity = data.aws_caller_identity.current.id
1417
tags = {
1518
Owner = "user"
1619
Environment = "dev"
@@ -158,6 +161,23 @@ module "master" {
158161
################################################################################
159162
# Replica DB
160163
################################################################################
164+
module "kms" {
165+
source = "terraform-aws-modules/kms/aws"
166+
version = "~> 1.0"
167+
description = "KMS key for cross region replica DB"
168+
169+
# Aliases
170+
aliases = [local.name]
171+
aliases_use_name_prefix = true
172+
173+
key_owners = [local.current_identity]
174+
175+
tags = local.tags
176+
177+
providers = {
178+
aws = aws.region2
179+
}
180+
}
161181

162182
module "replica" {
163183
source = "../../"
@@ -177,6 +197,7 @@ module "replica" {
177197
family = local.family
178198
major_engine_version = local.major_engine_version
179199
instance_class = local.instance_class
200+
kms_key_id = module.kms.key_arn
180201

181202
allocated_storage = local.allocated_storage
182203
max_allocated_storage = local.max_allocated_storage

0 commit comments

Comments
 (0)