Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support externally created source and target endpoint ARNs #72

Merged
merged 2 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/complete/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
40 changes: 21 additions & 19 deletions examples/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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" }
}
Expand All @@ -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" }
}
Expand Down Expand Up @@ -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" }
}
8 changes: 4 additions & 4 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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, {}))
}
Expand All @@ -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)
Expand Down
Loading