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

[Issue 1119] Deploy DMS from database module, fixup #1129

Merged
merged 5 commits into from
Feb 1, 2024

Conversation

coilysiren
Copy link
Collaborator

@coilysiren coilysiren commented Feb 1, 2024

Summary

Rolls up to #1119

Time to review: 2 mins

Context for reviewers

I tried to deploy the DMS, and noticed 2 things:

  • It didn't have a configuration for deploying it, like a file to run terraform init -backend-config=SOMETHING on. So I was unable to pull the existing state. This is why I moved the IAM role to the database module, which is deployed from infra/api/database
  • I got an error when deploying the database module. Specifically: "dms-access-role should have the DMS Regional Service Principal 'dms.us-east-1.amazonaws.com' as trusted entity"

I then proceeded to deploy to dev and fix everything I could find

Deployment

I've already deployed this to dev to test. It still doesn't fully deploy - for reasons I will solve in a different PR tomorrow.

resource "aws_iam_role" "dms_access" {
name = "dms-access-role"
name_prefix = "dms-access-role"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is to ensure the DMS can deploy to dev / staging / prod. Roles must have unique names

@coilysiren coilysiren changed the title [Issue 1119] Deploy DMS from database module [Issue 1119] Deploy DMS from database module, fixup Feb 1, 2024
type = "Service"
identifiers = [
"dms.amazonaws.com",
"dms.${data.aws_region.current.name}.amazonaws.com",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error message:

"dms-access-role should have the DMS Regional Service Principal 'dms.us-east-1.amazonaws.com' as trusted entity"

@@ -85,6 +89,6 @@ data "aws_iam_policy_document" "dms_access" {
"logs:ilterLogEvents",
"logs:GetLogEvents"
]
resources = ["*"] # don't have log group yet
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its just logs, we should be able to do logs:*, its fine

@@ -24,10 +24,10 @@ resource "aws_dms_endpoint" "target_endpoint" {
certificate_arn = "arn:aws:dms:us-east-1:315341936575:cert:GWOIQRTIVQVRBL5ERMCKTUPHMM33MMDGIP57J4I"
database_name = "app"
endpoint_id = "api-dev-primary"
endpoint_type = "source"
endpoint_type = "target"
Copy link
Collaborator Author

@coilysiren coilysiren Feb 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo, this is the target endpoint

@@ -49,7 +51,7 @@ data "aws_iam_policy_document" "dms_access" {
"iam:CreateRole",
"iam:AttachRolePolicy"
]
resources = ["arn:aws:iam:*:${data.aws_caller_identity.current.account_id}:*"]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error message:

creating IAM Policy (dms-access): MalformedPolicyDocument: IAM resource arn:aws:iam::315341936575: cannot contain region information.

@@ -1,24 +0,0 @@
# This file is maintained automatically by "terraform init".
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

superfluous lockfiles

Copy link
Contributor

@SammySteiner SammySteiner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving to unblock, but this isn't my area of expertise.

@@ -35,7 +36,8 @@ data "aws_iam_policy_document" "dms_access" {
sid = "AllowDMSAccess"
effect = "Allow"
actions = ["dms:*"]
resources = [""] # arn for the actual dms service goes here
resources = ["arn:aws:dms:*:${data.aws_caller_identity.current.account_id}:*"]
# TODO! arn for the actual dms service goes here
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need the TODO comment?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep! The DMS isn't up yet, and I do want to fill it in.

Copy link
Collaborator

@jamesbursa jamesbursa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thank you.

engine_name = "aurora-postgresql"
kms_key_arn = aws_kms_key.dms_endpoints.arn
secrets_manager_access_role_arn = data.aws_iam_role.dms_access.arn
secrets_manager_access_role_arn = aws_iam_role.dms_access.arn
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this was changed to refer directly to the role, can we remove lines 59-61 in this file? data "aws_iam_role" "dms_access" { ... }

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! Yep

engine_name = "aurora-postgresql"
kms_key_arn = aws_kms_key.dms_endpoints.arn
secrets_manager_access_role_arn = data.aws_iam_role.dms_access.arn
secrets_manager_access_role_arn = aws_iam_role.dms_access.arn
ssl_mode = "verify-ca"
secrets_manager_arn = data.aws_secretsmanager_secret.target_db.arn
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the same secret as the one defined in role-manager.tf as data "aws_secretsmanager_secret" "db_password" { ... }. Should we re-use that one, then remove lines 52-55 below with the hard-coded name?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mhmm! I'm planning on doing that next o7

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@coilysiren coilysiren merged commit cf656df into main Feb 1, 2024
7 checks passed
@coilysiren coilysiren deleted the deploy-dms-from-db branch February 1, 2024 22:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants