This repository has been archived by the owner on May 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
bastion.tf
132 lines (112 loc) · 4.46 KB
/
bastion.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
resource "aws_api_gateway_resource" "bastion" {
parent_id = aws_api_gateway_rest_api.bastion.root_resource_id
path_part = "bastion"
rest_api_id = aws_api_gateway_rest_api.bastion.id
}
resource "aws_api_gateway_model" "bastion" {
rest_api_id = aws_api_gateway_rest_api.bastion.id
name = "Bastion"
content_type = "application/json"
schema = <<-EOT
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Bastion",
"type": "object",
"additionalProperties": false,
"properties": {
"ip": {
"type": "string"
}
},
"required": [
"ip"
]
}
EOT
}
#
# POST /bastion
#
resource "aws_api_gateway_method" "post_bastion" {
authorization = "AWS_IAM"
http_method = "POST"
resource_id = aws_api_gateway_resource.bastion.id
rest_api_id = aws_api_gateway_rest_api.bastion.id
}
resource "aws_api_gateway_method_response" "post_bastion" {
depends_on = [
aws_api_gateway_method.post_bastion]
http_method = "POST"
resource_id = aws_api_gateway_resource.bastion.id
response_models = {
"application/json" = aws_api_gateway_model.bastion.name
}
rest_api_id = aws_api_gateway_rest_api.bastion.id
status_code = "201"
}
module "create_bastion_function" {
source = "./lambda/create-bastion"
cluster_arn = var.cluster_arn
cluster_name = var.cluster_name
cluster_subnet_ids = var.cluster_subnet_ids
cluster_vpc_default_security_group_id = var.cluster_vpc_default_security_group_id
cluster_vpc_id = var.cluster_vpc_id
container_name = var.container_name
execution_role_arn = var.execution_role_arn
http_method = aws_api_gateway_method.post_bastion.http_method
resource_path = aws_api_gateway_resource.bastion.path
rest_api_id = aws_api_gateway_rest_api.bastion.id
task_family = var.task_family
task_role_arn = var.task_role_arn
}
resource "aws_api_gateway_integration" "post_bastion" {
http_method = aws_api_gateway_method.post_bastion.http_method
resource_id = aws_api_gateway_resource.bastion.id
rest_api_id = aws_api_gateway_rest_api.bastion.id
type = "AWS_PROXY"
integration_http_method = "POST"
uri = "arn:aws:apigateway:${data.aws_region.current.name}:lambda:path/2015-03-31/functions/${module.create_bastion_function.function_arn}/invocations"
}
#
# DELETE /bastion
#
resource "aws_api_gateway_method" "delete_bastion" {
authorization = "AWS_IAM"
http_method = "DELETE"
resource_id = aws_api_gateway_resource.bastion.id
rest_api_id = aws_api_gateway_rest_api.bastion.id
}
resource "aws_api_gateway_method_response" "delete_bastion" {
depends_on = [
aws_api_gateway_method.delete_bastion]
http_method = "POST"
resource_id = aws_api_gateway_resource.bastion.id
response_models = {
"application/json" = "Empty"
}
rest_api_id = aws_api_gateway_rest_api.bastion.id
status_code = "200"
}
module "destroy_bastion_function" {
source = "./lambda/destroy-bastion"
cluster_arn = var.cluster_arn
cluster_name = var.cluster_name
cluster_vpc_default_security_group_id = var.cluster_vpc_default_security_group_id
cluster_vpc_id = var.cluster_vpc_id
}
module "trigger_bastion_destruction_function" {
source = "./lambda/trigger-bastion-destruction"
destroy_bastion_function_arn = module.destroy_bastion_function.function_arn
destroy_bastion_function_name = module.destroy_bastion_function.function_name
http_method = aws_api_gateway_method.delete_bastion.http_method
resource_path = aws_api_gateway_resource.bastion.path
rest_api_id = aws_api_gateway_rest_api.bastion.id
}
resource "aws_api_gateway_integration" "delete_bastion" {
http_method = aws_api_gateway_method.delete_bastion.http_method
resource_id = aws_api_gateway_resource.bastion.id
rest_api_id = aws_api_gateway_rest_api.bastion.id
type = "AWS_PROXY"
integration_http_method = "POST"
uri = "arn:aws:apigateway:${data.aws_region.current.name}:lambda:path/2015-03-31/functions/${module.trigger_bastion_destruction_function.function_arn}/invocations"
}