Stop hard-coding IP addresses in your firewall rules and security groups. This Terraform module automatically detects the public IP address of the machine running Terraform, so you can dynamically lock down access to only your current location — no manual lookups, no stale addresses.
What you get:
- Returns IPv4 IP Address by Default: The default usage of the module returns the IPv4 IP Address, but is configurable for IPv6 if necessary.
- Zero manual steps: No more visiting “what is my IP” websites — the module does it for you.
- Always current: Every
terraform applypicks up your latest public IP, keeping firewall rules in sync with where you actually are. - Works everywhere: Use with Azure NSGs, AWS Security Groups, GCP firewall rules, or any resource that accepts a CIDR block.
- Customizable source: Swap the lookup URL if you prefer a different provider or need to query an internal endpoint.
Usage Example
module "myip" {
source = "Build5Nines/myip/http"
}
resource "azurerm_network_security_rule" "allow_ssh" {
name = "AllowSSHFromMyIP"
priority = 100
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "22"
source_address_prefix = "${module.myip.ip_address}/32"
destination_address_prefix = "*"
resource_group_name = azurerm_resource_group.main.name
network_security_group_name = azurerm_network_security_group.main.name
}