'Terraform ip range
I'm in the process of trying to create a list of ip's using a combination of a for loop and the range function. I'm trying to get the loop to iterate through the range of numbers and appending that number as the last digits in an ip address.
locals {
windows_ip_list = [for i in range(var.Number) : format("%s%02d", "10.16.0.1", i)]
}
Giving the variable var.Number a value of 5 creates a 5 element tuple but the following error is probvided.
│ 9: private_ip = local.windows_ip_list #var.win_ip[count.index]
│ ├────────────────
│ │ local.windows_ip_list is tuple with 5 elements
│
│ Inappropriate value for attribute "private_ip": string required.
resource "aws_instance" "Windows" {
ami = "ami-02c1f4de3809f0050"
instance_type = "t2.large"
#subnet_id = aws_subnet.Engineering[count.index].id
subnet_id = aws_subnet.windows.id
security_groups = [aws_security_group.Engineering.id]
key_name = aws_key_pair.ENG-DEV.id
count = var.Number
private_ip = local.windows_ip_list #var.win_ip[count.index]
associate_public_ip_address = false
Any help creating the desired list would be appreciated.
Thanks in advance.
Solution 1:[1]
Calling the variable and using the count.index was how it was fixed.
private_ip = local.windows_ip_list[count.index]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | user15695494 |
