CiscoDevNet / terraform-provider-mso

Terraform Cisco MSO provider
https://registry.terraform.io/providers/CiscoDevNet/mso/latest/docs
Mozilla Public License 2.0
7 stars 28 forks source link

Adding service graph to contract fails when template is associated with multiple sites #233

Closed andbyrne closed 5 months ago

andbyrne commented 11 months ago

Community Note

Terraform Version

Terraform v1.5.4 on darwin_arm64

MSO version

APIC version and APIC Platform for Site Level Resources

Affected Resource(s)

Terraform Configuration Files

resource "mso_schema_template_contract_service_graph" "C1-A" {
  schema_id          = mso_schema.S1.id
  site_id            = mso_schema_site.S1-A.id
  template_name      = "T1"
  contract_name      = mso_schema_template_contract.C1.contract_name
  service_graph_name = mso_schema_template_service_graph.SG1.service_graph_name
  node_relationship {
    provider_connector_bd_name                = mso_schema_template_bd.BD1.name
    consumer_connector_bd_name                = mso_schema_template_bd.BD1.name
    provider_connector_cluster_interface      = "INT1"
    consumer_connector_cluster_interface      = "INT1"
    provider_connector_redirect_policy_tenant = "service_graph_bug"
    provider_connector_redirect_policy        = "PBR1"
    consumer_connector_redirect_policy_tenant = "service_graph_bug"
    consumer_connector_redirect_policy        = "PBR1"
  }
}

resource "mso_schema_template_contract_service_graph" "C1-B" {
  schema_id          = mso_schema.S1.id
  site_id            = mso_schema_site.S1-B.id
  template_name      = "T1"
  contract_name      = mso_schema_template_contract.C1.contract_name
  service_graph_name = mso_schema_template_service_graph.SG1.service_graph_name
  node_relationship {
    provider_connector_bd_name                = mso_schema_template_bd.BD1.name
    consumer_connector_bd_name                = mso_schema_template_bd.BD1.name
    provider_connector_cluster_interface      = "INT1"
    consumer_connector_cluster_interface      = "INT1"
    provider_connector_redirect_policy_tenant = "service_graph_bug"
    provider_connector_redirect_policy        = "PBR1"
    consumer_connector_redirect_policy_tenant = "service_graph_bug"
    consumer_connector_redirect_policy        = "PBR1"
  }
}

Debug Output

Terraform will perform the following actions:

  # mso_schema_template_contract_service_graph.C1-A will be created
  + resource "mso_schema_template_contract_service_graph" "C1-A" {
      + contract_name      = "C1"
      + id                 = (known after apply)
      + schema_id          = "64c357b989c60aeac3238a59"
      + service_graph_name = "SG1"
      + site_id            = "64c1c5ef9bf0739b4edad5c6"
      + template_name      = "T1"

      + node_relationship {
          + consumer_connector_bd_name                = "BD1"
          + consumer_connector_cluster_interface      = "INT1"
          + consumer_connector_redirect_policy        = "PBR1"
          + consumer_connector_redirect_policy_tenant = "service_graph_bug"
          + consumer_subnet_ips                       = (known after apply)
          + provider_connector_bd_name                = "BD1"
          + provider_connector_cluster_interface      = "INT1"
          + provider_connector_redirect_policy        = "PBR1"
          + provider_connector_redirect_policy_tenant = "service_graph_bug"
          + provider_subnet_ips                       = (known after apply)
        }
    }

  # mso_schema_template_contract_service_graph.C1-B will be created
  + resource "mso_schema_template_contract_service_graph" "C1-B" {
      + contract_name      = "C1"
      + id                 = (known after apply)
      + schema_id          = "64c357b989c60aeac3238a59"
      + service_graph_name = "SG1"
      + site_id            = "64c1c5fd9bf0739b4edad5c7"
      + template_name      = "T1"

      + node_relationship {
          + consumer_connector_bd_name                = "BD1"
          + consumer_connector_cluster_interface      = "INT1"
          + consumer_connector_redirect_policy        = "PBR1"
          + consumer_connector_redirect_policy_tenant = "service_graph_bug"
          + consumer_subnet_ips                       = (known after apply)
          + provider_connector_bd_name                = "BD1"
          + provider_connector_cluster_interface      = "INT1"
          + provider_connector_redirect_policy        = "PBR1"
          + provider_connector_redirect_policy_tenant = "service_graph_bug"
          + provider_subnet_ips                       = (known after apply)
        }
    }

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

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

mso_schema_template_contract_service_graph.C1-B: Creating...
mso_schema_template_contract_service_graph.C1-A: Creating...
╷
│ Error: "site-local Contract C1 in site SITE-B in template T1: missing Service Graph configuration"{}
│ 
│   with mso_schema_template_contract_service_graph.C1-A,
│   on ndo.tf line 115, in resource "mso_schema_template_contract_service_graph" "C1-A":
│  115: resource "mso_schema_template_contract_service_graph" "C1-A" {
│ 
╵
╷
│ Error: "site-local Contract C1 in site SITE-A in template T1: missing Service Graph configuration"{}
│ 
│   with mso_schema_template_contract_service_graph.C1-B,
│   on ndo.tf line 133, in resource "mso_schema_template_contract_service_graph" "C1-B":
│  133: resource "mso_schema_template_contract_service_graph" "C1-B" {
│ 

Recommendation

The mso_schema_template_contract_service_graph resource should have the site_id under the node_relationship block so that the configuration for each site can be specified in a single resource.

resource "mso_schema_template_contract_service_graph" "C1" {
  schema_id          = mso_schema.S1.id
  template_name      = "T1"
  contract_name      = mso_schema_template_contract.C1.contract_name
  service_graph_name = mso_schema_template_service_graph.SG1.service_graph_name
  node_relationship {
    site_id                                   = mso_schema_site.S1-A.id
    provider_connector_bd_name                = mso_schema_template_bd.BD1.name
    consumer_connector_bd_name                = mso_schema_template_bd.BD1.name
    provider_connector_cluster_interface      = "INT1"
    consumer_connector_cluster_interface      = "INT1"
    provider_connector_redirect_policy_tenant = "service_graph_bug"
    provider_connector_redirect_policy        = "PBR1"
    consumer_connector_redirect_policy_tenant = "service_graph_bug"
    consumer_connector_redirect_policy        = "PBR1"
  }
  node_relationship {
    site_id                                   = mso_schema_site.S1-B.id
    provider_connector_bd_name                = mso_schema_template_bd.BD1.name
    consumer_connector_bd_name                = mso_schema_template_bd.BD1.name
    provider_connector_cluster_interface      = "INT1"
    consumer_connector_cluster_interface      = "INT1"
    provider_connector_redirect_policy_tenant = "service_graph_bug"
    provider_connector_redirect_policy        = "PBR1"
    consumer_connector_redirect_policy_tenant = "service_graph_bug"
    consumer_connector_redirect_policy        = "PBR1"
  }
}
lhercot commented 11 months ago

Keeping as separate now but this might be related to #190 and the fix for it might apply to both.

lhercot commented 5 months ago

Closing this issue has we have merged a series of PRs to fix this and related Service Graph issues.

See https://github.com/CiscoDevNet/terraform-provider-mso/pull/244 and https://github.com/CiscoDevNet/terraform-provider-mso/pull/256 as part of those changes.