Skip to content

Commit 2575ab3

Browse files
authored
feat: Support externally created source and target endpoint ARNs (#72)
1 parent 7d25c92 commit 2575ab3

File tree

3 files changed

+26
-23
lines changed

3 files changed

+26
-23
lines changed

examples/complete/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ Note that this example may create resources which will incur monetary charges on
5757

5858
| Name | Type |
5959
|------|------|
60+
| [aws_dms_endpoint.postgresql_source](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/dms_endpoint) | resource |
6061
| [aws_kms_key.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/kms_key) | resource |
6162
| [aws_rds_cluster_parameter_group.postgresql](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/rds_cluster_parameter_group) | resource |
6263
| [aws_s3_object.hr_data](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_object) | resource |

examples/complete/main.tf

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -126,23 +126,6 @@ module "dms_aurora_postgresql_aurora_mysql" {
126126
tags = { EndpointType = "postgresql-destination" }
127127
}
128128

129-
postgresql-source = {
130-
database_name = local.db_name
131-
endpoint_id = "${local.name}-postgresql-source"
132-
endpoint_type = "source"
133-
engine_name = "aurora-postgresql"
134-
extra_connection_attributes = "heartbeatFrequency=1;secretsManagerEndpointOverride=${module.vpc_endpoints.endpoints["secretsmanager"]["dns_entry"][0]["dns_name"]}"
135-
secrets_manager_arn = module.secrets_manager_postgresql.secret_arn
136-
137-
postgres_settings = {
138-
capture_ddls = false
139-
heartbeat_enable = true
140-
heartbeat_frequency = 1
141-
}
142-
143-
tags = { EndpointType = "postgresql-source" }
144-
}
145-
146129
mysql-destination = {
147130
database_name = local.db_name
148131
endpoint_id = "${local.name}-mysql-destination"
@@ -190,7 +173,7 @@ module "dms_aurora_postgresql_aurora_mysql" {
190173
migration_type = "full-load-and-cdc"
191174
replication_task_settings = file("configs/task_settings.json")
192175
table_mappings = file("configs/table_mappings.json")
193-
source_endpoint_key = "postgresql-source"
176+
source_endpoint_arn = aws_dms_endpoint.postgresql_source.endpoint_arn
194177
target_endpoint_key = "mysql-destination"
195178
tags = { Task = "PostgreSQL-to-MySQL" }
196179
}
@@ -199,7 +182,7 @@ module "dms_aurora_postgresql_aurora_mysql" {
199182
migration_type = "full-load-and-cdc"
200183
replication_task_settings = file("configs/task_settings.json")
201184
table_mappings = file("configs/kafka_mappings.json")
202-
source_endpoint_key = "postgresql-source"
185+
source_endpoint_arn = aws_dms_endpoint.postgresql_source.endpoint_arn
203186
target_endpoint_key = "kafka-destination"
204187
tags = { Task = "PostgreSQL-to-Kafka" }
205188
}
@@ -528,3 +511,22 @@ module "secrets_manager_mysql" {
528511

529512
tags = local.tags
530513
}
514+
515+
resource "aws_dms_endpoint" "postgresql_source" {
516+
database_name = local.db_name
517+
endpoint_id = "${local.name}-postgresql-source"
518+
endpoint_type = "source"
519+
engine_name = "aurora-postgresql"
520+
extra_connection_attributes = "heartbeatFrequency=1;secretsManagerEndpointOverride=${module.vpc_endpoints.endpoints["secretsmanager"]["dns_entry"][0]["dns_name"]}"
521+
522+
secrets_manager_arn = module.secrets_manager_postgresql.secret_arn
523+
secrets_manager_access_role_arn = module.dms_aurora_postgresql_aurora_mysql.access_iam_role_arn
524+
525+
postgres_settings {
526+
capture_ddls = false
527+
heartbeat_enable = true
528+
heartbeat_frequency = 1
529+
}
530+
531+
tags = { EndpointType = "postgresql-source" }
532+
}

main.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -392,10 +392,10 @@ resource "aws_dms_replication_task" "this" {
392392
replication_instance_arn = aws_dms_replication_instance.this[0].replication_instance_arn
393393
replication_task_id = each.value.replication_task_id
394394
replication_task_settings = try(each.value.replication_task_settings, null)
395-
source_endpoint_arn = try(aws_dms_endpoint.this[each.value.source_endpoint_key].endpoint_arn, aws_dms_s3_endpoint.this[each.value.source_endpoint_key].endpoint_arn)
395+
source_endpoint_arn = try(each.value.source_endpoint_arn, aws_dms_endpoint.this[each.value.source_endpoint_key].endpoint_arn, aws_dms_s3_endpoint.this[each.value.source_endpoint_key].endpoint_arn)
396396
start_replication_task = try(each.value.start_replication_task, null)
397397
table_mappings = try(each.value.table_mappings, null)
398-
target_endpoint_arn = try(aws_dms_endpoint.this[each.value.target_endpoint_key].endpoint_arn, aws_dms_s3_endpoint.this[each.value.target_endpoint_key].endpoint_arn)
398+
target_endpoint_arn = try(each.value.target_endpoint_arn, aws_dms_endpoint.this[each.value.target_endpoint_key].endpoint_arn, aws_dms_s3_endpoint.this[each.value.target_endpoint_key].endpoint_arn)
399399

400400
tags = merge(var.tags, try(each.value.tags, {}))
401401
}
@@ -410,8 +410,8 @@ resource "aws_dms_replication_config" "this" {
410410
resource_identifier = each.value.replication_task_id
411411

412412
replication_type = each.value.migration_type
413-
source_endpoint_arn = try(aws_dms_endpoint.this[each.value.source_endpoint_key].endpoint_arn, aws_dms_s3_endpoint.this[each.value.source_endpoint_key].endpoint_arn)
414-
target_endpoint_arn = try(aws_dms_endpoint.this[each.value.target_endpoint_key].endpoint_arn, aws_dms_s3_endpoint.this[each.value.target_endpoint_key].endpoint_arn)
413+
source_endpoint_arn = try(each.value.source_endpoint_arn, aws_dms_endpoint.this[each.value.source_endpoint_key].endpoint_arn, aws_dms_s3_endpoint.this[each.value.source_endpoint_key].endpoint_arn)
414+
target_endpoint_arn = try(each.value.target_endpoint_arn, aws_dms_endpoint.this[each.value.target_endpoint_key].endpoint_arn, aws_dms_s3_endpoint.this[each.value.target_endpoint_key].endpoint_arn)
415415
table_mappings = try(each.value.table_mappings, null)
416416

417417
replication_settings = try(each.value.replication_task_settings, null)

0 commit comments

Comments
 (0)