Reputation: 2860
I am unable to create private IP with terraform with "count" in-built variable.
It errors out stating that IP address in "reserved IP range".
Please find below my code block.
resource "azurerm_network_interface" "tf_ax_nic" {
count=5
name = "subnet_app_aos_nic_${count.index}"
location = "${data.azurerm_resource_group.tf_rg.location}"
resource_group_name = "${data.azurerm_resource_group.tf_rg.name}"
ip_configuration {
name = "ax_${count.index}.ip"
subnet_id = "${data.azurerm_subnet.tf_sn_ax.id}"
private_ip_address_allocation = "static"
private_ip_address ="10.100.3.${count.index}"
}
tags {
environment = "${var.env}"
}
}
Any hep would be greatly appreciated.
Thank you very much.
Upvotes: 0
Views: 2726
Reputation: 31452
There will be reserved first four IP addresses in the subnet by Azure and the IP addresses cannot be assigned to resources. You can see the description in the Private IP address Allocation method like this:
Azure reserves the first four addresses in each subnet address range, so the addresses cannot be assigned to resources. For example, if the subnet's address range is 10.0.0.0/16, addresses 10.0.0.0-10.0.0.3 cannot be assigned to resources.
So I think you just need to use the offset as
private_ip_address="10.100.3.${count.index+4}"
Upvotes: 2
Reputation: 2860
Answer is to use offset private_ip_address="10.100.3.${count.index+5}"
Upvotes: 0