Skip to content

Instantly share code, notes, and snippets.

@karl-cardenas-coding
Last active May 29, 2020 15:28

Revisions

  1. karl-cardenas-coding revised this gist Mar 7, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion try.tf
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,7 @@ data "http" "primary-server" {

    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).syncTokenMadeUp,
    syncToken = try(jsondecode(data.http.primary-server.body).syncToken,
    "NO TOKEN AVAILABLE"
    )

  2. karl-cardenas-coding revised this gist Mar 7, 2020. 1 changed file with 15 additions and 3 deletions.
    18 changes: 15 additions & 3 deletions try.tf
    Original file line number Diff line number Diff line change
    @@ -11,24 +11,36 @@ data "http" "primary-server" {

    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,
    syncToken = try(jsondecode(data.http.primary-server.body).syncTokenMadeUp,
    "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")

    # This variable holds the all the IPs addresses for the S3 service returned by the endpoint. The return value is of the type list OR a string error value.
    s3_ips = try(distinct([
    for items in jsondecode(data.http.primary-server.body).prefixes:
    items.ip_prefix if items.service == "S3"
    ]), "NO LIST PROVIDED IN LOCALS SERVICES VARIABLE")

    }

    output "response-json-syncToken" {
    value = local.syncToken
    }

    output "response-json-s3-ips" {
    value = local.s3_ips
    }

    output "response-json-regions" {
  3. karl-cardenas-coding created this gist Mar 7, 2020.
    40 changes: 40 additions & 0 deletions try.tf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,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
    }