CiscoDevNet / terraform-provider-catalystcenter

Terraform Cisco Catalyst Center Provider
https://registry.terraform.io/providers/CiscoDevNet/catalystcenter
Mozilla Public License 2.0
8 stars 7 forks source link

Attaching a network profile to a day0 template #155

Open sudhanshujoshi23 opened 1 day ago

sudhanshujoshi23 commented 1 day ago

I am trying to attach a network profile to a day0 template using the below configuration, but I don't understand why it doesn't work. Can someone please let me know what I am missing here?

resource "catalystcenter_template" "base_template" {
  project_id       = "${catalystcenter_project.base_project.id}"
  name             = "C9200-C9300_Template"
  description      = "Jinja Template"
  device_types     = var.device_types
  language         = "JINJA"
  software_type    = "IOS-XE"
  software_variant = "XE"
  software_version = "16.12.1a"
  template_content = file("./modules/template/day0_template.j2")
  template_params = {{  some_params }}
  composite = false
}

resource "catalystcenter_network_profile" "network_profile" {
  name = "Network Profile for C9200-9300 switches"
  type = "switching"
  templates = [
    {
      type = "day0.templates"
      attributes = [
        {
          template_id = catalystcenter_template.base_template.id
        }
      ]
    }
  ]
}
sudhanshujoshi23 commented 1 day ago

For context, my terraform configuration is applied successfully without any errors, the template and network profiles are created. But the network profile isn't attached to the template.

kuba-mazurkiewicz commented 1 day ago

@sudhanshujoshi23 which DNAC version are you using?

I just creatd network profile and cli template and attach it as onboarding template to network_profile using following code:

terraform {
  required_providers {
    catalystcenter = {
      source  = "CiscoDevNet/catalystcenter"
      version = "0.1.16"
    }
  }
}

resource "catalystcenter_project" "example" {
  name        = "Test_Project_1"
  description = "My description"
}

resource "catalystcenter_template" "base_template" {
  project_id  = catalystcenter_project.example.id
  name        = "C9200-C9300_Template"
  description = "Jinja Template"
  device_types = [
    {
      product_family = "Switches and Hubs"
      product_series = "Cisco Catalyst 9300 Series Switches"
      product_type   = "Cisco Catalyst 9300 Switch"
    }
  ]
  language         = "JINJA"
  software_type    = "IOS-XE"
  software_variant = "XE"
  software_version = "16.12.1a"
  template_content = "hostname Test"
  composite        = false
}

resource "catalystcenter_network_profile" "network_profile" {
  name = "Network Profile for C9200-9300 switches"
  type = "switching"
  templates = [
    {
      type = "day0.templates"
      attributes = [
        {
          template_id = catalystcenter_template.base_template.id
        }
      ]
    }
  ]
}

and I can see template being attached to network profile:

Screenshot 2024-12-02 at 22 00 42

If terraform config was applied successfully without any errors, are you sure you cannot see template attached to network profile under Network Profiles -> Edit ?

sudhanshujoshi23 commented 1 day ago

The DNAC version I am using is Version 2.3.5.3-70194 The terraform provider version I am using is 0.1.15 And yes I am sure that I can't see the network profile being attached to the template. I tried the exact same code in the example you provided, but the network profile wasn't attached to the template after successful apply.

image image

kuba-mazurkiewicz commented 18 hours ago

Can you try upgrading to 2.3.7.X , provider was tested against 2.3.7 version of CC.

sudhanshujoshi23 commented 12 hours ago

This will need some time... Also, can you confirm if the templates needs to be committed before they can be attached to any network profile? If that's the case, can you point me to the documentation which I can use for committing the template?

Thanks!

kuba-mazurkiewicz commented 12 hours ago

For commiting template you need to use resource: https://registry.terraform.io/providers/CiscoDevNet/catalystcenter/latest/docs/resources/template_version

and code can look like this:

resource "catalystcenter_template" "base_template" {
  project_id  = catalystcenter_project.example.id
  name        = "C9200-C9300_Template"
  description = "Jinja Template"
  device_types = [
    {
      product_family = "Switches and Hubs"
      product_series = "Cisco Catalyst 9300 Series Switches"
      product_type   = "Cisco Catalyst 9300 Switch"
    }
  ]
  language         = "JINJA"
  software_type    = "IOS-XE"
  software_variant = "XE"
  software_version = "16.12.1a"
  template_content = "hostname Test"
  composite        = false
}

resource "catalystcenter_template_version" "example" {
  template_id = catalystcenter_template.base_template.id
  comments    = "New Version"
}
sudhanshujoshi23 commented 7 hours ago

Adding the version resource didn't help either. There were no errors during the terraform apply. image

Also, if I just go and attach the network profile manually to this newly created template using the catalyst center web portal, it works. So I am not sure what's wrong with the terraform code.

kuba-mazurkiewicz commented 7 hours ago

I don't think there is a problem with terraform code. This resource is using internal API endpoint: /api/v1/siteprofile, which might not work on your DNAC version. As i mentioned provider is tested against 2.3.7 DNAC version.

I would recommend to upgrade to 2.3.7.X and try again.