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

Allow Creating a DNS record for a claimed IP #29

Open
coteforbes opened this issue Jun 16, 2023 · 5 comments
Open

Allow Creating a DNS record for a claimed IP #29

coteforbes opened this issue Jun 16, 2023 · 5 comments

Comments

@coteforbes
Copy link

It seems as though if you use 'menandmice_ipam_record' and mark 'claimed = true', when you pass that IP to 'menandmice_dns_record', you get an error that the IP address is claimed. If you mark 'claimed=false' and attempt to assign multiple IP addresses, terraform will grab the same IP for multiple records.

@Martin-Metz
Copy link
Contributor

Yes, without a temp claim time it would always return the same IP. Please use the temp_claim_time to claim it
for a certain time and then just use the IP, e.g. in the following example the next free IP would be held for 30 seconds.
All other free_ip calls would skip over the IP to the next free one.

resource "menandmice_ipam_record" "ipam" {
  free_ip {
    range    = "192.168.6.0/24"
    start_at = "192.168.6.51"
    temporary_claim_time = "30"
    ping     = true
  }
  claimed = false
}

Then you can use it e.g. in an A record:
data = menandmice_ipam_record.ipam.address

@coteforbes
Copy link
Author

When you don't explicitly specify temporary_claim_time, it defaults to 60s so that functionality doesn't appear to be working properly it seems.

I tried doing a 5 second claim time and then a 7 second wait between the IPAM record assignment and the A record creation but am getting the same behavior.

@Martin-Metz
Copy link
Contributor

Right - it defaults to 60 seconds, i.e. the temp claim is not necessary here.
But I tested it now with version 0.4.0 and Micetro 10.5.0 and I can't reproduce it. E.g. the following TF creates two A records with two different IPs claimed by free_ip:

resource "menandmice_ipam_record" "ip1" {
  free_ip {
    range    = "192.168.6.0/24"
    start_at = "192.168.6.51"
  }
  claimed           = false
}

resource "menandmice_ipam_record" "ip2" {
  free_ip {
    range    = "192.168.6.0/24"
    start_at = "192.168.6.51"
  }
  claimed           = false
}

# 0.4.0 difference to providers <=0.3.0 : current_address is deprecated and "address" should be used 
resource "menandmice_dns_record" "rec1" {
  name   = "testip1"
  zone   = "example.net."
  server = "externaldns2.company.example.com."
  data   = menandmice_ipam_record.ip1.address # next free address in 192.168.6.0/24 starting at .51
  type   = "A"
}

resource "menandmice_dns_record" "rec2" {
  name   = "testip2"
  zone   = "example.net."
  server = "externaldns2.company.example.com."
  data   = menandmice_ipam_record.ip2.address # next free address in 192.168.6.0/24 starting at .51
  type   = "A"
}

output "ip1" {
  value = resource.menandmice_ipam_record.ip1.address
}
output "ip2" {
  value = resource.menandmice_ipam_record.ip2.address
}

with the following output:

Plan: 4 to add, 0 to change, 0 to destroy.

Changes to Outputs:
  + ip1 = (known after apply)
  + ip2 = (known after apply)

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

menandmice_ipam_record.ip2: Creating...
menandmice_ipam_record.ip1: Creating...
menandmice_ipam_record.ip1: Creation complete after 0s [id=ipamRecords/165940]
menandmice_dns_record.rec1: Creating...
menandmice_ipam_record.ip2: Creation complete after 1s [id=ipamRecords/166424]
menandmice_dns_record.rec2: Creating...
menandmice_dns_record.rec1: Creation complete after 0s [id=dnsRecords/916163]
menandmice_dns_record.rec2: Creation complete after 0s [id=dnsRecords/916165]

Apply complete! Resources: 4 added, 0 changed, 0 destroyed.

Outputs:

ip1 = "192.168.6.51"
ip2 = "192.168.6.52"

and in Micetro IPAM:

image

@coteforbes
Copy link
Author

Very Odd, I had the IPAM and DNS records in an module. I copied your code above to make 2 records with DNS entries and they both grabbed the same IP still.

TF v1.3.7
menandmice 4.0
Micetro v10.5

tf_ipam

@lopf
Copy link

lopf commented Nov 8, 2023

I can confirm this is still happening.

TF v1.5.7
menandmice 0.4.0
Micetro 10.5.2

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

3 participants