-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Single CloudWatch logging role for API Gateways (#89)
Create single CloudWatch log role for API Gateways API Gateway's CloudWatch logging role is account- and region-specific. This moves that role's creation to a single place rather than in both the cirrus and stac-server module as that leads to constant state drift.
- Loading branch information
1 parent
1bddd7f
commit 3ae1b4f
Showing
9 changed files
with
89 additions
and
116 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
57 changes: 57 additions & 0 deletions
57
modules/base_infra/api_gateway_account/api_gateway_account.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,57 @@ | ||
locals { | ||
name_prefix = "fd-${var.project_name}-${var.environment}" | ||
} | ||
|
||
|
||
resource "aws_iam_role" "shared_api_gw_logging_role" { | ||
name_prefix = "${local.name_prefix}-${data.aws_region.current.name}-apigw-" | ||
|
||
assume_role_policy = <<-JSON_POLICY_STRING | ||
{ | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Action": "sts:AssumeRole", | ||
"Principal": { | ||
"Service": "apigateway.amazonaws.com" | ||
}, | ||
"Effect": "Allow" | ||
} | ||
] | ||
} | ||
JSON_POLICY_STRING | ||
} | ||
|
||
resource "aws_iam_policy" "shared_api_gw_logging_role" { | ||
name_prefix = "${local.name_prefix}-${data.aws_region.current.name}-apigw-log-policy-" | ||
|
||
policy = <<-JSON_POLICY_STRING | ||
{ | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Action": [ | ||
"logs:CreateLogGroup", | ||
"logs:CreateLogStream", | ||
"logs:DescribeLogGroups", | ||
"logs:DescribeLogStreams", | ||
"logs:PutLogEvents", | ||
"logs:GetLogEvents", | ||
"logs:FilterLogEvents" | ||
], | ||
"Resource": "*", | ||
"Effect": "Allow" | ||
} | ||
] | ||
} | ||
JSON_POLICY_STRING | ||
} | ||
|
||
resource "aws_iam_role_policy_attachment" "shared_api_gw_logging_role" { | ||
role = aws_iam_role.shared_api_gw_logging_role.name | ||
policy_arn = aws_iam_policy.shared_api_gw_logging_role.arn | ||
} | ||
|
||
resource "aws_api_gateway_account" "shared_api_gw_logging_role" { | ||
cloudwatch_role_arn = aws_iam_role.shared_api_gw_logging_role.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 |
---|---|---|
@@ -0,0 +1 @@ | ||
data "aws_region" "current" {} |
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,9 @@ | ||
variable "project_name" { | ||
description = "Project Name" | ||
type = string | ||
} | ||
|
||
variable "environment" { | ||
description = "Project environment" | ||
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,9 @@ | ||
terraform { | ||
required_version = ">= 1.6.6, < 1.8.0" | ||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = "~> 5.22" | ||
} | ||
} | ||
} |
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