cisco-en-programmability / terraform-provider-dnacenter

https://registry.terraform.io/providers/cisco-en-programmability/dnacenter/latest/docs
MIT License
14 stars 12 forks source link

`dnacenter_network_create` generates incorrect payload #243

Closed mschedrin closed 10 months ago

mschedrin commented 10 months ago

Prerequisites

Describe the bug dnacenter_network_create generates wrong, almost empty payload upon resource creation and update. State is also not being refreshed and changes made outside terraform are not detected. It looks like issue #99 has found it's way back in the current code.

Terraform apply output:

Terraform will perform the following actions:

  # dnacenter_network_create.this["Global"] will be created
  + resource "dnacenter_network_create" "this" {
      + id           = (known after apply)
      + item         = (known after apply)
      + last_updated = (known after apply)

      + parameters {
          + persistbapioutput = "false"
          + site_id           = "457bfa63-693b-4979-a7fa-2457422cb1a2"

          + settings {
              + dhcp_server = (known after apply)
              + ntp_server  = (sensitive value)
              + timezone    = (sensitive value)

              + client_and_endpoint_aaa {
                  + ip_address    = (sensitive value)
                  + network       = (sensitive value)
                  + protocol      = (sensitive value)
                  + servers       = (sensitive value)
                  + shared_secret = (sensitive value)
                }

              + dns_server {
                  + domain_name          = (sensitive value)
                  + primary_ip_address   = (sensitive value)
                  + secondary_ip_address = (sensitive value)
                }

              + message_of_theday {
                  + banner_message         = (sensitive value)
                  + retain_existing_banner = (sensitive value)
                }

              + network_aaa {
                  + ip_address    = (sensitive value)
                  + network       = (sensitive value)
                  + protocol      = (sensitive value)
                  + servers       = (sensitive value)
                  + shared_secret = (sensitive value)
                }

              + snmp_server {
                  + configure_dnac_ip = (sensitive value)
                  + ip_addresses      = (sensitive value)
                }

              + syslog_server {
                  + configure_dnac_ip = (sensitive value)
                  + ip_addresses      = (sensitive value)
                }
            }
        }
    }

Plan: 1 to add, 0 to change, 0 to destroy.
dnacenter_network_create.this["Global"]: Creating...
dnacenter_network_create.this["Global"]: Creation complete after 5s [id=1701098519]

Extract from debug log showing POST BODY that provider crafted and sent to DNAC:

