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

IPAM Address remains "Assigned" after running Terraform Destroy - Can't clear or make free again. #30

Open
jacobbweber opened this issue Mar 2, 2024 · 0 comments

Comments

@jacobbweber
Copy link

Info:

App version: Micetro 10.5.4
provider version: 0.4.0
Status: Licensed

Issue:

When running resource: menandmice_ipam_record, it will find the first free IP address starting at 192.168.10.40 that is not claimed and can't ping. By default, will claim it for 60 seconds. resource:  menandmice_ipam_record will create DNS A record "testrecord" using that free IP.

After running terraform destroy, the DNS A Record is removed, IPAM shows no DNS record associated to the IP used, but the IP in IPAM remains assigned. I cannot clear it, when I test ping it, it shows red status indicating no successful ping. Not sure how to make it "Free" again.

Performing these steps manually via the web interface works.

Config:

providers.tf

terraform {
    required_providers {
        menandmice = {
            source = "menandmice/menandmice"
            version = '0.4.0'
        }
    }
}

provider "menandmice" {
    endpoint = "https://menandmice.example.com"
    username = var.ipam_user
    password = var.ipam_password
    tls_verify = true
}

main.tf

variable "ipam_user" {
  description = "ipam username"
  type        = string
}

variable "ipam_password" {
  description = "ipam password"
  type        = string
  sensitive   = true
}

data "menandmice_dns_zone" "zone" {
  name   = "example.com."
  server = "dc.example.com."
}

resource "menandmice_ipam_record" "ipam_ip" {
  free_ip {
    range    = "192.168.10.0/24"
    start_at = "192.168.10.40"
    ping     = true
  }
  claimed = false
}

resource "menandmice_dns_record" "rec" {
  name   = "testrecord"
  zone   = data.menandmice_dns_zone.zone.name # "zone1.net."
  server = data.menandmice_dns_zone.zone.server
  data   = menandmice_ipam_record.ipam_ip.address
  type   = "A"
}

Steps to reproduce

$env:TF_VAR_ipam_user = ''
$env:TF_VAR_ipam_password = ''
terraform init
terraform validate
terraform apply

Result:
Next free IP is found, then used to create the DNS A record.

Result Outputs

Outputs:

dns_record = {
    'aging' = tonumber(null)
    'comment' = ''
    'data' = '192.168.10.41'
    'dns_zone_ref' = 'dnsZones/23'
    'enabled' = true
    'fqdn' = 'testrecord.example.com.'
    'id' = 'dnsRecords/2170718'
    'name' = 'testrecord'
    'ref' = 'dnsRecords/2170718'
    'server' = 'dc.example.com.'
    'ttl' = 3600
    'type' = 'A'
    'view' = tostring(null)
    'zone' = 'example.com.'
}
free_ip = {
    'address' = '192.168.10.41'
    'claimed' = false
    'current_address' = '192.168.10.41'
    'custom_properties' = tomap(null) /* of string */
    'device' = ''
    'discovery_type' = 'None'
    'extraneous_ptr' = false
    'free_ip' = tolist([
        {
            'exclude_dhcp' = false
            'ping' = true
            'range' = '192.168.10.0/24'
            'start_at' = '192.168.10.40'
            'temporary_claim_time' = 60
        },
        ])
    'id' = 'ipamRecords/33400'
    'interface' = ''
    'last_discovery_date' = ''
    'last_known_client_identifier' = ''
    'last_seen_date' = ''
    'ptr_status' = 'OK'
    'ref' = 'ipamRecords/33400'
    'state' = 'Free'
    'usage' = 0
}
terraform destroy

Result:
DNS A record is cleaned up, IPAM IP address used remains stuck as assigned.

Result Outputs

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  - destroy

Terraform will perform the following actions:

  # menandmice_dns_record.rec will be destroyed
  - resource "menandmice_dns_record" "rec" {
      - data         = "192.168.10.41" -> null
      - dns_zone_ref = "dnsZones/23" -> null
      - enabled      = true -> null
      - fqdn         = "testrecord.example.com." -> null
      - id           = "dnsRecords/2170718" -> null
      - name         = "testrecord" -> null
      - ref          = "dnsRecords/2170718" -> null
      - server       = "dc.example.com." -> null
      - ttl          = 3600 -> null
      - type         = "A" -> null
      - zone         = "example.com." -> null
    }

  # menandmice_ipam_record.ipam_ip will be destroyed
  - resource "menandmice_ipam_record" "ipam_ip" {
      - address           = "192.168.10.41" -> null
      - claimed           = false -> null
      - current_address   = "192.168.10.41" -> null
      - custom_properties = {} -> null
      - discovery_type    = "None" -> null
      - extraneous_ptr    = false -> null
      - id                = "ipamRecords/33400" -> null
      - ptr_status        = "OK" -> null
      - ref               = "ipamRecords/33400" -> null
      - state             = "Assigned" -> null
      - usage             = 16388 -> null

      - free_ip {
          - exclude_dhcp         = false -> null
          - ping                 = true -> null
          - range                = "192.168.10.0/24" -> null
          - start_at             = "192.168.10.40" -> null
          - temporary_claim_time = 60 -> null
        }
    }

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

Changes to Outputs:
  - dns_record = {
      - aging        = null
      - comment      = ""
      - data         = "192.168.10.41"
      - dns_zone_ref = "dnsZones/23"
      - enabled      = true
      - fqdn         = "testrecord.example.com."
      - id           = "dnsRecords/2170718"
      - name         = "testrecord"
      - ref          = "dnsRecords/2170718"
      - server       = "dc.example.com."
      - ttl          = null
      - type         = "A"
      - view         = null
      - zone         = "example.com."
    } -> null
  - free_ip    = {
      - address                      = "192.168.10.41"
      - claimed                      = false
      - current_address              = "192.168.10.41"
      - custom_properties            = {}
      - device                       = ""
      - discovery_type               = "None"
      - extraneous_ptr               = false
      - free_ip                      = [
          - {
              - exclude_dhcp         = false
              - ping                 = true
              - range                = "192.168.10.0/24"
              - start_at             = "192.168.10.40"
              - temporary_claim_time = 60
            },
        ]
      - id                           = "ipamRecords/33400"
      - interface                    = ""
      - last_discovery_date          = ""
      - last_known_client_identifier = ""
      - last_seen_date               = ""
      - ptr_status                   = "OK"
      - ref                          = "ipamRecords/33400"
      - state                        = "Assigned"
      - usage                        = 16388
    } -> null
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

1 participant