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

BD with DHCP Relay Fails. NDO Version 4.1.2e and provider version 0.10.0 #221

Closed
scotttyso opened this issue Jun 19, 2023 · 8 comments · Fixed by #230
Closed

BD with DHCP Relay Fails. NDO Version 4.1.2e and provider version 0.10.0 #221

scotttyso opened this issue Jun 19, 2023 · 8 comments · Fixed by #230
Assignees

Comments

@scotttyso
Copy link

scotttyso commented Jun 19, 2023

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform Version

v1.4.5

MSO version

  • V 0.10.0

APIC version and APIC Platform for Site Level Resources

  • V 6.0.2 and on-prem

Affected Resource(s)

  • mso_schema_template_bd both data and resource

Terraform Configuration Files

locals {
  dhcp_relay_policies = ["ad1", "ad2"]
  template_id = flatten([
    for key, value in jsondecode(data.mso_rest.templates.content) : [
      for v in value : v if v.templateType == "tenantPolicy" && v.templateName == "common" && v.tenantName == "common"
    ]
  ])[0].templateId
  schemas = ["common", "terraform"]
  tenants = ["common", "terraform"]
}
data "mso_rest" "templates" {
  #path = "/mso/api/v1/tenants/templates"
  path     = "api/v1/tenants/templates"
  provider = mso
}

output "template_id" {
  #value = data.mso_rest.tenant_policy.content
  value = local.template_id
}

data "mso_rest" "versions" {
  path     = "api/v1/templates/${local.template_id}/versions/status"
  provider = mso
}

output "versions" {
  value = jsondecode(data.mso_rest.versions.content).version
}

data "mso_tenant" "tenants" {
  for_each     = { for v in local.tenants : v => v }
  name         = each.value
  display_name = each.value
}

data "mso_schema" "schemas" {
  for_each = { for v in local.schemas : v => v }
  name     = each.value
}

output "schemas" {
  value = { for k in sort(keys(data.mso_schema.schemas)) : k => data.mso_schema.schemas[k].id }
}

output "tenants" {
  value = { for k in sort(keys(data.mso_tenant.tenants)) : k => data.mso_tenant.tenants[k].id }
}
#resource "mso_schema_template_bd" "bd" {
#  arp_flooding      = true
#  display_name      = "testBD"
#  name              = "testBD"
#  schema_id         = data.mso_schema.schemas["terraform"].id
#  template_name     = "terraform"
#  vrf_name          = "dmz"
#  vrf_schema_id     = data.mso_schema.schemas["common"].id
#  vrf_template_name = "common"
#  #dynamic "dhcp_policies" {
#  #  for_each = { for v in local.dhcp_relay_policies : v => v }
#  #  content {
#  #    name    = dhcp_policies.value
#  #    version = jsondecode(data.mso_rest.versions.content).version
#  #  }
#  #}
#}

data "mso_schema_template_bd" "testBD" {
  name          = "testBD"
  schema_id     = data.mso_schema.schemas["terraform"].id
  template_name = "terraform"
}

Debug Output

Panic Output

