-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Includes IAM permissions, X-Ray, function URL and records the environment deployment in GitHub. For VEGA-1942 #minor
- Loading branch information
Showing
19 changed files
with
348 additions
and
20 deletions.
There are no files selected for viewing
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
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,4 @@ | ||
output "lambda_url" { | ||
description = "Public URL of 'create' Lambda function" | ||
value = module.eu_west_1.lambda_url | ||
} |
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,72 @@ | ||
resource "aws_kms_key" "cloudwatch" { | ||
description = "CloudWatch ${terraform.workspace} ${data.aws_region.current.name}" | ||
deletion_window_in_days = 10 | ||
policy = data.aws_iam_policy_document.cloudwatch_kms.json | ||
enable_key_rotation = true | ||
|
||
provider = aws.region | ||
} | ||
|
||
resource "aws_kms_alias" "cloudwatch_standard_alias" { | ||
name = "alias/cloudwatch-${var.environment_name}" | ||
target_key_id = aws_kms_key.cloudwatch.key_id | ||
|
||
provider = aws.region | ||
} | ||
|
||
data "aws_iam_policy_document" "cloudwatch_kms" { | ||
statement { | ||
sid = "Enable Root account permissions on Key" | ||
effect = "Allow" | ||
actions = ["kms:*"] | ||
resources = ["*"] | ||
principals { | ||
type = "AWS" | ||
identifiers = [ | ||
"arn:aws:iam::${data.aws_caller_identity.current.account_id}:root", | ||
] | ||
} | ||
} | ||
statement { | ||
sid = "Allow Key to be used for Encryption" | ||
effect = "Allow" | ||
resources = ["*"] | ||
actions = [ | ||
"kms:Encrypt", | ||
"kms:Decrypt", | ||
"kms:ReEncrypt*", | ||
"kms:GenerateDataKey*", | ||
"kms:DescribeKey", | ||
] | ||
principals { | ||
type = "Service" | ||
identifiers = ["logs.${data.aws_region.current.name}.amazonaws.com"] | ||
} | ||
} | ||
statement { | ||
sid = "Key Administrator" | ||
effect = "Allow" | ||
resources = ["*"] | ||
actions = [ | ||
"kms:Create*", | ||
"kms:Describe*", | ||
"kms:Enable*", | ||
"kms:List*", | ||
"kms:Put*", | ||
"kms:Update*", | ||
"kms:Revoke*", | ||
"kms:Disable*", | ||
"kms:Get*", | ||
"kms:Delete*", | ||
"kms:TagResource", | ||
"kms:UntagResource", | ||
"kms:ScheduleKeyDeletion", | ||
"kms:CancelKeyDeletion" | ||
] | ||
|
||
principals { | ||
type = "AWS" | ||
identifiers = ["arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/breakglass"] | ||
} | ||
} | ||
} |
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,47 @@ | ||
locals { | ||
functions = toset([ | ||
"create", | ||
# "get", | ||
# "update", | ||
]) | ||
} | ||
|
||
module "lambda" { | ||
for_each = local.functions | ||
source = "../../modules/lambda" | ||
|
||
environment_name = var.environment_name | ||
lambda_name = each.key | ||
ecr_image_uri = "${data.aws_ecr_repository.lambda[each.key].repository_url}:${var.app_version}" | ||
cloudwatch_kms_key_id = aws_kms_key.cloudwatch.arn | ||
|
||
providers = { | ||
aws = aws.region | ||
} | ||
} | ||
|
||
data "aws_ecr_repository" "lambda" { | ||
for_each = local.functions | ||
name = "lpa-store/lambda/api-${each.key}" | ||
provider = aws.management | ||
} | ||
|
||
resource "aws_iam_role_policy" "lambda" { | ||
for_each = local.functions | ||
name = "lambda" | ||
role = module.lambda[each.key].iam_role_id | ||
policy = data.aws_iam_policy_document.lambda_access_ddb.json | ||
provider = aws.region | ||
} | ||
|
||
data "aws_iam_policy_document" "lambda_access_ddb" { | ||
statement { | ||
sid = "allowDynamoDB" | ||
effect = "Allow" | ||
resources = [var.dynamodb_arn] | ||
actions = [ | ||
"dynamodb:PutItem", | ||
"dynamodb:GetItem", | ||
] | ||
} | ||
} |
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,4 @@ | ||
output "lambda_url" { | ||
description = "Public URL of 'create' Lambda function" | ||
value = module.lambda["create"].function_url | ||
} |
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,25 @@ | ||
terraform { | ||
required_version = ">= 1.4.0" | ||
|
||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
configuration_aliases = [ | ||
aws.region, | ||
aws.management, | ||
] | ||
} | ||
} | ||
} | ||
|
||
data "aws_region" "current" { | ||
provider = aws.region | ||
} | ||
|
||
data "aws_caller_identity" "current" { | ||
provider = aws.region | ||
} | ||
|
||
data "aws_default_tags" "current" { | ||
provider = aws.region | ||
} |
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,14 @@ | ||
variable "environment_name" { | ||
description = "The name of the environment the region is deployed to" | ||
type = string | ||
} | ||
|
||
variable "app_version" { | ||
description = "Version of application to deploy" | ||
type = string | ||
} | ||
|
||
variable "dynamodb_arn" { | ||
description = "ARN of DynamoDB global endpoint" | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module "eu_west_1" { | ||
source = "./region" | ||
|
||
app_version = var.app_version | ||
dynamodb_arn = aws_dynamodb_table.deeds_table.arn | ||
environment_name = local.environment_name | ||
|
||
providers = { | ||
aws.region = aws.eu_west_1 | ||
aws.management = aws.management_eu_west_1 | ||
} | ||
} | ||
|
||
module "eu_west_2" { | ||
source = "./region" | ||
|
||
app_version = var.app_version | ||
dynamodb_arn = aws_dynamodb_table_replica.deeds_table.arn | ||
environment_name = local.environment_name | ||
|
||
providers = { | ||
aws.region = aws.eu_west_2 | ||
aws.management = aws.management_eu_west_2 | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
resource "aws_iam_role" "lambda" { | ||
name = "lambda-${var.lambda_name}-${var.environment_name}-${data.aws_region.current.name}" | ||
assume_role_policy = data.aws_iam_policy_document.lambda_assume.json | ||
|
||
lifecycle { | ||
create_before_destroy = true | ||
} | ||
} | ||
|
||
data "aws_iam_policy_document" "lambda_assume" { | ||
statement { | ||
actions = ["sts:AssumeRole"] | ||
|
||
principals { | ||
type = "Service" | ||
identifiers = ["lambda.amazonaws.com"] | ||
} | ||
} | ||
} | ||
|
||
resource "aws_iam_role_policy_attachment" "aws_xray_write_only_access" { | ||
role = aws_iam_role.lambda.name | ||
policy_arn = "arn:aws:iam::aws:policy/AWSXrayWriteOnlyAccess" | ||
} | ||
|
||
resource "aws_iam_role_policy_attachment" "vpc_access_execution_role" { | ||
role = aws_iam_role.lambda.name | ||
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole" | ||
} | ||
|
||
resource "aws_iam_role_policy" "lambda" { | ||
name = "lambda" | ||
role = aws_iam_role.lambda.id | ||
policy = data.aws_iam_policy_document.lambda.json | ||
} | ||
|
||
data "aws_iam_policy_document" "lambda" { | ||
statement { | ||
sid = "allowLogging" | ||
effect = "Allow" | ||
resources = [aws_cloudwatch_log_group.lambda.arn] | ||
actions = [ | ||
"logs:CreateLogStream", | ||
"logs:PutLogEvents", | ||
"logs:DescribeLogStreams" | ||
] | ||
} | ||
} | ||
|
||
resource "aws_lambda_permission" "allow_lambda_execution_operator" { | ||
statement_id = "AllowExecutionOperator" | ||
action = "lambda:InvokeFunction" | ||
function_name = aws_lambda_function.main.function_name | ||
principal = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/operator" | ||
} |
Oops, something went wrong.