-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
dms-vpc-role not created before aws_dms_replication_instance #7748
Comments
I get the same error when trying to create a replication instance with an additional aws_dms_replication_subnet_group. Error:
|
So the resource assumes that a Role already exists to create the resources. This isn't the case if you have never created a DMS resource in your account before. A quick way to solve this is to go into your AWS console and create a temp DMS replication instance. Once it is created, delete it. AWS will provision the roles for you and the terraform script will use them from now on. It would be nice if Terraform documented this somewhere or provided a useful error message. I had to look at the original pull request to find out that this was assumed functionality. For a full solution, you'd have to create the roles manually and name them exactly as terraform/AWS expects them. I suspect this will be a bad idea and causes issues later on. The roles/policies are quite complex. |
…iguration for required roles Reference: #7748
Thanks for the heads up, @phillycheeze 👍 This is indeed a documentation issue on our end and as such am marking this issue accordingly. The DMS service is where the specifically named IAM Role requirement comes from: https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Security.APIRole.html Here is an example configuration that can accomplish the creation of these roles, using the available AWS managed service policies that automatically receive updates: data "aws_iam_policy_document" "dms_assume_role" {
statement {
actions = ["sts:AssumeRole"]
principals {
identifiers = ["dms.amazonaws.com"]
type = "Service"
}
}
}
resource "aws_iam_role" "dms-access-for-endpoint" {
assume_role_policy = "${data.aws_iam_policy_document.dms_assume_role.json}"
name = "dms-access-for-endpoint"
}
resource "aws_iam_role_policy_attachment" "dms-access-for-endpoint-AmazonDMSRedshiftS3Role" {
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonDMSRedshiftS3Role"
role = "${aws_iam_role.dms-access-for-endpoint.name}"
}
resource "aws_iam_role" "dms-cloudwatch-logs-role" {
assume_role_policy = "${data.aws_iam_policy_document.dms_assume_role.json}"
name = "dms-cloudwatch-logs-role"
}
resource "aws_iam_role_policy_attachment" "dms-cloudwatch-logs-role-AmazonDMSCloudWatchLogsRole" {
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonDMSCloudWatchLogsRole"
role = "${aws_iam_role.dms-cloudwatch-logs-role.name}"
}
resource "aws_iam_role" "dms-vpc-role" {
assume_role_policy = "${data.aws_iam_policy_document.dms_assume_role.json}"
name = "dms-vpc-role"
}
resource "aws_iam_role_policy_attachment" "dms-vpc-role-AmazonDMSVPCManagementRole" {
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonDMSVPCManagementRole"
role = "${aws_iam_role.dms-vpc-role.name}"
} I have submitted a pull request to update the documentation here: #9173 Hope this helps. |
Thanks @bflad ! This probably goes without saying, but if aws has already created the roles for you, that code sample won't work since it'll throw an error saying the roles already exist. In that case, it's probably better to go and delete the roles that aws created for you. Just a heads up if anyone runs into this problem. |
I am still getting the error the first run, a second apply straight after and it does work. |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks! |
This issue was originally opened by @neovasili as hashicorp/terraform#20346. It was migrated here as a result of the provider split. The original body of the issue is below.
Terraform Version
Terraform Configuration Files
Crash Output
Error: Error applying plan:
1 error(s) occurred:
aws_dms_replication_instance.dynamodb-import-instance: 1 error(s) occurred:
aws_dms_replication_instance.dynamodb-import-instance: error creating DMS Replication Instance: AccessDeniedFault: The IAM Role arn:aws:iam::xxxxxxxx:role/dms-vpc-role is not configured properly.
status code: 400, request id: xxxxxxxxx
Expected Behavior
Apply complete! Resources: X added, 0 changed, 0 destroyed.
Actual Behavior
Fails to apply because iam role is created after dms replication instance
Steps to Reproduce
terraform apply
Additional context
If you perform a secondary terraform apply all changes are applied perfectly
The text was updated successfully, but these errors were encountered: