Open mmshin opened 2 years ago
Btw, I found a better solution. Turns out Resource: aws_vpc_ipam_pool_cidr_allocation
returns cidr
attribute but it wasn't in the documentation
This is not a bug but perhaps is a poorly documented side effect of the resource & data source: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resource/vpc_ipam_preview_next_cidr
one note: you titled data source
but include code for the resource
. they have the same effect in this circumstance but in others have different side effects.
The reason youre experiencing this is because the resource/ds are effectively running the command aws ec2 allocate-ipam-pool-cidr --preview --ipam-pool-id <>
which will simply return the next available CIDR without allocating it. if you were to run that command multiple times without using the allocation, IPAM sees the cidr as still available. The purpose for this is to overcome very particular situations where you MUST know the CIDR ahead of time but is not required in most definitions of terraform for creating a VPC (see below)
One way around this is to not preview the cidr and instead to just use aws_vpc
with ipam parameters to make the calls on your behalf. I have a VPC module that should satisfy most vpc requirements and fully integrates with ipam for ipv4 vpcs: https://registry.terraform.io/modules/aws-ia/vpc/aws/latest
Marking this issue as stale due to inactivity. This helps our maintainers find and focus on the active issues. If this issue receives no comments in the next 30 days it will automatically be closed. Maintainers can also remove the stale label.
If this issue was automatically closed and you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thank you!
Community Note
Terraform CLI and Terraform AWS Provider Version
Affected Resource(s)
Terraform Configuration Files
I have written a module to allocate IP from the CIDR Pool using the IPAM Preview Next CIDR because I need to get the CIDR as an output to be used by a different project.
Expected Output
data.aws_vpc_ipam_preview_next_cidr.subnet.*.cidr
It will produce different CIDR per count.index
Actual Output
data.aws_vpc_ipam_preview_next_cidr.subnet.*.cidr produced the same cidr