Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to define name in allocation #9

Closed
robertbrandso opened this issue Nov 24, 2023 · 2 comments
Closed

Add option to define name in allocation #9

robertbrandso opened this issue Nov 24, 2023 · 2 comments

Comments

@robertbrandso
Copy link

It would be great if it was possible to add a name of some kind for the allocation in the json file, to easier present the content of the json file in some kind of documentation or something.

Suggested configuration

resource "ipam_pool" "main" {
  cidr = "10.0.0.0/8"
}

resource "ipam_allocation" "foo" {
  name    = "foo"
  pool_id = ipam_pool.main.id
  size    = 24
}
@agrrh
Copy link
Owner

agrrh commented Nov 25, 2023

This provider heavily relies on metal-stack/go-ipam, which does not support prefixes naming at the moment.

metal-stack/go-ipam#99

We at metal-stack store these information alongside the gathered IP/Prefix.

Would it suit your needs to present data with tf state show?

# ipam_allocation.customer_a:
resource "ipam_allocation" "customer_a" {
    cidr    = "10.2.0.0/16"
    id      = "10.2.0.0/16"
    pool_id = "10.0.0.0/8"
    size    = 16
}

@robertbrandso
Copy link
Author

Understand. Thank you anyway!

I may do something like this to solve what I'm after:

# Create IPAM allocations
locals {
  apps = toset([
    "app1",
    "app2",
    "app3"
  ])
}

resource "ipam_allocation" "apps" {
  for_each = local.apps

  pool_id = ipam_pool.main.id
  size    = 24
}

# Output IPAM allocation with application name as key and IP allocation as value 
output "apps_ip_allocation" {
  description = "Shows every IP allocation done for apps."
  value       = { for k,v in ipam_allocation.apps : k => v.cidr }
}

To get a JSON file, we can for example doterraform output -json | jq '.apps_ip_allocation.value' > ipam_allocations.json.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants