Skip to content

Instantly share code, notes, and snippets.

@michaeljoy
Created November 20, 2019 02:35
Show Gist options
  • Save michaeljoy/129f6636a0058a0cce2f8739a4f5af9c to your computer and use it in GitHub Desktop.
Save michaeljoy/129f6636a0058a0cce2f8739a4f5af9c to your computer and use it in GitHub Desktop.
Terraform 0.12 json public IP via http data provider, jsondecode, for all your 'where am I actually running this build needs' - my_public_ip.tf
data "http" "my_public_ip" {
url = "https://ifconfig.co/json"
request_headers = {
Accept = "application/json"
}
}
locals {
ifconfig_co_json = jsondecode(data.http.my_public_ip.body)
}
output "my_ip_addr" {
value = local.ifconfig_co_json.ip
}
@michaeljoy
Copy link
Author

michaeljoy commented Nov 20, 2019

This is an IPv4 single IP ingress rule example with ICMP.

ingress {
  from_port = 0
  to_port = 0
  protocol = "-1"
  cidr_blocks = ["${local.ifconfig_co_json.ip)}/32"]
}

@michaeljoy
Copy link
Author

michaeljoy commented Nov 20, 2019

This works against any URL running this project's service : https://github.com/mpolden/echoip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment