Skip to content

Commit

Permalink
e2e: use DNS instead of HTTP to get my_public_ipv4 (hashicorp#17759)
Browse files Browse the repository at this point in the history
  • Loading branch information
gulducat authored Jun 28, 2023
1 parent 350c435 commit 6bd5098
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions e2e/terraform/network.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,18 @@ data "aws_subnet" "secondary" {
}
}

data "http" "my_public_ipv4" {
url = "https://api.ipify.org"
# using a dns lookup instead of http, because it's faster
# and should be more reliable.
data "external" "my_public_ipv4" {
program = ["/bin/sh", "-c", <<-EOT
ip="$(dig @resolver4.opendns.com myip.opendns.com +short -4)"
echo '{"ip": "'$ip'"}'
EOT
]
}

locals {
ingress_cidr = var.restrict_ingress_cidrblock ? "${chomp(data.http.my_public_ipv4.body)}/32" : "0.0.0.0/0"
ingress_cidr = var.restrict_ingress_cidrblock ? "${chomp(data.external.my_public_ipv4.result["ip"])}/32" : "0.0.0.0/0"
}

resource "aws_security_group" "servers" {
Expand Down

0 comments on commit 6bd5098

Please sign in to comment.