-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
85 lines (68 loc) · 1.75 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
resource "aws_sqs_queue" "queue" {
name = var.queue_name
delay_seconds = 0
max_message_size = 262144
message_retention_seconds = 86400
receive_wait_time_seconds = 10
tags = var.queue_tags
}
resource "aws_iam_role" "apiSQS" {
name = var.apigateway_rolename
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "apigateway.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
EOF
}
data "template_file" "gateway_policy" {
template = file("${path.module}/policies/api-gateway-permission.json")
vars = {
sqs_arn = aws_sqs_queue.queue.arn
}
}
resource "aws_iam_policy" "api_policy" {
name = "api-sqs-cloudwatch-policy"
policy = data.template_file.gateway_policy.rendered
}
resource "aws_iam_role_policy_attachment" "api_exec_role" {
role = aws_iam_role.apiSQS.name
policy_arn = aws_iam_policy.api_policy.arn
}
data "template_file" "_" {
template = var.api_template
vars = {
api_arn = aws_iam_role.apiSQS.arn
sqs_arn = aws_sqs_queue.queue.arn
}
# vars = var.api_template_vars
}
resource "aws_api_gateway_rest_api" "apiGateway" {
name = var.api_name
api_key_source = "HEADER"
binary_media_types = var.binary_media_types
description = var.api_description
body = data.template_file._.rendered
endpoint_configuration {
types = ["REGIONAL"]
}
}
resource "aws_api_gateway_deployment" "api" {
rest_api_id = aws_api_gateway_rest_api.apiGateway.id
stage_name = var.stage_name
triggers = {
redeployment = sha1(data.template_file._.rendered)
}
lifecycle {
create_before_destroy = true
}
}