-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
58 lines (49 loc) · 1.53 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
terraform {
required_version = ">= 0.12.1"
}
locals {
region = var.region == "" ? var.aws_region : var.region
}
module "label" {
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.15.0"
namespace = var.namespace
stage = var.stage
delimiter = var.delimiter
name = var.name
attributes = var.attributes
tags = merge(var.tags, { Region = local.region })
}
module "role_label" {
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.15.0"
context = module.label.context
attributes = [local.region]
}
data "aws_iam_policy_document" "trust" {
statement {
effect = "Allow"
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["apigateway.amazonaws.com"]
}
condition {
test = "StringEquals"
variable = "aws:RequestedRegion"
values = [var.aws_region]
}
}
}
resource "aws_iam_role" "logging" {
name = module.role_label.id
tags = module.role_label.tags
path = "/service/"
description = "Role for APIGateway in ${local.region} to use CloudWatch logs"
assume_role_policy = data.aws_iam_policy_document.trust.json
}
resource "aws_iam_role_policy_attachment" "allow_cloudwatch" {
role = aws_iam_role.logging.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonAPIGatewayPushToCloudWatchLogs"
}
resource "aws_api_gateway_account" "settings" {
cloudwatch_role_arn = aws_iam_role.logging.arn
}