Resource: aws_dms_replication_subnet_group

Provides a DMS (Data Migration Service) replication subnet group resource. DMS replication subnet groups can be created, updated, deleted, and imported.

Example Usage

Basic

# Create a new replication subnet group
resource "aws_dms_replication_subnet_group" "example" {
  replication_subnet_group_description = "Example replication subnet group"
  replication_subnet_group_id          = "example-dms-replication-subnet-group-tf"

  subnet_ids = [
    "subnet-12345678",
    "subnet-12345679",
  ]

  tags = {
    Name = "example"
  }
}

Creating special IAM role

If your account does not already include the dms-vpc-role IAM role, you will need to create it to allow DMS to manage subnets in the VPC.

resource "aws_iam_role" "dms-vpc-role" {
  name        = "dms-vpc-role"
  description = "Allows DMS to manage VPC"
  assume_role_policy = jsonencode({
    Version = "2012-10-17"
    Statement = [
      {
        Effect = "Allow"
        Principal = {
          Service = "dms.amazonaws.com"
        }
        Action = "sts:AssumeRole"
      },
    ]
  })
}

resource "aws_iam_role_policy_attachment" "example" {
  role       = aws_iam_role.dms-vpc-role.name
  policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonDMSVPCManagementRole"
}

resource "aws_dms_replication_subnet_group" "example" {
  replication_subnet_group_description = "Example"
  replication_subnet_group_id          = "example-id"

  subnet_ids = [
    "subnet-12345678",
    "subnet-12345679",
  ]

  tags = {
    Name = "example-id"
  }

  # explicit depends_on is needed since this resource doesn't reference the role or policy attachment
  depends_on = [aws_iam_role_policy_attachment.example]
}

Argument Reference

This resource supports the following arguments:

Attribute Reference

This resource exports the following attributes in addition to the arguments above:

Timeouts

Configuration options:

Import

In Terraform v1.5.0 and later, use an import block to import replication subnet groups using the replication_subnet_group_id. For example:

import {
  to = aws_dms_replication_subnet_group.test
  id = "test-dms-replication-subnet-group-tf"
}

Using terraform import, import replication subnet groups using the replication_subnet_group_id. For example:

% terraform import aws_dms_replication_subnet_group.test test-dms-replication-subnet-group-tf