generated from ministryofjustice/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5503 from ministryofjustice/feature/ap-ingestion-…
…ingress 🚚 Add egress functionality to Analytical Platform Ingestion
- Loading branch information
Showing
15 changed files
with
220 additions
and
51 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
terraform/environments/analytical-platform-ingestion/cloudwatch-log-groups.tf
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,2 +1 @@ | ||
#### This file can be used to store data specific to the member account #### | ||
data "aws_availability_zones" "available" {} |
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
108 changes: 108 additions & 0 deletions
108
...vironments/analytical-platform-ingestion/modules/transfer-family/user-with-egress/main.tf
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,108 @@ | ||
data "aws_iam_policy_document" "this" { | ||
statement { | ||
sid = "AllowKMS" | ||
effect = "Allow" | ||
actions = [ | ||
"kms:ReEncrypt*", | ||
"kms:GenerateDataKey*", | ||
"kms:Encrypt", | ||
"kms:DescribeKey", | ||
"kms:Decrypt", | ||
] | ||
resources = [ | ||
var.landing_bucket_kms_key, | ||
var.egress_bucket_kms_key | ||
] | ||
} | ||
statement { | ||
sid = "AllowS3ListBucket" | ||
effect = "Allow" | ||
actions = ["s3:ListBucket"] | ||
resources = [ | ||
"arn:aws:s3:::${var.landing_bucket}", | ||
"arn:aws:s3:::${var.egress_bucket}" | ||
] | ||
} | ||
statement { | ||
sid = "AllowS3LandingBucketObjectActions" | ||
effect = "Allow" | ||
actions = ["s3:PutObject"] | ||
resources = ["arn:aws:s3:::${var.landing_bucket}/${var.name}/*"] | ||
} | ||
statement { | ||
sid = "AllowS3EgressBucketObjectActions" | ||
effect = "Allow" | ||
actions = [ | ||
"s3:GetObject", | ||
"s3:GetObjectAcl", | ||
"s3:GetObjectVersion" | ||
] | ||
resources = ["arn:aws:s3:::${var.egress_bucket}/${var.name}/*"] | ||
} | ||
} | ||
|
||
module "policy" { | ||
#checkov:skip=CKV_TF_1:Module registry does not support commit hashes for versions | ||
|
||
source = "terraform-aws-modules/iam/aws//modules/iam-policy" | ||
version = "5.37.1" | ||
|
||
name_prefix = "transfer-user-${var.name}" | ||
|
||
policy = data.aws_iam_policy_document.this.json | ||
} | ||
|
||
module "role" { | ||
#checkov:skip=CKV_TF_1:Module registry does not support commit hashes for versions | ||
|
||
source = "terraform-aws-modules/iam/aws//modules/iam-assumable-role" | ||
version = "5.37.1" | ||
|
||
create_role = true | ||
|
||
role_name = "transfer-user-${var.name}" | ||
role_requires_mfa = false | ||
|
||
trusted_role_services = ["transfer.amazonaws.com"] | ||
|
||
custom_role_policy_arns = [module.policy.arn] | ||
} | ||
|
||
resource "aws_transfer_user" "this" { | ||
server_id = var.transfer_server | ||
user_name = var.name | ||
role = module.role.iam_role_arn | ||
|
||
home_directory_type = "LOGICAL" | ||
home_directory_mappings { | ||
entry = "/upload" | ||
target = "/${var.landing_bucket}/${var.name}" | ||
} | ||
|
||
home_directory_mappings { | ||
entry = "/download" | ||
target = "/${var.egress_bucket}/${var.name}" | ||
} | ||
} | ||
|
||
resource "aws_transfer_ssh_key" "this" { | ||
server_id = var.transfer_server | ||
user_name = aws_transfer_user.this.user_name | ||
body = var.ssh_key | ||
} | ||
|
||
resource "aws_security_group_rule" "this" { | ||
type = "ingress" | ||
from_port = 2222 | ||
to_port = 2222 | ||
protocol = "tcp" | ||
cidr_blocks = var.cidr_blocks | ||
security_group_id = var.transfer_server_security_group | ||
} | ||
|
||
resource "aws_secretsmanager_secret" "this" { | ||
for_each = toset(["technical-contact", "data-contact", "target-bucket"]) | ||
|
||
name = "ingestion/sftp/${var.name}/${each.key}" | ||
kms_key_id = var.supplier_data_kms_key | ||
} |
39 changes: 39 additions & 0 deletions
39
...ments/analytical-platform-ingestion/modules/transfer-family/user-with-egress/variables.tf
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,39 @@ | ||
variable "name" { | ||
type = string | ||
} | ||
|
||
variable "ssh_key" { | ||
type = string | ||
} | ||
|
||
variable "cidr_blocks" { | ||
type = list(string) | ||
} | ||
|
||
variable "transfer_server" { | ||
type = string | ||
} | ||
|
||
variable "transfer_server_security_group" { | ||
type = string | ||
} | ||
|
||
variable "landing_bucket" { | ||
type = string | ||
} | ||
|
||
variable "landing_bucket_kms_key" { | ||
type = string | ||
} | ||
|
||
variable "egress_bucket" { | ||
type = string | ||
} | ||
|
||
variable "egress_bucket_kms_key" { | ||
type = string | ||
} | ||
|
||
variable "supplier_data_kms_key" { | ||
type = string | ||
} |
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
2 changes: 2 additions & 0 deletions
2
terraform/environments/analytical-platform-ingestion/observability-platform.tf
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.