-
Notifications
You must be signed in to change notification settings - Fork 2
/
try.tf
40 lines (30 loc) · 1.13 KB
/
try.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
# Try example
data "http" "primary-server" {
url = "https://ip-ranges.amazonaws.com/ip-ranges.json"
# Optional request headers
request_headers = {
Accept = "application/json"
}
}
locals {
# This returns the sync token from the endpoint, the return value is of the type string.
syncToken = try(jsondecode(data.http.primary-server.body).syncToken,
"NO TOKEN AVAILABLE"
)
# This variable holds the all the unique regions returned by the endpoint. The return value is of the type list OR a string error value.
regions = try(distinct([
for items in jsondecode(data.http.primary-server.body).prefixes:
items.region
]), "NO LIST PROVIDED IN LOCALS REGION VARIABLE")
# This variable holds the all the unique services returned by the endpoint. The return value is of the type list OR a string error value.
services = try(distinct([
for items in jsondecode(data.http.primary-server.body).prefixes:
items.service
]), "NO LIST PROVIDED IN LOCALS SERVICES VARIABLE")
}
output "response-json-regions" {
value = local.regions
}
output "response-json-services" {
value = local.services
}