│ Error: strconv.Atoi: parsing "{}": invalid syntax
│ 
│   with data.mso_schema_template_bd.testBD,
│   on main.tf line 67, in data "mso_schema_template_bd" "testBD":
│   67: data "mso_schema_template_bd" "testBD" {
│ 

Expected Behavior

the DHCP Relay Policies are failing to apply. It added two dhcp relay policies to the BD with empty values.

After completing the plan I get the following fault from terraform

│ Error: strconv.Atoi: parsing "{}": invalid syntax

I cleared my terraform state and commented out the resource and tried to read the bd object and I then get the same error message.

│ Error: strconv.Atoi: parsing "{}": invalid syntax
│ 
│   with data.mso_schema_template_bd.testBD,
│   on main.tf line 67, in data "mso_schema_template_bd" "testBD":
│   67: data "mso_schema_template_bd" "testBD" {
│ 

I then created a BD manually in the UI and tried to read it with the same data source and got the same error messages.

I removed the dhcp relay policies from both BD's that I created and the plan works.

I added the dhcp relay policy back to the BD and ran with just the data resource and it failed with the same error message.

It seems to be a bug with the provider.

Actual Behavior

│ Error: strconv.Atoi: parsing "{}": invalid syntax
│ 
│   with data.mso_schema_template_bd.testBD,
│   on main.tf line 67, in data "mso_schema_template_bd" "testBD":
│   67: data "mso_schema_template_bd" "testBD" {
│ 

Steps to Reproduce

Attempt to add or read a bridge domain with a dhcp relay policy attached in NDO version 4.1 with the provider 0.10.0

  1. terraform apply

Important Factoids

References

  • #0000
@scotttyso
Copy link
Author

scotttyso commented Jun 19, 2023

From the API Browser I am able to see a Bridge Domain with DHCP Relay policies attached. This doesn't seem to be a problem with the API. It seems to be a problem with the provider in my testing.

I used the rest resource and adding a few other calls to see how it interacts. It seems to be able to read a dhcp policy with the mso_rest data

locals {
  dhcp_relay_policy_names = ["ad1", "ad2"]
  template_id = flatten([
    for key, value in jsondecode(data.mso_rest.templates.content) : [
      for v in value : v if v.templateType == "tenantPolicy" && v.templateName == "common" && v.tenantName == "common"
    ]
  ])[0].templateId
}

data "mso_rest" "templates" {
  path     = "api/v1/tenants/templates"
  provider = mso
}

data "mso_rest" "tenant_policies" {
  path = "api/v1/templates/${local.template_id}"
}

output "tenant_policies_dhcp_relays" {
  value = { for i in flatten([
    for v in jsondecode(data.mso_rest.tenant_policies.content).tenantPolicyTemplate.template.dhcpRelayPolicies : [
        for e in local.dhcp_relay_policy_names : {
            name = v.name
            uuid = v.uuid
        } if v.name == e
    ]
  ]) : "${i.name}" => i.uuid }
}

outputs with this

tyscott@TYSCOTT-DESKTOP:~/terraform-cisco-modules/test2$ terraform output
tenant_policies_dhcp_relays = {
  "ad1" = "fdf9561d-53c6-4366-8ab3-c3fc52ff2def"
  "ad2" = "dc7431fc-0a70-4961-b479-20d47394053b"
}
tyscott@TYSCOTT-DESKTOP:~/terraform-cisco-modules/test2$ 

@lhercot
Copy link
Member

lhercot commented Jun 22, 2023

Might be already fixed by #220

@sajagana sajagana self-assigned this Jun 30, 2023
@sajagana
Copy link
Collaborator

Hi @scotttyso,

I just tested the mso_schema_template_bd resource issue with the latest master source code. The Atoi Issue was fixed with another PR: #220.

@scotttyso
Copy link
Author

@sajagana - When will it be released?

@lhercot
Copy link
Member

lhercot commented Jul 1, 2023

I just released v0.11.0. Please let us know if this issue is fixed now.

@lhercot
Copy link
Member

lhercot commented Jul 7, 2023

@scotttyso Have you had the time to check if the latest release has fixed the issue?

@scotttyso
Copy link
Author

scotttyso commented Jul 8, 2023

@lhercot
Unfortunately it not resolved and it seems to be introducing another problem.

When I run a plan/apply. The first attempt says it is successful

tyscott@TYSCOTT-DESKTOP:~/terraform-cisco-modules/ndo-test$ tfa
module.tenants["terraform"].mso_schema_template_bd.bridge_domains["10.88.203.0"]: Modifying... [id=10.88.203.0]
module.tenants["terraform"].mso_schema_template_bd.bridge_domains["10.88.203.0"]: Modifications complete after 1s [id=10.88.203.0]
module.tenants["terraform"].mso_schema_template_bd_subnet.bridge_domain_subnets["10.88.203.0:10.88.203.1/24"]: Creating...
module.tenants["terraform"].mso_schema_template_bd_subnet.bridge_domain_subnets["10.88.203.0:10.88.203.1/24"]: Creation complete after 0s [id=10.88.203.1]

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

But when I go to NDO the value in the dhcp relay policies is blank

Running a plan again it says it is going to delete and re-add

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following
symbols:
  ~ update in-place

Terraform will perform the following actions:

  # module.tenants["terraform"].mso_schema_template_bd.bridge_domains["10.88.203.0"] will be updated in-place
  ~ resource "mso_schema_template_bd" "bridge_domains" {
        id                              = "10.88.203.0"
        name                            = "10.88.203.0"
        # (18 unchanged attributes hidden)

      - dhcp_policies {
          - dhcp_option_policy_version = 0 -> null
          - name                       = "dummy" -> null
          - version                    = 0 -> null
        }
      + dhcp_policies {
          + dhcp_option_policy_name    = (known after apply)
          + dhcp_option_policy_version = (known after apply)
          + name                       = "dummy"
          + version                    = 3
        }
    }

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

────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

Saved the plan to: main.plan

To perform exactly these actions, run the following command to apply:
    terraform apply "main.plan"

This second round actually impacts the bridge domain subnet, and the next plan starts the re-create of the relay and subnet associations:

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following
symbols:
  + create
  ~ update in-place

Terraform will perform the following actions:

  # module.tenants["terraform"].mso_schema_template_bd.bridge_domains["10.88.203.0"] will be updated in-place
  ~ resource "mso_schema_template_bd" "bridge_domains" {
        id                              = "10.88.203.0"
        name                            = "10.88.203.0"
        # (18 unchanged attributes hidden)

      - dhcp_policies {
          - dhcp_option_policy_version = 0 -> null
          - name                       = "dummy" -> null
          - version                    = 0 -> null
        }
      + dhcp_policies {
          + dhcp_option_policy_name    = (known after apply)
          + dhcp_option_policy_version = (known after apply)
          + name                       = "dummy"
          + version                    = 3
        }
    }

  # module.tenants["terraform"].mso_schema_template_bd_subnet.bridge_domain_subnets["10.88.203.0:10.88.203.1/24"] will be created
  + resource "mso_schema_template_bd_subnet" "bridge_domain_subnets" {
      + bd_name            = "10.88.203.0"
      + description        = (known after apply)
      + id                 = (known after apply)
      + ip                 = "10.88.203.1/24"
      + no_default_gateway = false
      + querier            = false
      + schema_id          = "64703625321af62f63df94b5"
      + scope              = "public"
      + shared             = false
      + template_name      = "terraform"
    }

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

────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

Saved the plan to: main.plan

To perform exactly these actions, run the following command to apply:
    terraform apply "main.plan"
tyscott@TYSCOTT-DESKTOP:~/terraform-cisco-modules/ndo-test$ 

@scotttyso
Copy link
Author

scotttyso commented Jul 29, 2023

This issue is not solved. I am sorry for the delay but I had other customer requests for a while

Right now I just pushed a new SCHEMA with 2 BDs/EPGs/domains etc.

If I do a terraform plan it shows there are no changes


No changes. Your infrastructure matches the configuration.

Terraform has compared your real infrastructure against your configuration and found no differences, so no changes are needed.

If I now add in the DHCP policies to the resources

You will see the only update is the DHCP Policies

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # module.tenants["RICH"].mso_schema_template_bd.map["198.18.101.0"] will be updated in-place
  ~ resource "mso_schema_template_bd" "map" {
        id                              = "198.18.101.0"
        name                            = "198.18.101.0"
        # (18 unchanged attributes hidden)

      + dhcp_policies {
          + dhcp_option_policy_name    = "default"
          + dhcp_option_policy_version = 3
          + name                       = "10.101.128.15"
          + version                    = 0
        }
      + dhcp_policies {
          + dhcp_option_policy_name    = "default"
          + dhcp_option_policy_version = 3
          + name                       = "10.101.128.16"
          + version                    = 0
        }
    }

  # module.tenants["RICH"].mso_schema_template_bd.map["198.18.102.0"] will be updated in-place
  ~ resource "mso_schema_template_bd" "map" {
        id                              = "198.18.102.0"
        name                            = "198.18.102.0"
        # (18 unchanged attributes hidden)

      + dhcp_policies {
          + dhcp_option_policy_name    = "default"
          + dhcp_option_policy_version = 3
          + name                       = "10.101.128.15"
          + version                    = 0
        }
      + dhcp_policies {
          + dhcp_option_policy_name    = "default"
          + dhcp_option_policy_version = 3
          + name                       = "10.101.128.16"
          + version                    = 0
        }
    }

Plan: 0 to add, 2 to change, 0 to destroy.
tyscott@TYSCOTT-DESKTOP:~/terraform-cisco-modules/easy-aci/RICH/Odin$ tfa
module.tenants["RICH"].mso_schema_template_bd.map["198.18.102.0"]: Modifying... [id=198.18.102.0]
module.tenants["RICH"].mso_schema_template_bd.map["198.18.101.0"]: Modifying... [id=198.18.101.0]
╷
│ Error: strconv.Atoi: parsing "{}": invalid syntax
│ 
│   with module.tenants["RICH"].mso_schema_template_bd.map["198.18.101.0"],
│   on ../../../terraform-aci-tenants/bridge-domains.tf line 209, in resource "mso_schema_template_bd" "map":
│  209: resource "mso_schema_template_bd" "map" {
│ 
╵
╷
│ Error: strconv.Atoi: parsing "{}": invalid syntax
│ 
│   with module.tenants["RICH"].mso_schema_template_bd.map["198.18.102.0"],
│   on ../../../terraform-aci-tenants/bridge-domains.tf line 209, in resource "mso_schema_template_bd" "map":
│  209: resource "mso_schema_template_bd" "map" {
│ 
╵
tyscott@TYSCOTT-DESKTOP:~/terraform-cisco-modules/easy-aci/RICH/Odin$ 

And now the state is corrupt and I can't do anything with terraform.

The only way to recover is to delete the terraform state. Manually delete the objects in the UI or painfully re-import the objects one at a time.

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

Successfully merging a pull request may close this issue.

3 participants