lord-kyron / terraform-provider-phpipam

Terrform provider for PHPIPAM
https://registry.terraform.io/providers/lord-kyron/phpipam/latest
Apache License 2.0
54 stars 30 forks source link

`Error getting custom fields for updating: Error from API (200): No custom fields defined` #73

Closed eugene-marchanka closed 1 year ago

eugene-marchanka commented 1 year ago

I'm recently upgraded to 1.5.2 and started getting error:

phpipam_first_free_subnet.new_subnet: Modifying... [id=1608]
╷
│ Error: Error getting custom fields for updating: Error from API (200): No custom fields defined
│ 
│   with phpipam_first_free_subnet.new_subnet,
│   on networking.tf line 6, in resource "phpipam_first_free_subnet" "new_subnet":
│    6: resource "phpipam_first_free_subnet" "new_subnet" {
│ 
╵

.tf is pretty standard:

data "phpipam_subnet" "master-subnet" {
  subnet_address = var.master_subnet_ip
  subnet_mask    = var.master_subnet_mask
}

resource "phpipam_first_free_subnet" "new_subnet" {
  parent_subnet_id = data.phpipam_subnet.master-subnet.subnet_id
  subnet_mask      = var.vpc_subnet_cidr_length
  description      = format("EKS subnet for %s", var.cluster_domain)
  custom_fields = {
    custom_Field = "custom-Field"
  }
  vrf_id           = 1
  is_full          = true
}

Any ideas why it is failing? Thanks!

pavel-z1 commented 1 year ago

Hi @eugene-marchanka

According to the README file use next custom field format: ⚠️ NOTE on custom fields: PHPIPAM installations with custom fields must have all fields set to optional when using this plugin. For more info see https://github.com/phpipam/phpipam/issues/1073. Further to this, either ensure that your fields also do not have default values, or ensure the default is set in your TF configuration. Diff loops may happen otherwise! Custom fileds must contain mandatory prefix custom_.

Example:

data "phpipam_section" "section" {
  name = "Customers"
}

resource "phpipam_subnet" "subnet" {
  section_id     = data.phpipam_section.section.section_id
  subnet_address = "10.10.3.0"
  subnet_mask    = 24

  custom_fields = {
    custom_CustomTestSubnets = "terraform-test"
  }
}
eugene-marchanka commented 1 year ago

Was able to solve it by providing empty custom_fields and specific lifecycle:

resource "phpipam_first_free_subnet" "new_subnet" {
  parent_subnet_id = data.phpipam_subnet.master-subnet.subnet_id
  subnet_mask      = var.vpc_subnet_cidr_length
  description      = format("EKS subnet for %s", var.cluster_domain)
  vrf_id           = 1
  is_full          = true
  custom_fields    = {}
  lifecycle {
    ignore_changes = [
      section_id
    ]
  }
}