==============================================================================
~~~ REQUEST ~~~
POST  /dna/intent/api/v1/network/457bfa63-693b-4979-a7fa-2457422cb1a2  HTTP/1.1
HOST   : 100.68.0.71
HEADERS:
    Accept: application/json
    Content-Type: application/json
    User-Agent: go-resty/2.7.0 (https://github.com/go-resty/resty)
    X-Auth-Token: <redacted>
    __persistbapioutput: false
BODY   :
{
   "settings": {}
}
------------------------------------------------------------------------------

The same payload is generated when the resource is planned to be updated in-place.

API reply when reading network settings from DNAC, for reference:

GET /dna/intent/api/v1/network
{
    "response": [
        {
            "instanceType": "banner",
            "instanceUuid": "b97c778e-d23f-4cad-9981-a198666970b0",
            "namespace": "global",
            "type": "banner.setting",
            "key": "device.banner",
            "version": 1,
            "value": [
                {
                    "bannerMessage": "Welcome to the SP network, take care of lives",
                    "retainExistingBanner": false
                }
            ],
            "groupUuid": "457bfa63-693b-4979-a7fa-2457422cb1a2",
            "inheritedGroupUuid": "-1",
            "inheritedGroupName": "Global"
        },
        {
            "instanceType": "banner",
            "instanceUuid": "0a3d745a-148c-4303-aadc-709ab009e528",
            "namespace": "global",
            "type": "banner.setting",
            "key": "device.banner",
            "version": 43,
            "value": [
                {
                    "bannerMessage": "Hello from devhf",
                    "retainExistingBanner": false
                }
            ],
            "groupUuid": "457bfa63-693b-4979-a7fa-2457422cb1a2",
            "inheritedGroupUuid": "-1",
            "inheritedGroupName": "Global"
        },
        {
            "instanceType": "timezone",
            "instanceUuid": "4fdeccfa-f8b8-4eb3-9348-62c0ff83ab69",
            "namespace": "global",
            "type": "timezone.setting",
            "key": "timezone.site",
            "version": 8,
            "value": [
                "Europe/Oslo"
            ],
            "groupUuid": "457bfa63-693b-4979-a7fa-2457422cb1a2",
            "inheritedGroupUuid": "-1",
            "inheritedGroupName": "Global"
        },
        {
            "instanceType": "syslog",
            "instanceUuid": "1f23cc43-a5ef-4b32-9800-a3d2aa3d67d1",
            "namespace": "global",
            "type": "syslog.setting",
            "key": "syslog.server",
            "version": 20,
            "value": [
                {
                    "ipAddresses": [
                        "100.68.0.71"
                    ],
                    "configureDnacIP": true
                }
            ],
            "groupUuid": "457bfa63-693b-4979-a7fa-2457422cb1a2",
            "inheritedGroupUuid": "-1",
            "inheritedGroupName": "Global"
        },
        {
            "instanceType": "netflow",
            "instanceUuid": "84b28a50-3b1c-450e-9326-122c8a6d8fee",
            "namespace": "global",
            "type": "netflow.setting",
            "key": "netflow.collector",
            "version": 14,
            "value": [
                {
                    "ipAddress": "",
                    "port": null,
                    "configureDnacIP": true
                }
            ],
            "groupUuid": "457bfa63-693b-4979-a7fa-2457422cb1a2",
            "inheritedGroupUuid": "-1",
            "inheritedGroupName": "Global"
        },
        {
            "instanceType": "wiredclient",
            "instanceUuid": "0fa7ce7d-dc32-459c-a78e-72e6a7f40f9e",
            "namespace": "global",
            "type": "wiredclient.setting",
            "key": "wiredclient.ipdt",
            "version": 14,
            "value": [
                {
                    "ipdtEnabled": true
                }
            ],
            "groupUuid": "457bfa63-693b-4979-a7fa-2457422cb1a2",
            "inheritedGroupUuid": "-1",
            "inheritedGroupName": "Global"
        },
        {
            "instanceType": "pan",
            "instanceUuid": "1d11830e-d9f8-40fe-8660-6817e3668ddd",
            "namespace": "global",
            "type": "pan.setting",
            "key": "aaa.server.pan.network",
            "version": 42,
            "value": [
                "100.68.0.137"
            ],
            "groupUuid": "457bfa63-693b-4979-a7fa-2457422cb1a2",
            "inheritedGroupUuid": "-1",
            "inheritedGroupName": "Global"
        },
        {
            "instanceType": "aaa",
            "instanceUuid": "2e1b1613-7b83-46f6-9ce3-facf72348bd3",
            "namespace": "global",
            "type": "aaa.setting",
            "key": "aaa.endpoint.server.1",
            "version": 42,
            "value": [
                {
                    "ipAddress": "100.68.0.137",
                    "sharedSecret": "",
                    "protocol": "RADIUS",
                    "encryptionScheme": "",
                    "encryptionKey": "",
                    "messageKey": ""
                }
            ],
            "groupUuid": "457bfa63-693b-4979-a7fa-2457422cb1a2",
            "inheritedGroupUuid": "-1",
            "inheritedGroupName": "Global"
        },
        {
            "instanceType": "securityandtrust",
            "instanceUuid": "2e2b3eb3-8144-4a3c-973f-fec687c35739",
            "namespace": "global",
            "type": "securityandtrust.setting",
            "key": "securityandtrust.revocationcheck",
            "version": 0,
            "value": [
                {
                    "revocationCheckEnabled": true
                }
            ],
            "groupUuid": "457bfa63-693b-4979-a7fa-2457422cb1a2",
            "inheritedGroupUuid": "-1",
            "inheritedGroupName": "Global"
        },
        {
            "instanceType": "ip",
            "instanceUuid": "23fdda43-4b16-4e20-a5c8-32d88e1fd72e",
            "namespace": "global",
            "type": "ip.address",
            "key": "dhcp.server",
            "version": 42,
            "value": [],
            "groupUuid": "457bfa63-693b-4979-a7fa-2457422cb1a2",
            "inheritedGroupUuid": "-1",
            "inheritedGroupName": "Global"
        },
        {
            "instanceType": "aaa",
            "instanceUuid": "3e47078b-b6da-41f0-a43d-16b1326b3bb2",
            "namespace": "global",
            "type": "aaa.setting",
            "key": "aaa.endpoint.server.2",
            "version": 42,
            "value": [
                {
                    "ipAddress": "",
                    "sharedSecret": "",
                    "protocol": "",
                    "encryptionScheme": "",
                    "encryptionKey": "",
                    "messageKey": ""
                }
            ],
            "groupUuid": "457bfa63-693b-4979-a7fa-2457422cb1a2",
            "inheritedGroupUuid": "-1",
            "inheritedGroupName": "Global"
        },
        {
            "instanceType": "interface",
            "instanceUuid": "e47d5ec1-c6eb-405b-940e-ebe5ab413c5e",
            "namespace": "global",
            "type": "interface.setting",
            "key": "interface.info",
            "version": 3,
            "value": [
                {
                    "interfaceName": "management",
                    "vlanId": 0
                }
            ],
            "groupUuid": "457bfa63-693b-4979-a7fa-2457422cb1a2",
            "inheritedGroupUuid": "-1",
            "inheritedGroupName": "Global"
        },
        {
            "instanceType": "telemetry",
            "instanceUuid": "f61297fc-4292-4582-accd-f7d5b71a1fa1",
            "namespace": "global",
            "type": "telemetry.setting",
            "key": "wireless.telemetry",
            "version": 0,
            "value": [
                {
                    "telemetryEnabled": true
                }
            ],
            "groupUuid": "457bfa63-693b-4979-a7fa-2457422cb1a2",
            "inheritedGroupUuid": "-1",
            "inheritedGroupName": "Global"
        },
        {
            "instanceType": "aaa",
            "instanceUuid": "e9f6be67-7f52-484f-9637-0e2a335099f8",
            "namespace": "global",
            "type": "aaa.setting",
            "key": "aaa.network.server.1",
            "version": 42,
            "value": [
                {
                    "ipAddress": "100.68.0.137",
                    "sharedSecret": "",
                    "protocol": "TACACS",
                    "encryptionScheme": "",
                    "encryptionKey": "",
                    "messageKey": ""
                }
            ],
            "groupUuid": "457bfa63-693b-4979-a7fa-2457422cb1a2",
            "inheritedGroupUuid": "-1",
            "inheritedGroupName": "Global"
        },
        {
            "instanceType": "ip",
            "instanceUuid": "ef1387b2-fdf7-4535-8ae2-28c5553eddec",
            "namespace": "global",
            "type": "ip.address",
            "key": "ntp.server",
            "version": 1,
            "value": [
                "100.68.0.141",
                "10.179.27.1",
                "10.179.27.2",
                "10.179.27.3",
                "10.179.27.4"
            ],
            "groupUuid": "457bfa63-693b-4979-a7fa-2457422cb1a2",
            "inheritedGroupUuid": "-1",
            "inheritedGroupName": "Global"
        },
        {
            "instanceType": "ip",
            "instanceUuid": "a8cce0b7-9d31-4262-bd7c-629a4102bb7c",
            "namespace": "global",
            "type": "ip.address",
            "key": "ntp.server",
            "version": 40,
            "value": [
                "10.179.27.1",
                "10.179.27.2",
                "10.179.27.3",
                "10.179.27.4"
            ],
            "groupUuid": "457bfa63-693b-4979-a7fa-2457422cb1a2",
            "inheritedGroupUuid": "-1",
            "inheritedGroupName": "Global"
        },
        {
            "instanceType": "snmp",
            "instanceUuid": "6e73999a-99d9-4c2c-9ba9-1c7e5a76776f",
            "namespace": "global",
            "type": "snmp.setting",
            "key": "snmp.trap.receiver",
            "version": 19,
            "value": [
                {
                    "ipAddresses": [
                        "100.68.0.71"
                    ],
                    "configureDnacIP": true
                }
            ],
            "groupUuid": "457bfa63-693b-4979-a7fa-2457422cb1a2",
            "inheritedGroupUuid": "-1",
            "inheritedGroupName": "Global"
        },
        {
            "instanceType": "dns",
            "instanceUuid": "3c038371-c8bb-4741-b17e-27f8276eb6c7",
            "namespace": "global",
            "type": "dns.setting",
            "key": "dns.server",
            "version": 2,
            "value": [
                {
                    "domainName": "devhf.local",
                    "primaryIpAddress": "100.68.0.141",
                    "secondaryIpAddress": "100.68.0.135"
                }
            ],
            "groupUuid": "457bfa63-693b-4979-a7fa-2457422cb1a2",
            "inheritedGroupUuid": "-1",
            "inheritedGroupName": "Global"
        },
        {
            "instanceType": "dns",
            "instanceUuid": "95362e2d-4ff4-4380-ad1d-2dd8cb46c82c",
            "namespace": "global",
            "type": "dns.setting",
            "key": "dns.server",
            "version": 50,
            "value": [
                {
                    "domainName": "devhf.local",
                    "primaryIpAddress": "100.68.0.141",
                    "secondaryIpAddress": "100.68.0.135"
                }
            ],
            "groupUuid": "457bfa63-693b-4979-a7fa-2457422cb1a2",
            "inheritedGroupUuid": "-1",
            "inheritedGroupName": "Global"
        },
        {
            "instanceType": "aaa",
            "instanceUuid": "22287ccd-08df-4735-a99e-949f96852202",
            "namespace": "global",
            "type": "aaa.setting",
            "key": "aaa.network.server.2",
            "version": 42,
            "value": [
                {
                    "ipAddress": "",
                    "sharedSecret": "",
                    "protocol": "",
                    "encryptionScheme": "",
                    "encryptionKey": "",
                    "messageKey": ""
                }
            ],
            "groupUuid": "457bfa63-693b-4979-a7fa-2457422cb1a2",
            "inheritedGroupUuid": "-1",
            "inheritedGroupName": "Global"
        },
        {
            "instanceType": "eapfastauthority",
            "instanceUuid": "1a16bb3e-08b8-4d9a-ba39-6dc18f6505a7",
            "namespace": "global",
            "type": "eapfast.authority",
            "key": "eapfast.authority.seeds",
            "version": 1,
            "value": [
                {
                    "authorityId": "CB29F71F5BCC3B16A491C714334B8023",
                    "seedKey": "<redacted>",
                    "seedId": "19"
                }
            ],
            "groupUuid": "457bfa63-693b-4979-a7fa-2457422cb1a2",
            "inheritedGroupUuid": "-1",
            "inheritedGroupName": "Global"
        },
        {
            "instanceType": "pan",
            "instanceUuid": "849f4891-5887-48e3-860e-53328039fe3b",
            "namespace": "global",
            "type": "pan.setting",
            "key": "aaa.server.pan.endpoint",
            "version": 42,
            "value": [
                "100.68.0.137"
            ],
            "groupUuid": "457bfa63-693b-4979-a7fa-2457422cb1a2",
            "inheritedGroupUuid": "-1",
            "inheritedGroupName": "Global"
        },
        {
            "instanceType": "eta_collector",
            "instanceUuid": "360ed503-9e6e-4311-a148-a6b1ca17791f",
            "namespace": "global",
            "type": "eta.setting",
            "key": "eta.collector",
            "version": 8,
            "value": [],
            "groupUuid": "457bfa63-693b-4979-a7fa-2457422cb1a2",
            "inheritedGroupUuid": "-1",
            "inheritedGroupName": "Global"
        }
    ],
    "version": "1.0"
}

Expected behavior Correct body should be generated.

Screenshots Please provide an screenshot of the successful API call with cuRL, Postman, etc.

Environment (please complete the following information):

mschedrin commented 10 months ago

Thanks for fixing this really quick @fmunozmiranda. BODY looks correct now and create operation works good. When it comes to update operation body looks correct too, however the resource still uses POST method which does not work well and for updating it should be used PUT method.

I have also tested refresh/read operation for some selected parameters and none of them is read: ntp_server, banner_message, dns_server. If you need example BODY from DNAC when sending GET request, you can find it in my first message in this issue.

fmunozmiranda commented 10 months ago

Network Create and Network Update

Actually we have POST and PUT separated because of response is so different to request. https://registry.terraform.io/providers/cisco-en-programmability/dnacenter/latest/docs/resources/network_create https://registry.terraform.io/providers/cisco-en-programmability/dnacenter/latest/docs/resources/network_update

Network V2

If you want to use it as a complete resource, you can use: https://registry.terraform.io/providers/cisco-en-programmability/dnacenter/latest/docs/resources/network_v2

Documentation Network v2 and GET Network

In this case dnacenter_network_v2, detecting external changes has not been contemplated either, due to the documentation, it was not clear how to achieve this. If there was more detail about where each attribute of the request comes from in the response, something could be done. https://developer.cisco.com/docs/dna-center/#!create-network-v2 https://developer.cisco.com/docs/dna-center/#!get-network

mschedrin commented 10 months ago

I didn't know that dnacenter_network_v2 was implemented. v1 is very buggy anyway so I have tried dnacenter_network_v2 and created issue #246