File tree Expand file tree Collapse file tree 3 files changed +58
-1
lines changed Expand file tree Collapse file tree 3 files changed +58
-1
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,9 @@ module "api-gateway" {
12
12
# Api Gateway Resource
13
13
path_parts = [" mytestresource" ]
14
14
15
+ # #endpoint_configuration
16
+ types = [" PRIVATE" ]
17
+
15
18
# Api Gateway Method
16
19
method_enabled = true
17
20
http_methods = [" GET" ]
55
58
# Api Gateway Stage
56
59
stage_enabled = true
57
60
stage_names = [" qa" ]
61
+ # # Api Policy
62
+
63
+ api_policy = data. aws_iam_policy_document . test . json
64
+
65
+ }
66
+
67
+ data "aws_iam_policy_document" "test" {
68
+ statement {
69
+ effect = " Allow"
70
+
71
+ principals {
72
+ type = " AWS"
73
+ identifiers = [" *" ]
74
+ }
75
+
76
+ actions = [" execute-api:Invoke" ]
77
+ resources = [module . api-gateway . execution_arn ]
78
+
79
+ condition {
80
+ test = " IpAddress"
81
+ variable = " aws:SourceIp"
82
+ values = [" 123.123.123.123/32" ]
83
+ }
84
+ }
58
85
}
Original file line number Diff line number Diff line change 83
83
# Api Gateway Api Key
84
84
key_count = 2
85
85
key_names = [" test" , " test1" ]
86
+
87
+ # # Api Policy
88
+
89
+ api_policy = data. aws_iam_policy_document . test . json
90
+
86
91
}
92
+
93
+ data "aws_iam_policy_document" "test" {
94
+ statement {
95
+ effect = " Allow"
96
+
97
+ principals {
98
+ type = " AWS"
99
+ identifiers = [" *" ]
100
+ }
101
+
102
+ actions = [" execute-api:Invoke" ]
103
+ resources = [module . api-gateway . execution_arn ]
104
+
105
+ condition {
106
+ test = " IpAddress"
107
+ variable = " aws:SourceIp"
108
+ values = [" 123.123.123.123/32" ]
109
+ }
110
+ }
111
+ }
Original file line number Diff line number Diff line change @@ -33,10 +33,15 @@ resource "aws_api_gateway_rest_api" "default" {
33
33
types = var. types
34
34
vpc_endpoint_ids = length (var. vpc_endpoint_ids ) > 0 && var. vpc_endpoint_ids [0 ] != " " ? var. vpc_endpoint_ids : null
35
35
}
36
- policy = var. api_policy
37
36
tags = var. tags
38
37
}
39
38
39
+
40
+ resource "aws_api_gateway_rest_api_policy" "test" {
41
+ rest_api_id = join (" " , aws_api_gateway_rest_api. default . * . id )
42
+ policy = var. api_policy
43
+ }
44
+
40
45
# Module : Api Gateway Resource
41
46
# Description : Terraform module to create Api Gateway resource on AWS.
42
47
resource "aws_api_gateway_resource" "default" {
You can’t perform that action at this time.
0 commit comments