Skip to content

Commit

Permalink
fix: add variable and additional poicy document to allow redshift to …
Browse files Browse the repository at this point in the history
…assume the `dms-access-for-endpoint` IAM role
  • Loading branch information
bryantbiggs committed Nov 3, 2021
1 parent eb444df commit 8b67475
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ No modules.
| [aws_iam_role.dms_cloudwatch_logs_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource |
| [aws_iam_role.dms_vpc_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource |
| [aws_iam_policy_document.dms_assume_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
| [aws_iam_policy_document.dms_assume_role_redshift](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
| [aws_partition.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/partition) | data source |

## Inputs
Expand All @@ -340,6 +341,7 @@ No modules.
| <a name="input_create"></a> [create](#input\_create) | Determines whether resources will be created | `bool` | `true` | no |
| <a name="input_create_iam_roles"></a> [create\_iam\_roles](#input\_create\_iam\_roles) | Determines whether the required [DMS IAM resources](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Security.html#CHAP_Security.APIRole) will be created | `bool` | `true` | no |
| <a name="input_create_repl_subnet_group"></a> [create\_repl\_subnet\_group](#input\_create\_repl\_subnet\_group) | Determines whether the replication subnet group will be created | `bool` | `true` | no |
| <a name="input_enable_redshift_target_permissions"></a> [enable\_redshift\_target\_permissions](#input\_enable\_redshift\_target\_permissions) | Determines whether `redshift.amazonaws.com` is permitted access to assume the `dms-access-for-endpoint` role | `bool` | `false` | no |
| <a name="input_endpoints"></a> [endpoints](#input\_endpoints) | Map of objects that define the endpoints to be created | `any` | `{}` | no |
| <a name="input_event_subscription_timeouts"></a> [event\_subscription\_timeouts](#input\_event\_subscription\_timeouts) | A map of timeouts for event subscription create/update/delete operations | `map(string)` | `{}` | no |
| <a name="input_event_subscriptions"></a> [event\_subscriptions](#input\_event\_subscriptions) | Map of objects that define the event subscriptions to be created | `any` | `{}` | no |
Expand Down
17 changes: 16 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,29 @@ data "aws_iam_policy_document" "dms_assume_role" {
}
}

data "aws_iam_policy_document" "dms_assume_role_redshift" {
count = var.create && var.create_iam_roles ? 1 : 0

source_json = data.aws_iam_policy_document.dms_assume_role[0].json

statement {
actions = ["sts:AssumeRole"]

principals {
identifiers = ["redshift.amazonaws.com"]
type = "Service"
}
}
}

# DMS Endpoint
resource "aws_iam_role" "dms_access_for_endpoint" {
count = var.create && var.create_iam_roles ? 1 : 0

name = "dms-access-for-endpoint"
description = "DMS IAM role for endpoint access permissions"
permissions_boundary = var.iam_role_permissions_boundary
assume_role_policy = data.aws_iam_policy_document.dms_assume_role[0].json
assume_role_policy = var.enable_redshift_target_permissions ? data.aws_iam_policy_document.dms_assume_role_redshift[0].json : data.aws_iam_policy_document.dms_assume_role[0].json
managed_policy_arns = ["arn:${local.partition}:iam::aws:policy/service-role/AmazonDMSRedshiftS3Role"]
force_detach_policies = true

Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ variable "iam_role_tags" {
default = {}
}

variable "enable_redshift_target_permissions" {
description = "Determines whether `redshift.amazonaws.com` is permitted access to assume the `dms-access-for-endpoint` role"
type = bool
default = false
}

# Subnet group
variable "create_repl_subnet_group" {
description = "Determines whether the replication subnet group will be created"
Expand Down

0 comments on commit 8b67475

Please sign in to comment.