From c596665d6f9529eaed2c1dac68cc94f27e5befc3 Mon Sep 17 00:00:00 2001 From: Kellen Anker Date: Mon, 9 Sep 2024 12:43:50 -0600 Subject: [PATCH 1/2] support overriding source_endpoint_arn and target_endpoint_arn to var.replication_tasks --- main.tf | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/main.tf b/main.tf index 012113e..0c66107 100644 --- a/main.tf +++ b/main.tf @@ -392,10 +392,10 @@ resource "aws_dms_replication_task" "this" { replication_instance_arn = aws_dms_replication_instance.this[0].replication_instance_arn replication_task_id = each.value.replication_task_id replication_task_settings = try(each.value.replication_task_settings, null) - 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) + 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) start_replication_task = try(each.value.start_replication_task, null) table_mappings = try(each.value.table_mappings, null) - 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) + 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) tags = merge(var.tags, try(each.value.tags, {})) } @@ -410,8 +410,8 @@ resource "aws_dms_replication_config" "this" { resource_identifier = each.value.replication_task_id replication_type = each.value.migration_type - 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) - 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) + 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) + 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) table_mappings = try(each.value.table_mappings, null) replication_settings = try(each.value.replication_task_settings, null) From 6fcab902126a63a711080486d9259ff3fbf0ca24 Mon Sep 17 00:00:00 2001 From: Kellen Anker Date: Mon, 9 Sep 2024 12:56:07 -0600 Subject: [PATCH 2/2] update complete example --- examples/complete/README.md | 1 + examples/complete/main.tf | 40 +++++++++++++++++++------------------ 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/examples/complete/README.md b/examples/complete/README.md index b5d457d..2dd6495 100644 --- a/examples/complete/README.md +++ b/examples/complete/README.md @@ -57,6 +57,7 @@ Note that this example may create resources which will incur monetary charges on | Name | Type | |------|------| +| [aws_dms_endpoint.postgresql_source](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/dms_endpoint) | resource | | [aws_kms_key.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/kms_key) | resource | | [aws_rds_cluster_parameter_group.postgresql](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/rds_cluster_parameter_group) | resource | | [aws_s3_object.hr_data](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_object) | resource | diff --git a/examples/complete/main.tf b/examples/complete/main.tf index 8f801cc..bc45279 100644 --- a/examples/complete/main.tf +++ b/examples/complete/main.tf @@ -126,23 +126,6 @@ module "dms_aurora_postgresql_aurora_mysql" { tags = { EndpointType = "postgresql-destination" } } - postgresql-source = { - database_name = local.db_name - endpoint_id = "${local.name}-postgresql-source" - endpoint_type = "source" - engine_name = "aurora-postgresql" - extra_connection_attributes = "heartbeatFrequency=1;secretsManagerEndpointOverride=${module.vpc_endpoints.endpoints["secretsmanager"]["dns_entry"][0]["dns_name"]}" - secrets_manager_arn = module.secrets_manager_postgresql.secret_arn - - postgres_settings = { - capture_ddls = false - heartbeat_enable = true - heartbeat_frequency = 1 - } - - tags = { EndpointType = "postgresql-source" } - } - mysql-destination = { database_name = local.db_name endpoint_id = "${local.name}-mysql-destination" @@ -190,7 +173,7 @@ module "dms_aurora_postgresql_aurora_mysql" { migration_type = "full-load-and-cdc" replication_task_settings = file("configs/task_settings.json") table_mappings = file("configs/table_mappings.json") - source_endpoint_key = "postgresql-source" + source_endpoint_arn = aws_dms_endpoint.postgresql_source.endpoint_arn target_endpoint_key = "mysql-destination" tags = { Task = "PostgreSQL-to-MySQL" } } @@ -199,7 +182,7 @@ module "dms_aurora_postgresql_aurora_mysql" { migration_type = "full-load-and-cdc" replication_task_settings = file("configs/task_settings.json") table_mappings = file("configs/kafka_mappings.json") - source_endpoint_key = "postgresql-source" + source_endpoint_arn = aws_dms_endpoint.postgresql_source.endpoint_arn target_endpoint_key = "kafka-destination" tags = { Task = "PostgreSQL-to-Kafka" } } @@ -528,3 +511,22 @@ module "secrets_manager_mysql" { tags = local.tags } + +resource "aws_dms_endpoint" "postgresql_source" { + database_name = local.db_name + endpoint_id = "${local.name}-postgresql-source" + endpoint_type = "source" + engine_name = "aurora-postgresql" + extra_connection_attributes = "heartbeatFrequency=1;secretsManagerEndpointOverride=${module.vpc_endpoints.endpoints["secretsmanager"]["dns_entry"][0]["dns_name"]}" + + secrets_manager_arn = module.secrets_manager_postgresql.secret_arn + secrets_manager_access_role_arn = module.dms_aurora_postgresql_aurora_mysql.access_iam_role_arn + + postgres_settings { + capture_ddls = false + heartbeat_enable = true + heartbeat_frequency = 1 + } + + tags = { EndpointType = "postgresql-source" } +}