-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "[PRMP-123] Changing file permissions (#105)"
This reverts commit 94eae93.
- Loading branch information
1 parent
076df60
commit eac9f7c
Showing
18 changed files
with
408 additions
and
32 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// TODO: PRMP-120 - Entire file may need removing | ||
|
||
resource "postgresql_role" "application_role" { | ||
name = "application_role" | ||
} | ||
|
||
resource "postgresql_grant" "application_role_schema_usage_grant" { | ||
database = var.db_name | ||
role = postgresql_role.application_role.name | ||
schema = "public" | ||
object_type = "schema" | ||
privileges = ["USAGE"] | ||
} | ||
|
||
resource "postgresql_role" "application_user" { | ||
name = "application_user" | ||
login = true | ||
roles = ["rds_iam", postgresql_role.application_role.name] | ||
} | ||
|
||
data "aws_iam_policy_document" "db_application_user_policy_doc" { | ||
statement { | ||
actions = [ | ||
"rds-db:connect" | ||
] | ||
|
||
resources = [ | ||
"arn:aws:rds-db:${var.region}:${data.aws_caller_identity.current.account_id}:dbuser:${data.aws_ssm_parameter.db_cluster_resource_id.value}/${postgresql_role.application_user.name}" | ||
] | ||
|
||
effect = "Allow" | ||
} | ||
} | ||
|
||
resource "aws_iam_policy" "db_application_user_policy" { | ||
name = "${var.environment}-${var.component_name}-db_application_user" | ||
policy = data.aws_iam_policy_document.db_application_user_policy_doc.json | ||
} | ||
|
||
# Grant ECS Task permissions to connect to the DB as application_user | ||
resource "aws_iam_role_policy_attachment" "db_application_user_policy_attach" { | ||
role = "${var.environment}-${var.component_name}-EcsTaskRole" | ||
policy_arn = aws_iam_policy.db_application_user_policy.arn | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
data "aws_caller_identity" "current" {} | ||
|
||
data "aws_ssm_parameter" "db_cluster_resource_id" { // TODO: PRMP-120 - May need removing | ||
name = "/repo/${var.environment}/output/${var.repo_name}/db-resource-cluster-id" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// TODO: PRMP-120 - Entire file may need removing | ||
|
||
resource "postgresql_role" "migration_role" { | ||
name = "migration_role" | ||
} | ||
|
||
resource "postgresql_grant" "migration_role_schema_usage_grant" { | ||
database = var.db_name | ||
role = postgresql_role.migration_role.name | ||
schema = "public" | ||
object_type = "schema" | ||
privileges = ["USAGE", "CREATE"] | ||
} | ||
|
||
resource "postgresql_role" "migration_user" { | ||
name = "migration_user" | ||
login = true | ||
valid_until = "" | ||
roles = ["rds_iam", postgresql_role.migration_role.name] | ||
} | ||
|
||
resource "aws_ssm_parameter" "migration_user" { | ||
name = "/repo/${var.environment}/output/${var.repo_name}/db-migration-user" | ||
type = "String" | ||
value = postgresql_role.migration_user.name | ||
} | ||
|
||
data "aws_iam_policy_document" "migration-assume-role-policy" { | ||
statement { | ||
actions = ["sts:AssumeRole"] | ||
|
||
principals { | ||
type = "Service" | ||
identifiers = [ | ||
"ec2.amazonaws.com" | ||
] | ||
} | ||
} | ||
} | ||
|
||
resource "aws_iam_role" "db_migration_role" { | ||
name = "${var.environment}-${var.component_name}-DbMigrationRole" | ||
assume_role_policy = data.aws_iam_policy_document.migration-assume-role-policy.json | ||
description = "DbMigration role to migrate db in the pipeline" | ||
|
||
tags = { | ||
Environment = var.environment | ||
CreatedBy = var.repo_name | ||
} | ||
} | ||
|
||
resource "aws_iam_instance_profile" "db_migration_role_profile" { | ||
name = "${var.environment}-${var.component_name}-DbMigrationRole" | ||
role = aws_iam_role.db_migration_role.name | ||
} | ||
|
||
data "aws_iam_policy_document" "db_migration_user_policy_doc" { | ||
statement { | ||
actions = [ | ||
"rds-db:connect" | ||
] | ||
|
||
resources = [ | ||
"arn:aws:rds-db:${var.region}:${data.aws_caller_identity.current.account_id}:dbuser:${data.aws_ssm_parameter.db_cluster_resource_id.value}/${postgresql_role.migration_user.name}" | ||
] | ||
|
||
effect = "Allow" | ||
} | ||
} | ||
|
||
resource "aws_iam_policy" "db_migration_user_policy" { | ||
name = "${var.environment}-${var.component_name}-db_migration_user" | ||
policy = data.aws_iam_policy_document.db_migration_user_policy_doc.json | ||
} | ||
|
||
resource "aws_iam_role_policy_attachment" "db_migration_user_policy_attach" { | ||
role = aws_iam_role.db_migration_role.name | ||
policy_arn = aws_iam_policy.db_migration_user_policy.arn | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
provider "aws" { | ||
region = var.region | ||
profile = "default" | ||
region = var.region | ||
} | ||
|
||
terraform { | ||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = "~> 4.0" | ||
version = "3.75.1" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.