forked from fortunkam/apim-devops-demos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdadjokeAPI.tf
149 lines (137 loc) · 4.26 KB
/
dadjokeAPI.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
resource "azurerm_api_management_api" "dadjoke" {
name = "dad-joke"
resource_group_name = local.resource_group_name
api_management_name = data.azurerm_api_management.apim.name
revision = "1"
display_name = "Dad Joke"
path = "joke"
protocols = ["https"]
import {
content_format = "swagger-json"
content_value = file("swagger.json")
}
}
resource "azurerm_api_management_api_policy" "dadjoke" {
api_name = azurerm_api_management_api.dadjoke.name
resource_group_name = local.resource_group_name
api_management_name = data.azurerm_api_management.apim.name
xml_content = <<XML
<policies>
<inbound>
<base />
<set-backend-service backend-id="ICanHazDadJoke" />
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
</outbound>
<on-error>
<base />
</on-error>
</policies>
XML
}
resource "azurerm_api_management_api_operation_policy" "get-a-random-joke" {
api_name = azurerm_api_management_api.dadjoke.name
resource_group_name = local.resource_group_name
api_management_name = data.azurerm_api_management.apim.name
operation_id = "get-a-random-joke"
xml_content = <<XML
<policies>
<inbound>
<base />
<rewrite-uri template="/" copy-unmatched-params="false" />
<set-header name="Accept" exists-action="override">
<value>application/json</value>
</set-header>
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
</outbound>
<on-error>
<base />
</on-error>
</policies>
XML
}
# resource "azurerm_api_management_api_operation_tag" "get-a-random-joke-joke-tag" {
# api_operation_id = "get-a-random-joke"
# name = azurerm_api_management_tag.joke.name
# display_name = azurerm_api_management_tag.joke.name
# }
resource "azurerm_api_management_api_operation_policy" "get-joke" {
api_name = azurerm_api_management_api.dadjoke.name
resource_group_name = local.resource_group_name
api_management_name = data.azurerm_api_management.apim.name
operation_id = "get-joke"
xml_content = <<XML
<policies>
<inbound>
<base />
<rewrite-uri template="/j/{id}" copy-unmatched-params="false" />
<set-header name="Accept" exists-action="override">
<value>application/json</value>
</set-header>
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
</outbound>
<on-error>
<base />
</on-error>
</policies>
XML
}
resource "azurerm_api_management_api_operation_policy" "joke-search" {
api_name = azurerm_api_management_api.dadjoke.name
resource_group_name = local.resource_group_name
api_management_name = data.azurerm_api_management.apim.name
operation_id = "search-for-jokes"
xml_content = <<XML
<policies>
<inbound>
<base />
<rewrite-uri template="/search" copy-unmatched-params="false" />
<set-header name="Accept" exists-action="override">
<value>application/json</value>
</set-header>
<set-variable name="jsonBody" value="@{
return context.Request.Body.As<JObject>();
}" />
<set-query-parameter name="page" exists-action="override">
<value>@(((JObject)context.Variables["jsonBody"])["page"].ToString())</value>
</set-query-parameter>
<set-query-parameter name="term" exists-action="override">
<value>@(((JObject)context.Variables["jsonBody"])["term"].ToString())</value>
</set-query-parameter>
<set-query-parameter name="limit" exists-action="override">
<value>{{ DadJokePageLimit }}</value>
</set-query-parameter>
<set-method>GET</set-method>
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
</outbound>
<on-error>
<base />
</on-error>
</policies>
XML
}
resource "azurerm_api_management_product_api" "dadjoke-product" {
api_name = azurerm_api_management_api.dadjoke.name
product_id = azurerm_api_management_product.dadjoke.product_id
resource_group_name = local.resource_group_name
api_management_name = data.azurerm_api_management.apim.name
}