From 71be5844f301fc7c38a9738ca2fa71736a2aaae1 Mon Sep 17 00:00:00 2001 From: Rafael Muller Date: Thu, 27 Feb 2025 06:53:09 -0500 Subject: [PATCH] Add isis af and overload resources and data sources (#304) --- CHANGELOG.md | 2 + docs/data-sources/isis_address_family.md | 45 +++ docs/data-sources/isis_overload.md | 40 +++ docs/guides/changelog.md | 2 + docs/guides/supported_objects.md | 2 + docs/resources/isis_address_family.md | 75 +++++ docs/resources/isis_overload.md | 63 ++++ docs/resources/isis_vrf.md | 7 + .../nxos_isis_address_family/data-source.tf | 5 + .../nxos_isis_overload/data-source.tf | 4 + .../nxos_isis_address_family/import.sh | 1 + .../nxos_isis_address_family/resource.tf | 9 + .../resources/nxos_isis_overload/import.sh | 1 + .../resources/nxos_isis_overload/resource.tf | 5 + gen/definitions/isis_address_family.yaml | 82 +++++ gen/definitions/isis_overload.yaml | 57 ++++ gen/definitions/isis_vrf.yaml | 3 + .../data_source_nxos_isis_address_family.go | 138 +++++++++ ...ta_source_nxos_isis_address_family_test.go | 103 +++++++ .../data_source_nxos_isis_overload.go | 122 ++++++++ .../data_source_nxos_isis_overload_test.go | 93 ++++++ .../model_nxos_isis_address_family.go | 132 ++++++++ internal/provider/model_nxos_isis_overload.go | 86 ++++++ internal/provider/provider.go | 4 + .../resource_nxos_isis_address_family.go | 291 ++++++++++++++++++ .../resource_nxos_isis_address_family_test.go | 114 +++++++ .../provider/resource_nxos_isis_overload.go | 266 ++++++++++++++++ .../resource_nxos_isis_overload_test.go | 105 +++++++ internal/provider/resource_nxos_isis_vrf.go | 2 +- templates/guides/changelog.md.tmpl | 2 + templates/guides/supported_objects.md.tmpl | 2 + 31 files changed, 1862 insertions(+), 1 deletion(-) create mode 100644 docs/data-sources/isis_address_family.md create mode 100644 docs/data-sources/isis_overload.md create mode 100644 docs/resources/isis_address_family.md create mode 100644 docs/resources/isis_overload.md create mode 100644 examples/data-sources/nxos_isis_address_family/data-source.tf create mode 100644 examples/data-sources/nxos_isis_overload/data-source.tf create mode 100644 examples/resources/nxos_isis_address_family/import.sh create mode 100644 examples/resources/nxos_isis_address_family/resource.tf create mode 100644 examples/resources/nxos_isis_overload/import.sh create mode 100644 examples/resources/nxos_isis_overload/resource.tf create mode 100644 gen/definitions/isis_address_family.yaml create mode 100644 gen/definitions/isis_overload.yaml create mode 100644 internal/provider/data_source_nxos_isis_address_family.go create mode 100644 internal/provider/data_source_nxos_isis_address_family_test.go create mode 100644 internal/provider/data_source_nxos_isis_overload.go create mode 100644 internal/provider/data_source_nxos_isis_overload_test.go create mode 100644 internal/provider/model_nxos_isis_address_family.go create mode 100644 internal/provider/model_nxos_isis_overload.go create mode 100644 internal/provider/resource_nxos_isis_address_family.go create mode 100644 internal/provider/resource_nxos_isis_address_family_test.go create mode 100644 internal/provider/resource_nxos_isis_overload.go create mode 100644 internal/provider/resource_nxos_isis_overload_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index ede9eca4..a756efd1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ - Check if a device referenced in a resource or data source exists in the provider configuration - When importing a resource, also populate attributes referencing parent resources +- Add `nxos_isis_address_family` resource and data source +- Add `nxos_isis_overload` resource and data source ## 0.5.7 diff --git a/docs/data-sources/isis_address_family.md b/docs/data-sources/isis_address_family.md new file mode 100644 index 00000000..b2f871fa --- /dev/null +++ b/docs/data-sources/isis_address_family.md @@ -0,0 +1,45 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "nxos_isis_address_family Data Source - terraform-provider-nxos" +subcategory: "ISIS" +description: |- + This data source can read the IS-IS Address Family configuration. + API Documentation: isisDomAf https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Routing%20and%20Forwarding/isis:DomAf/ +--- + +# nxos_isis_address_family (Data Source) + +This data source can read the IS-IS Address Family configuration. + +- API Documentation: [isisDomAf](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Routing%20and%20Forwarding/isis:DomAf/) + +## Example Usage + +```terraform +data "nxos_isis_address_family" "example" { + instance_name = "ISIS1" + vrf = "default" + address_family = "v4" +} +``` + + +## Schema + +### Required + +- `address_family` (String) Address family type. +- `instance_name` (String) IS-IS instance name. +- `vrf` (String) VRF name. + +### Optional + +- `device` (String) A device name from the provider configuration. + +### Read-Only + +- `enable_bfd` (Boolean) Enabling BFD on all ISIS domain interfaces. +- `id` (String) The distinguished name of the object. +- `prefix_advertise_passive_l1` (Boolean) Prefix advertise passive only for level-1 +- `prefix_advertise_passive_l2` (Boolean) Prefix advertise passive only level-2 +- `segment_routing_mpls` (Boolean) Segment routing for MPLS diff --git a/docs/data-sources/isis_overload.md b/docs/data-sources/isis_overload.md new file mode 100644 index 00000000..dae5256a --- /dev/null +++ b/docs/data-sources/isis_overload.md @@ -0,0 +1,40 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "nxos_isis_overload Data Source - terraform-provider-nxos" +subcategory: "ISIS" +description: |- + This data source can read the IS-IS overload configuration. + API Documentation: isisOverload https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Routing%20and%20Forwarding/isis:Overload/ +--- + +# nxos_isis_overload (Data Source) + +This data source can read the IS-IS overload configuration. + +- API Documentation: [isisOverload](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Routing%20and%20Forwarding/isis:Overload/) + +## Example Usage + +```terraform +data "nxos_isis_overload" "example" { + instance_name = "ISIS1" + vrf = "default" +} +``` + + +## Schema + +### Required + +- `instance_name` (String) IS-IS instance name. +- `vrf` (String) VRF name. + +### Optional + +- `device` (String) A device name from the provider configuration. + +### Read-Only + +- `id` (String) The distinguished name of the object. +- `startup_time` (Number) The overload startup time. The overload state begins when the switch boots up and ends at the time specified as the overload startup time. diff --git a/docs/guides/changelog.md b/docs/guides/changelog.md index bb9aad3d..a9098943 100644 --- a/docs/guides/changelog.md +++ b/docs/guides/changelog.md @@ -11,6 +11,8 @@ description: |- - Check if a device referenced in a resource or data source exists in the provider configuration - When importing a resource, also populate attributes referencing parent resources +- Add `nxos_isis_address_family` resource and data source +- Add `nxos_isis_overload` resource and data source ## 0.5.7 diff --git a/docs/guides/supported_objects.md b/docs/guides/supported_objects.md index 90227b66..cd770074 100644 --- a/docs/guides/supported_objects.md +++ b/docs/guides/supported_objects.md @@ -87,8 +87,10 @@ For the following DME objects a corresponding Terraform resource and data source | [ipv4Route](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Layer%203/ipv4:Route/) | [nxos_ipv4_static_route](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/ipv4_static_route) | [nxos_ipv4_static_route](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/data-sources/ipv4_static_route) | | [ipv4Dom](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Layer%203/ipv4:Dom/) | [nxos_ipv4_vrf](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/ipv4_vrf) | [nxos_ipv4_vrf](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/data-sources/ipv4_vrf) | | [isisEntity](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Routing%20and%20Forwarding/isis:Entity/) | [nxos_isis](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/isis) | [nxos_isis](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/data-sources/isis) | +| [isisDomAf](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Routing%20and%20Forwarding/isis:DomAf/) | [nxos_isis_address_family](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/isis_address_family) | [nxos_isis_address_family](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/data-sources/isis_address_family) | | [isisInst](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Routing%20and%20Forwarding/isis:Inst/) | [nxos_isis_instance](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/isis_instance) | [nxos_isis_instance](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/data-sources/isis_instance) | | [isisInternalIf](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Routing%20and%20Forwarding/isis:InternalIf/) | [nxos_isis_interface](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/isis_interface) | [nxos_isis_interface](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/data-sources/isis_interface) | +| [isisOverload](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Routing%20and%20Forwarding/isis:Overload/) | [nxos_isis_overload](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/isis_overload) | [nxos_isis_overload](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/data-sources/isis_overload) | | [isisDom](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Routing%20and%20Forwarding/isis:Dom/) | [nxos_isis_vrf](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/isis_vrf) | [nxos_isis_vrf](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/data-sources/isis_vrf) | | [l3LbRtdIf](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Layer%203/l3:LbRtdIf/) | [nxos_loopback_interface](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/loopback_interface) | [nxos_loopback_interface](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/data-sources/loopback_interface) | | [nwRtVrfMbr](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Routing%20and%20Forwarding/nw:RtVrfMbr/) | [nxos_loopback_interface_vrf](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/loopback_interface_vrf) | [nxos_loopback_interface_vrf](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/data-sources/loopback_interface_vrf) | diff --git a/docs/resources/isis_address_family.md b/docs/resources/isis_address_family.md new file mode 100644 index 00000000..2d57bec0 --- /dev/null +++ b/docs/resources/isis_address_family.md @@ -0,0 +1,75 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "nxos_isis_address_family Resource - terraform-provider-nxos" +subcategory: "ISIS" +description: |- + This resource can manage the IS-IS Address Family configuration. + API Documentation: isisDomAf https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Routing%20and%20Forwarding/isis:DomAf/ + Parent resources + nxos_isis_vrf https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/isis_vrf + Referenced resources + nxos_vrf https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/vrf +--- + +# nxos_isis_address_family (Resource) + +This resource can manage the IS-IS Address Family configuration. + +- API Documentation: [isisDomAf](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Routing%20and%20Forwarding/isis:DomAf/) + +### Parent resources + +- [nxos_isis_vrf](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/isis_vrf) + +### Referenced resources + +- [nxos_vrf](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/vrf) + +## Example Usage + +```terraform +resource "nxos_isis_address_family" "example" { + instance_name = "ISIS1" + vrf = "default" + address_family = "v4" + segment_routing_mpls = true + enable_bfd = false + prefix_advertise_passive_l1 = true + prefix_advertise_passive_l2 = true +} +``` + + +## Schema + +### Required + +- `address_family` (String) Address family type. + - Choices: `v4`, `v6` + - Default value: `v4` +- `instance_name` (String) IS-IS instance name. +- `vrf` (String) VRF name. + +### Optional + +- `device` (String) A device name from the provider configuration. +- `enable_bfd` (Boolean) Enabling BFD on all ISIS domain interfaces. + - Default value: `false` +- `prefix_advertise_passive_l1` (Boolean) Prefix advertise passive only for level-1 + - Default value: `false` +- `prefix_advertise_passive_l2` (Boolean) Prefix advertise passive only level-2 + - Default value: `false` +- `segment_routing_mpls` (Boolean) Segment routing for MPLS + - Default value: `false` + +### Read-Only + +- `id` (String) The distinguished name of the object. + +## Import + +Import is supported using the following syntax: + +```shell +terraform import nxos_isis_address_family.example "sys/isis/inst-[ISIS1]/dom-[default]/af-[v4]" +``` diff --git a/docs/resources/isis_overload.md b/docs/resources/isis_overload.md new file mode 100644 index 00000000..5c75ceba --- /dev/null +++ b/docs/resources/isis_overload.md @@ -0,0 +1,63 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "nxos_isis_overload Resource - terraform-provider-nxos" +subcategory: "ISIS" +description: |- + This resource can manage the IS-IS overload configuration. + API Documentation: isisOverload https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Routing%20and%20Forwarding/isis:Overload/ + Parent resources + nxos_isis_vrf https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/isis_vrf + Referenced resources + nxos_vrf https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/vrf +--- + +# nxos_isis_overload (Resource) + +This resource can manage the IS-IS overload configuration. + +- API Documentation: [isisOverload](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Routing%20and%20Forwarding/isis:Overload/) + +### Parent resources + +- [nxos_isis_vrf](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/isis_vrf) + +### Referenced resources + +- [nxos_vrf](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/vrf) + +## Example Usage + +```terraform +resource "nxos_isis_overload" "example" { + instance_name = "ISIS1" + vrf = "default" + startup_time = 60 +} +``` + + +## Schema + +### Required + +- `instance_name` (String) IS-IS instance name. +- `vrf` (String) VRF name. + +### Optional + +- `device` (String) A device name from the provider configuration. +- `startup_time` (Number) The overload startup time. The overload state begins when the switch boots up and ends at the time specified as the overload startup time. + - Range: `5`-`86400` + - Default value: `60` + +### Read-Only + +- `id` (String) The distinguished name of the object. + +## Import + +Import is supported using the following syntax: + +```shell +terraform import nxos_isis_overload.example "sys/isis/inst-[ISIS1]/dom-[default]/overload" +``` diff --git a/docs/resources/isis_vrf.md b/docs/resources/isis_vrf.md index a364a1a2..a435a04a 100644 --- a/docs/resources/isis_vrf.md +++ b/docs/resources/isis_vrf.md @@ -7,6 +7,8 @@ description: |- API Documentation: isisDom https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Routing%20and%20Forwarding/isis:Dom/ Parent resources nxos_isis_instance https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/isis_instance + Child resources + nxos_isis_address_family https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/isis_address_familynxos_isis_overload https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/isis_overload Referenced resources nxos_vrf https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/vrf --- @@ -21,6 +23,11 @@ This resource can manage the IS-IS VRF configuration. - [nxos_isis_instance](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/isis_instance) +### Child resources + +- [nxos_isis_address_family](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/isis_address_family) +- [nxos_isis_overload](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/isis_overload) + ### Referenced resources - [nxos_vrf](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/vrf) diff --git a/examples/data-sources/nxos_isis_address_family/data-source.tf b/examples/data-sources/nxos_isis_address_family/data-source.tf new file mode 100644 index 00000000..66bfe3e5 --- /dev/null +++ b/examples/data-sources/nxos_isis_address_family/data-source.tf @@ -0,0 +1,5 @@ +data "nxos_isis_address_family" "example" { + instance_name = "ISIS1" + vrf = "default" + address_family = "v4" +} diff --git a/examples/data-sources/nxos_isis_overload/data-source.tf b/examples/data-sources/nxos_isis_overload/data-source.tf new file mode 100644 index 00000000..72a318d9 --- /dev/null +++ b/examples/data-sources/nxos_isis_overload/data-source.tf @@ -0,0 +1,4 @@ +data "nxos_isis_overload" "example" { + instance_name = "ISIS1" + vrf = "default" +} diff --git a/examples/resources/nxos_isis_address_family/import.sh b/examples/resources/nxos_isis_address_family/import.sh new file mode 100644 index 00000000..17b35784 --- /dev/null +++ b/examples/resources/nxos_isis_address_family/import.sh @@ -0,0 +1 @@ +terraform import nxos_isis_address_family.example "sys/isis/inst-[ISIS1]/dom-[default]/af-[v4]" diff --git a/examples/resources/nxos_isis_address_family/resource.tf b/examples/resources/nxos_isis_address_family/resource.tf new file mode 100644 index 00000000..e900124d --- /dev/null +++ b/examples/resources/nxos_isis_address_family/resource.tf @@ -0,0 +1,9 @@ +resource "nxos_isis_address_family" "example" { + instance_name = "ISIS1" + vrf = "default" + address_family = "v4" + segment_routing_mpls = true + enable_bfd = false + prefix_advertise_passive_l1 = true + prefix_advertise_passive_l2 = true +} diff --git a/examples/resources/nxos_isis_overload/import.sh b/examples/resources/nxos_isis_overload/import.sh new file mode 100644 index 00000000..8057da7f --- /dev/null +++ b/examples/resources/nxos_isis_overload/import.sh @@ -0,0 +1 @@ +terraform import nxos_isis_overload.example "sys/isis/inst-[ISIS1]/dom-[default]/overload" diff --git a/examples/resources/nxos_isis_overload/resource.tf b/examples/resources/nxos_isis_overload/resource.tf new file mode 100644 index 00000000..b4e51cc3 --- /dev/null +++ b/examples/resources/nxos_isis_overload/resource.tf @@ -0,0 +1,5 @@ +resource "nxos_isis_overload" "example" { + instance_name = "ISIS1" + vrf = "default" + startup_time = 60 +} diff --git a/gen/definitions/isis_address_family.yaml b/gen/definitions/isis_address_family.yaml new file mode 100644 index 00000000..d37097f0 --- /dev/null +++ b/gen/definitions/isis_address_family.yaml @@ -0,0 +1,82 @@ +--- +name: ISIS Address Family +class_name: isisDomAf +dn: sys/isis/inst-[%s]/dom-[%s]/af-[%s] +ds_description: This data source can read the IS-IS Address Family configuration. +res_description: This resource can manage the IS-IS Address Family configuration. +doc_path: Routing%20and%20Forwarding/isis:DomAf/ +doc_category: ISIS +parents: + - ISIS VRF +references: + - VRF +attributes: + - nxos_name: inst + tf_name: instance_name + type: String + id: true + reference_only: true + description: 'IS-IS instance name.' + example: ISIS1 + - nxos_name: name + tf_name: vrf + type: String + id: true + description: 'VRF name.' + example: default + - nxos_name: type + tf_name: address_family + type: String + id: true + description: 'Address family type.' + enum_values: + - v4 + - v6 + default_value: v4 + example: v4 + - nxos_name: srMpls + tf_name: segment_routing_mpls + type: Bool + description: 'Segment routing for MPLS ' + default_value: false + example: true + - nxos_name: enableBfd + tf_name: enable_bfd + type: Bool + description: 'Enabling BFD on all ISIS domain interfaces.' + default_value: false + example: false + - nxos_name: advPassiveLvl1 + tf_name: prefix_advertise_passive_l1 + type: Bool + description: 'Prefix advertise passive only for level-1' + default_value: false + example: true + - nxos_name: advPassiveLvl2 + tf_name: prefix_advertise_passive_l2 + type: Bool + description: 'Prefix advertise passive only level-2' + default_value: false + example: true +test_prerequisites: + - dn: sys/fm/isis + class_name: fmIsis + no_delete: true + attributes: + - name: adminSt + value: enabled + - dn: sys/isis + class_name: isisEntity + dependencies: [0] + - dn: sys/isis/inst-[ISIS1] + class_name: isisInst + attributes: + - name: name + value: ISIS1 + dependencies: [1] + - dn: sys/isis/inst-[ISIS1]/dom-[default] + class_name: isisDom + attributes: + - name: name + value: default + dependencies: [2] diff --git a/gen/definitions/isis_overload.yaml b/gen/definitions/isis_overload.yaml new file mode 100644 index 00000000..d508420a --- /dev/null +++ b/gen/definitions/isis_overload.yaml @@ -0,0 +1,57 @@ +--- +name: ISIS Overload +class_name: isisOverload +dn: sys/isis/inst-[%s]/dom-[%s]/overload +ds_description: This data source can read the IS-IS overload configuration. +res_description: This resource can manage the IS-IS overload configuration. +doc_path: Routing%20and%20Forwarding/isis:Overload/ +doc_category: ISIS +parents: + - ISIS VRF +references: + - VRF +attributes: + - nxos_name: inst + tf_name: instance_name + type: String + id: true + reference_only: true + description: 'IS-IS instance name.' + example: ISIS1 + - nxos_name: name + tf_name: vrf + type: String + id: true + reference_only: true + description: 'VRF name.' + example: default + - nxos_name: startupTime + tf_name: startup_time + type: Int64 + min_int: 5 + max_int: 86400 + default_value: 60 + description: 'The overload startup time. The overload state begins when the switch boots up and ends at the time specified as the overload startup time.' + example: 60 +test_prerequisites: + - dn: sys/fm/isis + class_name: fmIsis + no_delete: true + attributes: + - name: adminSt + value: enabled + - dn: sys/isis + class_name: isisEntity + dependencies: [0] + - dn: sys/isis/inst-[ISIS1] + class_name: isisInst + attributes: + - name: name + value: ISIS1 + dependencies: [1] + - dn: sys/isis/inst-[ISIS1]/dom-[default] + class_name: isisDom + attributes: + - name: name + value: default + dependencies: [2] diff --git a/gen/definitions/isis_vrf.yaml b/gen/definitions/isis_vrf.yaml index 0ec9f365..e19347e3 100644 --- a/gen/definitions/isis_vrf.yaml +++ b/gen/definitions/isis_vrf.yaml @@ -8,6 +8,9 @@ doc_path: Routing%20and%20Forwarding/isis:Dom/ doc_category: ISIS parents: - ISIS Instance +children: + - ISIS Address Family + - ISIS Overload references: - VRF attributes: diff --git a/internal/provider/data_source_nxos_isis_address_family.go b/internal/provider/data_source_nxos_isis_address_family.go new file mode 100644 index 00000000..81eda087 --- /dev/null +++ b/internal/provider/data_source_nxos_isis_address_family.go @@ -0,0 +1,138 @@ +// Copyright © 2023 Cisco Systems, Inc. and its affiliates. +// All rights reserved. +// +// Licensed under the Mozilla Public License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://mozilla.org/MPL/2.0/ +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: MPL-2.0 + +// Code generated by "gen/generator.go"; DO NOT EDIT. + +package provider + +import ( + "context" + "fmt" + + "github.com/CiscoDevNet/terraform-provider-nxos/internal/provider/helpers" + "github.com/hashicorp/terraform-plugin-framework/datasource" + "github.com/hashicorp/terraform-plugin-framework/datasource/schema" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-plugin-log/tflog" + "github.com/netascode/go-nxos" +) + +// Ensure the implementation satisfies the expected interfaces. +var ( + _ datasource.DataSource = &ISISAddressFamilyDataSource{} + _ datasource.DataSourceWithConfigure = &ISISAddressFamilyDataSource{} +) + +func NewISISAddressFamilyDataSource() datasource.DataSource { + return &ISISAddressFamilyDataSource{} +} + +type ISISAddressFamilyDataSource struct { + clients map[string]*nxos.Client +} + +func (d *ISISAddressFamilyDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_isis_address_family" +} + +func (d *ISISAddressFamilyDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { + resp.Schema = schema.Schema{ + // This description is used by the documentation generator and the language server. + MarkdownDescription: helpers.NewResourceDescription("This data source can read the IS-IS Address Family configuration.", "isisDomAf", "Routing%20and%20Forwarding/isis:DomAf/").String, + + Attributes: map[string]schema.Attribute{ + "device": schema.StringAttribute{ + MarkdownDescription: "A device name from the provider configuration.", + Optional: true, + }, + "id": schema.StringAttribute{ + MarkdownDescription: "The distinguished name of the object.", + Computed: true, + }, + "instance_name": schema.StringAttribute{ + MarkdownDescription: "IS-IS instance name.", + Required: true, + }, + "vrf": schema.StringAttribute{ + MarkdownDescription: "VRF name.", + Required: true, + }, + "address_family": schema.StringAttribute{ + MarkdownDescription: "Address family type.", + Required: true, + }, + "segment_routing_mpls": schema.BoolAttribute{ + MarkdownDescription: "Segment routing for MPLS ", + Computed: true, + }, + "enable_bfd": schema.BoolAttribute{ + MarkdownDescription: "Enabling BFD on all ISIS domain interfaces.", + Computed: true, + }, + "prefix_advertise_passive_l1": schema.BoolAttribute{ + MarkdownDescription: "Prefix advertise passive only for level-1", + Computed: true, + }, + "prefix_advertise_passive_l2": schema.BoolAttribute{ + MarkdownDescription: "Prefix advertise passive only level-2", + Computed: true, + }, + }, + } +} + +func (d *ISISAddressFamilyDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, _ *datasource.ConfigureResponse) { + if req.ProviderData == nil { + return + } + + d.clients = req.ProviderData.(map[string]*nxos.Client) +} + +func (d *ISISAddressFamilyDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + var config ISISAddressFamily + + // Read config + diags := req.Config.Get(ctx, &config) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Read", config.getDn())) + + client, ok := d.clients[config.Device.ValueString()] + if !ok { + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to find device '%s' in provider configuration", config.Device.ValueString())) + return + } + + queries := []func(*nxos.Req){} + res, err := client.GetDn(config.getDn(), queries...) + if err != nil { + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve object, got error: %s", err)) + return + } + + config.fromBody(res, true) + config.Dn = types.StringValue(config.getDn()) + + tflog.Debug(ctx, fmt.Sprintf("%s: Read finished successfully", config.getDn())) + + diags = resp.State.Set(ctx, &config) + resp.Diagnostics.Append(diags...) +} diff --git a/internal/provider/data_source_nxos_isis_address_family_test.go b/internal/provider/data_source_nxos_isis_address_family_test.go new file mode 100644 index 00000000..82177050 --- /dev/null +++ b/internal/provider/data_source_nxos_isis_address_family_test.go @@ -0,0 +1,103 @@ +// Copyright © 2023 Cisco Systems, Inc. and its affiliates. +// All rights reserved. +// +// Licensed under the Mozilla Public License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://mozilla.org/MPL/2.0/ +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: MPL-2.0 + +// Code generated by "gen/generator.go"; DO NOT EDIT. + +package provider + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" +) + +func TestAccDataSourceNxosISISAddressFamily(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceNxosISISAddressFamilyPrerequisitesConfig + testAccDataSourceNxosISISAddressFamilyConfig, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("data.nxos_isis_address_family.test", "vrf", "default"), + resource.TestCheckResourceAttr("data.nxos_isis_address_family.test", "address_family", "v4"), + resource.TestCheckResourceAttr("data.nxos_isis_address_family.test", "segment_routing_mpls", "true"), + resource.TestCheckResourceAttr("data.nxos_isis_address_family.test", "enable_bfd", "false"), + resource.TestCheckResourceAttr("data.nxos_isis_address_family.test", "prefix_advertise_passive_l1", "true"), + resource.TestCheckResourceAttr("data.nxos_isis_address_family.test", "prefix_advertise_passive_l2", "true"), + ), + }, + }, + }) +} + +const testAccDataSourceNxosISISAddressFamilyPrerequisitesConfig = ` +resource "nxos_rest" "PreReq0" { + dn = "sys/fm/isis" + class_name = "fmIsis" + delete = false + content = { + adminSt = "enabled" + } +} + +resource "nxos_rest" "PreReq1" { + dn = "sys/isis" + class_name = "isisEntity" + depends_on = [nxos_rest.PreReq0, ] +} + +resource "nxos_rest" "PreReq2" { + dn = "sys/isis/inst-[ISIS1]" + class_name = "isisInst" + content = { + name = "ISIS1" + } + depends_on = [nxos_rest.PreReq1, ] +} + +resource "nxos_rest" "PreReq3" { + dn = "sys/isis/inst-[ISIS1]/dom-[default]" + class_name = "isisDom" + content = { + name = "default" + } + depends_on = [nxos_rest.PreReq2, ] +} + +` + +const testAccDataSourceNxosISISAddressFamilyConfig = ` + +resource "nxos_isis_address_family" "test" { + instance_name = "ISIS1" + vrf = "default" + address_family = "v4" + segment_routing_mpls = true + enable_bfd = false + prefix_advertise_passive_l1 = true + prefix_advertise_passive_l2 = true + depends_on = [nxos_rest.PreReq0, nxos_rest.PreReq1, nxos_rest.PreReq2, nxos_rest.PreReq3, ] +} + +data "nxos_isis_address_family" "test" { + instance_name = "ISIS1" + vrf = "default" + address_family = "v4" + depends_on = [nxos_isis_address_family.test] +} +` diff --git a/internal/provider/data_source_nxos_isis_overload.go b/internal/provider/data_source_nxos_isis_overload.go new file mode 100644 index 00000000..9566b938 --- /dev/null +++ b/internal/provider/data_source_nxos_isis_overload.go @@ -0,0 +1,122 @@ +// Copyright © 2023 Cisco Systems, Inc. and its affiliates. +// All rights reserved. +// +// Licensed under the Mozilla Public License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://mozilla.org/MPL/2.0/ +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: MPL-2.0 + +// Code generated by "gen/generator.go"; DO NOT EDIT. + +package provider + +import ( + "context" + "fmt" + + "github.com/CiscoDevNet/terraform-provider-nxos/internal/provider/helpers" + "github.com/hashicorp/terraform-plugin-framework/datasource" + "github.com/hashicorp/terraform-plugin-framework/datasource/schema" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-plugin-log/tflog" + "github.com/netascode/go-nxos" +) + +// Ensure the implementation satisfies the expected interfaces. +var ( + _ datasource.DataSource = &ISISOverloadDataSource{} + _ datasource.DataSourceWithConfigure = &ISISOverloadDataSource{} +) + +func NewISISOverloadDataSource() datasource.DataSource { + return &ISISOverloadDataSource{} +} + +type ISISOverloadDataSource struct { + clients map[string]*nxos.Client +} + +func (d *ISISOverloadDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_isis_overload" +} + +func (d *ISISOverloadDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { + resp.Schema = schema.Schema{ + // This description is used by the documentation generator and the language server. + MarkdownDescription: helpers.NewResourceDescription("This data source can read the IS-IS overload configuration.", "isisOverload", "Routing%20and%20Forwarding/isis:Overload/").String, + + Attributes: map[string]schema.Attribute{ + "device": schema.StringAttribute{ + MarkdownDescription: "A device name from the provider configuration.", + Optional: true, + }, + "id": schema.StringAttribute{ + MarkdownDescription: "The distinguished name of the object.", + Computed: true, + }, + "instance_name": schema.StringAttribute{ + MarkdownDescription: "IS-IS instance name.", + Required: true, + }, + "vrf": schema.StringAttribute{ + MarkdownDescription: "VRF name.", + Required: true, + }, + "startup_time": schema.Int64Attribute{ + MarkdownDescription: "The overload startup time. The overload state begins when the switch boots up and ends at the time specified as the overload startup time.", + Computed: true, + }, + }, + } +} + +func (d *ISISOverloadDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, _ *datasource.ConfigureResponse) { + if req.ProviderData == nil { + return + } + + d.clients = req.ProviderData.(map[string]*nxos.Client) +} + +func (d *ISISOverloadDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + var config ISISOverload + + // Read config + diags := req.Config.Get(ctx, &config) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Read", config.getDn())) + + client, ok := d.clients[config.Device.ValueString()] + if !ok { + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to find device '%s' in provider configuration", config.Device.ValueString())) + return + } + + queries := []func(*nxos.Req){} + res, err := client.GetDn(config.getDn(), queries...) + if err != nil { + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve object, got error: %s", err)) + return + } + + config.fromBody(res, true) + config.Dn = types.StringValue(config.getDn()) + + tflog.Debug(ctx, fmt.Sprintf("%s: Read finished successfully", config.getDn())) + + diags = resp.State.Set(ctx, &config) + resp.Diagnostics.Append(diags...) +} diff --git a/internal/provider/data_source_nxos_isis_overload_test.go b/internal/provider/data_source_nxos_isis_overload_test.go new file mode 100644 index 00000000..6d0ad12c --- /dev/null +++ b/internal/provider/data_source_nxos_isis_overload_test.go @@ -0,0 +1,93 @@ +// Copyright © 2023 Cisco Systems, Inc. and its affiliates. +// All rights reserved. +// +// Licensed under the Mozilla Public License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://mozilla.org/MPL/2.0/ +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: MPL-2.0 + +// Code generated by "gen/generator.go"; DO NOT EDIT. + +package provider + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" +) + +func TestAccDataSourceNxosISISOverload(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceNxosISISOverloadPrerequisitesConfig + testAccDataSourceNxosISISOverloadConfig, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("data.nxos_isis_overload.test", "startup_time", "60"), + ), + }, + }, + }) +} + +const testAccDataSourceNxosISISOverloadPrerequisitesConfig = ` +resource "nxos_rest" "PreReq0" { + dn = "sys/fm/isis" + class_name = "fmIsis" + delete = false + content = { + adminSt = "enabled" + } +} + +resource "nxos_rest" "PreReq1" { + dn = "sys/isis" + class_name = "isisEntity" + depends_on = [nxos_rest.PreReq0, ] +} + +resource "nxos_rest" "PreReq2" { + dn = "sys/isis/inst-[ISIS1]" + class_name = "isisInst" + content = { + name = "ISIS1" + } + depends_on = [nxos_rest.PreReq1, ] +} + +resource "nxos_rest" "PreReq3" { + dn = "sys/isis/inst-[ISIS1]/dom-[default]" + class_name = "isisDom" + content = { + name = "default" + } + depends_on = [nxos_rest.PreReq2, ] +} + +` + +const testAccDataSourceNxosISISOverloadConfig = ` + +resource "nxos_isis_overload" "test" { + instance_name = "ISIS1" + vrf = "default" + startup_time = 60 + depends_on = [nxos_rest.PreReq0, nxos_rest.PreReq1, nxos_rest.PreReq2, nxos_rest.PreReq3, ] +} + +data "nxos_isis_overload" "test" { + instance_name = "ISIS1" + vrf = "default" + depends_on = [nxos_isis_overload.test] +} +` diff --git a/internal/provider/model_nxos_isis_address_family.go b/internal/provider/model_nxos_isis_address_family.go new file mode 100644 index 00000000..5397a8e1 --- /dev/null +++ b/internal/provider/model_nxos_isis_address_family.go @@ -0,0 +1,132 @@ +// Copyright © 2023 Cisco Systems, Inc. and its affiliates. +// All rights reserved. +// +// Licensed under the Mozilla Public License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://mozilla.org/MPL/2.0/ +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: MPL-2.0 + +// Code generated by "gen/generator.go"; DO NOT EDIT. + +package provider + +import ( + "fmt" + "regexp" + "strconv" + "strings" + + "github.com/CiscoDevNet/terraform-provider-nxos/internal/provider/helpers" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/netascode/go-nxos" + "github.com/tidwall/gjson" + "github.com/tidwall/sjson" +) + +type ISISAddressFamily struct { + Device types.String `tfsdk:"device"` + Dn types.String `tfsdk:"id"` + InstanceName types.String `tfsdk:"instance_name"` + Vrf types.String `tfsdk:"vrf"` + AddressFamily types.String `tfsdk:"address_family"` + SegmentRoutingMpls types.Bool `tfsdk:"segment_routing_mpls"` + EnableBfd types.Bool `tfsdk:"enable_bfd"` + PrefixAdvertisePassiveL1 types.Bool `tfsdk:"prefix_advertise_passive_l1"` + PrefixAdvertisePassiveL2 types.Bool `tfsdk:"prefix_advertise_passive_l2"` +} + +func (data ISISAddressFamily) getDn() string { + return fmt.Sprintf("sys/isis/inst-[%s]/dom-[%s]/af-[%s]", data.InstanceName.ValueString(), data.Vrf.ValueString(), data.AddressFamily.ValueString()) +} + +func (data ISISAddressFamily) getClassName() string { + return "isisDomAf" +} + +func (data ISISAddressFamily) toBody(statusReplace bool) nxos.Body { + body := "" + body, _ = sjson.Set(body, data.getClassName()+".attributes", map[string]interface{}{}) + if statusReplace { + body, _ = sjson.Set(body, data.getClassName()+".attributes."+"status", "replaced") + } + if (!data.Vrf.IsUnknown() && !data.Vrf.IsNull()) || true { + body, _ = sjson.Set(body, data.getClassName()+".attributes."+"name", data.Vrf.ValueString()) + } + if (!data.AddressFamily.IsUnknown() && !data.AddressFamily.IsNull()) || true { + body, _ = sjson.Set(body, data.getClassName()+".attributes."+"type", data.AddressFamily.ValueString()) + } + if (!data.SegmentRoutingMpls.IsUnknown() && !data.SegmentRoutingMpls.IsNull()) || true { + body, _ = sjson.Set(body, data.getClassName()+".attributes."+"srMpls", strconv.FormatBool(data.SegmentRoutingMpls.ValueBool())) + } + if (!data.EnableBfd.IsUnknown() && !data.EnableBfd.IsNull()) || true { + body, _ = sjson.Set(body, data.getClassName()+".attributes."+"enableBfd", strconv.FormatBool(data.EnableBfd.ValueBool())) + } + if (!data.PrefixAdvertisePassiveL1.IsUnknown() && !data.PrefixAdvertisePassiveL1.IsNull()) || true { + body, _ = sjson.Set(body, data.getClassName()+".attributes."+"advPassiveLvl1", strconv.FormatBool(data.PrefixAdvertisePassiveL1.ValueBool())) + } + if (!data.PrefixAdvertisePassiveL2.IsUnknown() && !data.PrefixAdvertisePassiveL2.IsNull()) || true { + body, _ = sjson.Set(body, data.getClassName()+".attributes."+"advPassiveLvl2", strconv.FormatBool(data.PrefixAdvertisePassiveL2.ValueBool())) + } + + return nxos.Body{body} +} + +func (data *ISISAddressFamily) fromBody(res gjson.Result, all bool) { + if !data.Vrf.IsNull() || all { + data.Vrf = types.StringValue(res.Get(data.getClassName() + ".attributes.name").String()) + } else { + data.Vrf = types.StringNull() + } + if !data.AddressFamily.IsNull() || all { + data.AddressFamily = types.StringValue(res.Get(data.getClassName() + ".attributes.type").String()) + } else { + data.AddressFamily = types.StringNull() + } + if !data.SegmentRoutingMpls.IsNull() || all { + data.SegmentRoutingMpls = types.BoolValue(helpers.ParseNxosBoolean(res.Get(data.getClassName() + ".attributes.srMpls").String())) + } else { + data.SegmentRoutingMpls = types.BoolNull() + } + if !data.EnableBfd.IsNull() || all { + data.EnableBfd = types.BoolValue(helpers.ParseNxosBoolean(res.Get(data.getClassName() + ".attributes.enableBfd").String())) + } else { + data.EnableBfd = types.BoolNull() + } + if !data.PrefixAdvertisePassiveL1.IsNull() || all { + data.PrefixAdvertisePassiveL1 = types.BoolValue(helpers.ParseNxosBoolean(res.Get(data.getClassName() + ".attributes.advPassiveLvl1").String())) + } else { + data.PrefixAdvertisePassiveL1 = types.BoolNull() + } + if !data.PrefixAdvertisePassiveL2.IsNull() || all { + data.PrefixAdvertisePassiveL2 = types.BoolValue(helpers.ParseNxosBoolean(res.Get(data.getClassName() + ".attributes.advPassiveLvl2").String())) + } else { + data.PrefixAdvertisePassiveL2 = types.BoolNull() + } +} + +func (data ISISAddressFamily) toDeleteBody() nxos.Body { + body := "" + + return nxos.Body{body} +} + +func (data *ISISAddressFamily) getIdsFromDn() { + reString := strings.ReplaceAll("sys/isis/inst-[%s]/dom-[%s]/af-[%s]", "%s", "(.+)") + reString = strings.ReplaceAll(reString, "%v", "(.+)") + reString = strings.ReplaceAll(reString, "[", "\\[") + reString = strings.ReplaceAll(reString, "]", "\\]") + re := regexp.MustCompile(reString) + matches := re.FindStringSubmatch(data.Dn.ValueString()) + data.InstanceName = types.StringValue(matches[1]) + data.Vrf = types.StringValue(matches[2]) + data.AddressFamily = types.StringValue(matches[3]) +} diff --git a/internal/provider/model_nxos_isis_overload.go b/internal/provider/model_nxos_isis_overload.go new file mode 100644 index 00000000..a498097a --- /dev/null +++ b/internal/provider/model_nxos_isis_overload.go @@ -0,0 +1,86 @@ +// Copyright © 2023 Cisco Systems, Inc. and its affiliates. +// All rights reserved. +// +// Licensed under the Mozilla Public License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://mozilla.org/MPL/2.0/ +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: MPL-2.0 + +// Code generated by "gen/generator.go"; DO NOT EDIT. + +package provider + +import ( + "fmt" + "regexp" + "strconv" + "strings" + + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/netascode/go-nxos" + "github.com/tidwall/gjson" + "github.com/tidwall/sjson" +) + +type ISISOverload struct { + Device types.String `tfsdk:"device"` + Dn types.String `tfsdk:"id"` + InstanceName types.String `tfsdk:"instance_name"` + Vrf types.String `tfsdk:"vrf"` + StartupTime types.Int64 `tfsdk:"startup_time"` +} + +func (data ISISOverload) getDn() string { + return fmt.Sprintf("sys/isis/inst-[%s]/dom-[%s]/overload", data.InstanceName.ValueString(), data.Vrf.ValueString()) +} + +func (data ISISOverload) getClassName() string { + return "isisOverload" +} + +func (data ISISOverload) toBody(statusReplace bool) nxos.Body { + body := "" + body, _ = sjson.Set(body, data.getClassName()+".attributes", map[string]interface{}{}) + if statusReplace { + body, _ = sjson.Set(body, data.getClassName()+".attributes."+"status", "replaced") + } + if (!data.StartupTime.IsUnknown() && !data.StartupTime.IsNull()) || true { + body, _ = sjson.Set(body, data.getClassName()+".attributes."+"startupTime", strconv.FormatInt(data.StartupTime.ValueInt64(), 10)) + } + + return nxos.Body{body} +} + +func (data *ISISOverload) fromBody(res gjson.Result, all bool) { + if !data.StartupTime.IsNull() || all { + data.StartupTime = types.Int64Value(res.Get(data.getClassName() + ".attributes.startupTime").Int()) + } else { + data.StartupTime = types.Int64Null() + } +} + +func (data ISISOverload) toDeleteBody() nxos.Body { + body := "" + + return nxos.Body{body} +} + +func (data *ISISOverload) getIdsFromDn() { + reString := strings.ReplaceAll("sys/isis/inst-[%s]/dom-[%s]/overload", "%s", "(.+)") + reString = strings.ReplaceAll(reString, "%v", "(.+)") + reString = strings.ReplaceAll(reString, "[", "\\[") + reString = strings.ReplaceAll(reString, "]", "\\]") + re := regexp.MustCompile(reString) + matches := re.FindStringSubmatch(data.Dn.ValueString()) + data.InstanceName = types.StringValue(matches[1]) + data.Vrf = types.StringValue(matches[2]) +} diff --git a/internal/provider/provider.go b/internal/provider/provider.go index bc00ae82..7370d3f6 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -348,8 +348,10 @@ func (p *NxosProvider) Resources(ctx context.Context) []func() resource.Resource NewIPv4StaticRouteResource, NewIPv4VRFResource, NewISISResource, + NewISISAddressFamilyResource, NewISISInstanceResource, NewISISInterfaceResource, + NewISISOverloadResource, NewISISVRFResource, NewLoopbackInterfaceResource, NewLoopbackInterfaceVRFResource, @@ -492,8 +494,10 @@ func (p *NxosProvider) DataSources(ctx context.Context) []func() datasource.Data NewIPv4StaticRouteDataSource, NewIPv4VRFDataSource, NewISISDataSource, + NewISISAddressFamilyDataSource, NewISISInstanceDataSource, NewISISInterfaceDataSource, + NewISISOverloadDataSource, NewISISVRFDataSource, NewLoopbackInterfaceDataSource, NewLoopbackInterfaceVRFDataSource, diff --git a/internal/provider/resource_nxos_isis_address_family.go b/internal/provider/resource_nxos_isis_address_family.go new file mode 100644 index 00000000..744135e3 --- /dev/null +++ b/internal/provider/resource_nxos_isis_address_family.go @@ -0,0 +1,291 @@ +// Copyright © 2023 Cisco Systems, Inc. and its affiliates. +// All rights reserved. +// +// Licensed under the Mozilla Public License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://mozilla.org/MPL/2.0/ +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: MPL-2.0 + +// Code generated by "gen/generator.go"; DO NOT EDIT. + +package provider + +import ( + "context" + "fmt" + + "github.com/CiscoDevNet/terraform-provider-nxos/internal/provider/helpers" + "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" + "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-plugin-log/tflog" + "github.com/netascode/go-nxos" +) + +// Ensure provider defined types fully satisfy framework interfaces +var _ resource.Resource = &ISISAddressFamilyResource{} +var _ resource.ResourceWithImportState = &ISISAddressFamilyResource{} + +func NewISISAddressFamilyResource() resource.Resource { + return &ISISAddressFamilyResource{} +} + +type ISISAddressFamilyResource struct { + clients map[string]*nxos.Client +} + +func (r *ISISAddressFamilyResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_isis_address_family" +} + +func (r *ISISAddressFamilyResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { + resp.Schema = schema.Schema{ + // This description is used by the documentation generator and the language server. + MarkdownDescription: helpers.NewResourceDescription("This resource can manage the IS-IS Address Family configuration.", "isisDomAf", "Routing%20and%20Forwarding/isis:DomAf/").AddParents("isis_vrf").AddReferences("vrf").String, + + Attributes: map[string]schema.Attribute{ + "device": schema.StringAttribute{ + MarkdownDescription: "A device name from the provider configuration.", + Optional: true, + }, + "id": schema.StringAttribute{ + MarkdownDescription: "The distinguished name of the object.", + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "instance_name": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("IS-IS instance name.").String, + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, + }, + "vrf": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("VRF name.").String, + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, + }, + "address_family": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Address family type.").AddStringEnumDescription("v4", "v6").AddDefaultValueDescription("v4").String, + Required: true, + Validators: []validator.String{ + stringvalidator.OneOf("v4", "v6"), + }, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, + }, + "segment_routing_mpls": schema.BoolAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Segment routing for MPLS ").AddDefaultValueDescription("false").String, + Optional: true, + Computed: true, + Default: booldefault.StaticBool(false), + }, + "enable_bfd": schema.BoolAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Enabling BFD on all ISIS domain interfaces.").AddDefaultValueDescription("false").String, + Optional: true, + Computed: true, + Default: booldefault.StaticBool(false), + }, + "prefix_advertise_passive_l1": schema.BoolAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Prefix advertise passive only for level-1").AddDefaultValueDescription("false").String, + Optional: true, + Computed: true, + Default: booldefault.StaticBool(false), + }, + "prefix_advertise_passive_l2": schema.BoolAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Prefix advertise passive only level-2").AddDefaultValueDescription("false").String, + Optional: true, + Computed: true, + Default: booldefault.StaticBool(false), + }, + }, + } +} + +func (r *ISISAddressFamilyResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { + // Prevent panic if the provider has not been configured. + if req.ProviderData == nil { + return + } + + r.clients = req.ProviderData.(map[string]*nxos.Client) +} + +func (r *ISISAddressFamilyResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + var plan ISISAddressFamily + + // Read plan + diags := req.Plan.Get(ctx, &plan) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Create", plan.getDn())) + + client, ok := r.clients[plan.Device.ValueString()] + if !ok { + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to find device '%s' in provider configuration", plan.Device.ValueString())) + return + } + + // Post object + body := plan.toBody(false) + _, err := client.Post(plan.getDn(), body.Str) + if err != nil { + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to post object, got error: %s", err)) + return + } + + plan.Dn = types.StringValue(plan.getDn()) + + tflog.Debug(ctx, fmt.Sprintf("%s: Create finished successfully", plan.getDn())) + + diags = resp.State.Set(ctx, &plan) + resp.Diagnostics.Append(diags...) + + helpers.SetFlagImporting(ctx, false, resp.Private, &resp.Diagnostics) +} + +func (r *ISISAddressFamilyResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + var state ISISAddressFamily + + // Read state + diags := req.State.Get(ctx, &state) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Read", state.Dn.ValueString())) + + client, ok := r.clients[state.Device.ValueString()] + if !ok { + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to find device '%s' in provider configuration", state.Device.ValueString())) + return + } + + queries := []func(*nxos.Req){nxos.Query("rsp-prop-include", "config-only")} + res, err := client.GetDn(state.Dn.ValueString(), queries...) + if err != nil { + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve object, got error: %s", err)) + return + } + + imp, diags := helpers.IsFlagImporting(ctx, req) + if resp.Diagnostics.Append(diags...); resp.Diagnostics.HasError() { + return + } + state.fromBody(res, imp) + if imp { + state.getIdsFromDn() + } + + tflog.Debug(ctx, fmt.Sprintf("%s: Read finished successfully", state.Dn.ValueString())) + + diags = resp.State.Set(ctx, &state) + resp.Diagnostics.Append(diags...) + + helpers.SetFlagImporting(ctx, false, resp.Private, &resp.Diagnostics) +} + +func (r *ISISAddressFamilyResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + var plan ISISAddressFamily + + // Read plan + diags := req.Plan.Get(ctx, &plan) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Update", plan.getDn())) + + client, ok := r.clients[plan.Device.ValueString()] + if !ok { + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to find device '%s' in provider configuration", plan.Device.ValueString())) + return + } + + body := plan.toBody(false) + + _, err := client.Post(plan.getDn(), body.Str) + if err != nil { + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to update object, got error: %s", err)) + return + } + + tflog.Debug(ctx, fmt.Sprintf("%s: Update finished successfully", plan.getDn())) + + diags = resp.State.Set(ctx, &plan) + resp.Diagnostics.Append(diags...) +} + +func (r *ISISAddressFamilyResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + var state ISISAddressFamily + + // Read state + diags := req.State.Get(ctx, &state) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Delete", state.Dn.ValueString())) + + client, ok := r.clients[state.Device.ValueString()] + if !ok { + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to find device '%s' in provider configuration", state.Device.ValueString())) + return + } + + body := state.toDeleteBody() + + if len(body.Str) > 0 { + _, err := client.Post(state.getDn(), body.Str) + if err != nil { + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to update object, got error: %s", err)) + return + } + } else { + res, err := client.DeleteDn(state.Dn.ValueString()) + if err != nil { + errCode := res.Get("imdata.0.error.attributes.code").Str + // Ignore errors of type "Cannot delete object" + if errCode != "1" && errCode != "107" { + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to delete object, got error: %s", err)) + return + } + } + } + + tflog.Debug(ctx, fmt.Sprintf("%s: Delete finished successfully", state.Dn.ValueString())) + + resp.State.RemoveResource(ctx) +} + +func (r *ISISAddressFamilyResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + + helpers.SetFlagImporting(ctx, true, resp.Private, &resp.Diagnostics) +} diff --git a/internal/provider/resource_nxos_isis_address_family_test.go b/internal/provider/resource_nxos_isis_address_family_test.go new file mode 100644 index 00000000..0aba1dd5 --- /dev/null +++ b/internal/provider/resource_nxos_isis_address_family_test.go @@ -0,0 +1,114 @@ +// Copyright © 2023 Cisco Systems, Inc. and its affiliates. +// All rights reserved. +// +// Licensed under the Mozilla Public License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://mozilla.org/MPL/2.0/ +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: MPL-2.0 + +// Code generated by "gen/generator.go"; DO NOT EDIT. + +package provider + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" +) + +func TestAccNxosISISAddressFamily(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccNxosISISAddressFamilyPrerequisitesConfig + testAccNxosISISAddressFamilyConfig_all(), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("nxos_isis_address_family.test", "instance_name", "ISIS1"), + resource.TestCheckResourceAttr("nxos_isis_address_family.test", "vrf", "default"), + resource.TestCheckResourceAttr("nxos_isis_address_family.test", "address_family", "v4"), + resource.TestCheckResourceAttr("nxos_isis_address_family.test", "segment_routing_mpls", "true"), + resource.TestCheckResourceAttr("nxos_isis_address_family.test", "enable_bfd", "false"), + resource.TestCheckResourceAttr("nxos_isis_address_family.test", "prefix_advertise_passive_l1", "true"), + resource.TestCheckResourceAttr("nxos_isis_address_family.test", "prefix_advertise_passive_l2", "true"), + ), + }, + { + ResourceName: "nxos_isis_address_family.test", + ImportState: true, + ImportStateId: "sys/isis/inst-[ISIS1]/dom-[default]/af-[v4]", + }, + }, + }) +} + +const testAccNxosISISAddressFamilyPrerequisitesConfig = ` +resource "nxos_rest" "PreReq0" { + dn = "sys/fm/isis" + class_name = "fmIsis" + delete = false + content = { + adminSt = "enabled" + } +} + +resource "nxos_rest" "PreReq1" { + dn = "sys/isis" + class_name = "isisEntity" + depends_on = [nxos_rest.PreReq0, ] +} + +resource "nxos_rest" "PreReq2" { + dn = "sys/isis/inst-[ISIS1]" + class_name = "isisInst" + content = { + name = "ISIS1" + } + depends_on = [nxos_rest.PreReq1, ] +} + +resource "nxos_rest" "PreReq3" { + dn = "sys/isis/inst-[ISIS1]/dom-[default]" + class_name = "isisDom" + content = { + name = "default" + } + depends_on = [nxos_rest.PreReq2, ] +} + +` + +func testAccNxosISISAddressFamilyConfig_minimum() string { + return ` + resource "nxos_isis_address_family" "test" { + instance_name = "ISIS1" + vrf = "default" + address_family = "v4" + depends_on = [nxos_rest.PreReq0, nxos_rest.PreReq1, nxos_rest.PreReq2, nxos_rest.PreReq3, ] + } + ` +} + +func testAccNxosISISAddressFamilyConfig_all() string { + return ` + resource "nxos_isis_address_family" "test" { + instance_name = "ISIS1" + vrf = "default" + address_family = "v4" + segment_routing_mpls = true + enable_bfd = false + prefix_advertise_passive_l1 = true + prefix_advertise_passive_l2 = true + depends_on = [nxos_rest.PreReq0, nxos_rest.PreReq1, nxos_rest.PreReq2, nxos_rest.PreReq3, ] + } + ` +} diff --git a/internal/provider/resource_nxos_isis_overload.go b/internal/provider/resource_nxos_isis_overload.go new file mode 100644 index 00000000..ba79f921 --- /dev/null +++ b/internal/provider/resource_nxos_isis_overload.go @@ -0,0 +1,266 @@ +// Copyright © 2023 Cisco Systems, Inc. and its affiliates. +// All rights reserved. +// +// Licensed under the Mozilla Public License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://mozilla.org/MPL/2.0/ +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: MPL-2.0 + +// Code generated by "gen/generator.go"; DO NOT EDIT. + +package provider + +import ( + "context" + "fmt" + + "github.com/CiscoDevNet/terraform-provider-nxos/internal/provider/helpers" + "github.com/hashicorp/terraform-plugin-framework-validators/int64validator" + "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/int64default" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-plugin-log/tflog" + "github.com/netascode/go-nxos" +) + +// Ensure provider defined types fully satisfy framework interfaces +var _ resource.Resource = &ISISOverloadResource{} +var _ resource.ResourceWithImportState = &ISISOverloadResource{} + +func NewISISOverloadResource() resource.Resource { + return &ISISOverloadResource{} +} + +type ISISOverloadResource struct { + clients map[string]*nxos.Client +} + +func (r *ISISOverloadResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_isis_overload" +} + +func (r *ISISOverloadResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { + resp.Schema = schema.Schema{ + // This description is used by the documentation generator and the language server. + MarkdownDescription: helpers.NewResourceDescription("This resource can manage the IS-IS overload configuration.", "isisOverload", "Routing%20and%20Forwarding/isis:Overload/").AddParents("isis_vrf").AddReferences("vrf").String, + + Attributes: map[string]schema.Attribute{ + "device": schema.StringAttribute{ + MarkdownDescription: "A device name from the provider configuration.", + Optional: true, + }, + "id": schema.StringAttribute{ + MarkdownDescription: "The distinguished name of the object.", + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "instance_name": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("IS-IS instance name.").String, + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, + }, + "vrf": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("VRF name.").String, + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, + }, + "startup_time": schema.Int64Attribute{ + MarkdownDescription: helpers.NewAttributeDescription("The overload startup time. The overload state begins when the switch boots up and ends at the time specified as the overload startup time.").AddIntegerRangeDescription(5, 86400).AddDefaultValueDescription("60").String, + Optional: true, + Computed: true, + Default: int64default.StaticInt64(60), + Validators: []validator.Int64{ + int64validator.Between(5, 86400), + }, + }, + }, + } +} + +func (r *ISISOverloadResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { + // Prevent panic if the provider has not been configured. + if req.ProviderData == nil { + return + } + + r.clients = req.ProviderData.(map[string]*nxos.Client) +} + +func (r *ISISOverloadResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + var plan ISISOverload + + // Read plan + diags := req.Plan.Get(ctx, &plan) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Create", plan.getDn())) + + client, ok := r.clients[plan.Device.ValueString()] + if !ok { + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to find device '%s' in provider configuration", plan.Device.ValueString())) + return + } + + // Post object + body := plan.toBody(false) + _, err := client.Post(plan.getDn(), body.Str) + if err != nil { + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to post object, got error: %s", err)) + return + } + + plan.Dn = types.StringValue(plan.getDn()) + + tflog.Debug(ctx, fmt.Sprintf("%s: Create finished successfully", plan.getDn())) + + diags = resp.State.Set(ctx, &plan) + resp.Diagnostics.Append(diags...) + + helpers.SetFlagImporting(ctx, false, resp.Private, &resp.Diagnostics) +} + +func (r *ISISOverloadResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + var state ISISOverload + + // Read state + diags := req.State.Get(ctx, &state) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Read", state.Dn.ValueString())) + + client, ok := r.clients[state.Device.ValueString()] + if !ok { + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to find device '%s' in provider configuration", state.Device.ValueString())) + return + } + + queries := []func(*nxos.Req){nxos.Query("rsp-prop-include", "config-only")} + res, err := client.GetDn(state.Dn.ValueString(), queries...) + if err != nil { + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve object, got error: %s", err)) + return + } + + imp, diags := helpers.IsFlagImporting(ctx, req) + if resp.Diagnostics.Append(diags...); resp.Diagnostics.HasError() { + return + } + state.fromBody(res, imp) + if imp { + state.getIdsFromDn() + } + + tflog.Debug(ctx, fmt.Sprintf("%s: Read finished successfully", state.Dn.ValueString())) + + diags = resp.State.Set(ctx, &state) + resp.Diagnostics.Append(diags...) + + helpers.SetFlagImporting(ctx, false, resp.Private, &resp.Diagnostics) +} + +func (r *ISISOverloadResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + var plan ISISOverload + + // Read plan + diags := req.Plan.Get(ctx, &plan) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Update", plan.getDn())) + + client, ok := r.clients[plan.Device.ValueString()] + if !ok { + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to find device '%s' in provider configuration", plan.Device.ValueString())) + return + } + + body := plan.toBody(false) + + _, err := client.Post(plan.getDn(), body.Str) + if err != nil { + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to update object, got error: %s", err)) + return + } + + tflog.Debug(ctx, fmt.Sprintf("%s: Update finished successfully", plan.getDn())) + + diags = resp.State.Set(ctx, &plan) + resp.Diagnostics.Append(diags...) +} + +func (r *ISISOverloadResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + var state ISISOverload + + // Read state + diags := req.State.Get(ctx, &state) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Delete", state.Dn.ValueString())) + + client, ok := r.clients[state.Device.ValueString()] + if !ok { + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to find device '%s' in provider configuration", state.Device.ValueString())) + return + } + + body := state.toDeleteBody() + + if len(body.Str) > 0 { + _, err := client.Post(state.getDn(), body.Str) + if err != nil { + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to update object, got error: %s", err)) + return + } + } else { + res, err := client.DeleteDn(state.Dn.ValueString()) + if err != nil { + errCode := res.Get("imdata.0.error.attributes.code").Str + // Ignore errors of type "Cannot delete object" + if errCode != "1" && errCode != "107" { + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to delete object, got error: %s", err)) + return + } + } + } + + tflog.Debug(ctx, fmt.Sprintf("%s: Delete finished successfully", state.Dn.ValueString())) + + resp.State.RemoveResource(ctx) +} + +func (r *ISISOverloadResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + + helpers.SetFlagImporting(ctx, true, resp.Private, &resp.Diagnostics) +} diff --git a/internal/provider/resource_nxos_isis_overload_test.go b/internal/provider/resource_nxos_isis_overload_test.go new file mode 100644 index 00000000..c83a1589 --- /dev/null +++ b/internal/provider/resource_nxos_isis_overload_test.go @@ -0,0 +1,105 @@ +// Copyright © 2023 Cisco Systems, Inc. and its affiliates. +// All rights reserved. +// +// Licensed under the Mozilla Public License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://mozilla.org/MPL/2.0/ +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: MPL-2.0 + +// Code generated by "gen/generator.go"; DO NOT EDIT. + +package provider + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" +) + +func TestAccNxosISISOverload(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccNxosISISOverloadPrerequisitesConfig + testAccNxosISISOverloadConfig_all(), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("nxos_isis_overload.test", "instance_name", "ISIS1"), + resource.TestCheckResourceAttr("nxos_isis_overload.test", "vrf", "default"), + resource.TestCheckResourceAttr("nxos_isis_overload.test", "startup_time", "60"), + ), + }, + { + ResourceName: "nxos_isis_overload.test", + ImportState: true, + ImportStateId: "sys/isis/inst-[ISIS1]/dom-[default]/overload", + }, + }, + }) +} + +const testAccNxosISISOverloadPrerequisitesConfig = ` +resource "nxos_rest" "PreReq0" { + dn = "sys/fm/isis" + class_name = "fmIsis" + delete = false + content = { + adminSt = "enabled" + } +} + +resource "nxos_rest" "PreReq1" { + dn = "sys/isis" + class_name = "isisEntity" + depends_on = [nxos_rest.PreReq0, ] +} + +resource "nxos_rest" "PreReq2" { + dn = "sys/isis/inst-[ISIS1]" + class_name = "isisInst" + content = { + name = "ISIS1" + } + depends_on = [nxos_rest.PreReq1, ] +} + +resource "nxos_rest" "PreReq3" { + dn = "sys/isis/inst-[ISIS1]/dom-[default]" + class_name = "isisDom" + content = { + name = "default" + } + depends_on = [nxos_rest.PreReq2, ] +} + +` + +func testAccNxosISISOverloadConfig_minimum() string { + return ` + resource "nxos_isis_overload" "test" { + instance_name = "ISIS1" + vrf = "default" + depends_on = [nxos_rest.PreReq0, nxos_rest.PreReq1, nxos_rest.PreReq2, nxos_rest.PreReq3, ] + } + ` +} + +func testAccNxosISISOverloadConfig_all() string { + return ` + resource "nxos_isis_overload" "test" { + instance_name = "ISIS1" + vrf = "default" + startup_time = 60 + depends_on = [nxos_rest.PreReq0, nxos_rest.PreReq1, nxos_rest.PreReq2, nxos_rest.PreReq3, ] + } + ` +} diff --git a/internal/provider/resource_nxos_isis_vrf.go b/internal/provider/resource_nxos_isis_vrf.go index 16bd2f8e..09e983b0 100644 --- a/internal/provider/resource_nxos_isis_vrf.go +++ b/internal/provider/resource_nxos_isis_vrf.go @@ -59,7 +59,7 @@ func (r *ISISVRFResource) Metadata(ctx context.Context, req resource.MetadataReq func (r *ISISVRFResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { resp.Schema = schema.Schema{ // This description is used by the documentation generator and the language server. - MarkdownDescription: helpers.NewResourceDescription("This resource can manage the IS-IS VRF configuration.", "isisDom", "Routing%20and%20Forwarding/isis:Dom/").AddParents("isis_instance").AddReferences("vrf").String, + MarkdownDescription: helpers.NewResourceDescription("This resource can manage the IS-IS VRF configuration.", "isisDom", "Routing%20and%20Forwarding/isis:Dom/").AddParents("isis_instance").AddChildren("isis_address_family", "isis_overload").AddReferences("vrf").String, Attributes: map[string]schema.Attribute{ "device": schema.StringAttribute{ diff --git a/templates/guides/changelog.md.tmpl b/templates/guides/changelog.md.tmpl index bb9aad3d..a9098943 100644 --- a/templates/guides/changelog.md.tmpl +++ b/templates/guides/changelog.md.tmpl @@ -11,6 +11,8 @@ description: |- - Check if a device referenced in a resource or data source exists in the provider configuration - When importing a resource, also populate attributes referencing parent resources +- Add `nxos_isis_address_family` resource and data source +- Add `nxos_isis_overload` resource and data source ## 0.5.7 diff --git a/templates/guides/supported_objects.md.tmpl b/templates/guides/supported_objects.md.tmpl index 90227b66..cd770074 100644 --- a/templates/guides/supported_objects.md.tmpl +++ b/templates/guides/supported_objects.md.tmpl @@ -87,8 +87,10 @@ For the following DME objects a corresponding Terraform resource and data source | [ipv4Route](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Layer%203/ipv4:Route/) | [nxos_ipv4_static_route](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/ipv4_static_route) | [nxos_ipv4_static_route](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/data-sources/ipv4_static_route) | | [ipv4Dom](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Layer%203/ipv4:Dom/) | [nxos_ipv4_vrf](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/ipv4_vrf) | [nxos_ipv4_vrf](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/data-sources/ipv4_vrf) | | [isisEntity](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Routing%20and%20Forwarding/isis:Entity/) | [nxos_isis](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/isis) | [nxos_isis](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/data-sources/isis) | +| [isisDomAf](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Routing%20and%20Forwarding/isis:DomAf/) | [nxos_isis_address_family](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/isis_address_family) | [nxos_isis_address_family](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/data-sources/isis_address_family) | | [isisInst](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Routing%20and%20Forwarding/isis:Inst/) | [nxos_isis_instance](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/isis_instance) | [nxos_isis_instance](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/data-sources/isis_instance) | | [isisInternalIf](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Routing%20and%20Forwarding/isis:InternalIf/) | [nxos_isis_interface](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/isis_interface) | [nxos_isis_interface](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/data-sources/isis_interface) | +| [isisOverload](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Routing%20and%20Forwarding/isis:Overload/) | [nxos_isis_overload](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/isis_overload) | [nxos_isis_overload](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/data-sources/isis_overload) | | [isisDom](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Routing%20and%20Forwarding/isis:Dom/) | [nxos_isis_vrf](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/isis_vrf) | [nxos_isis_vrf](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/data-sources/isis_vrf) | | [l3LbRtdIf](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Layer%203/l3:LbRtdIf/) | [nxos_loopback_interface](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/loopback_interface) | [nxos_loopback_interface](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/data-sources/loopback_interface) | | [nwRtVrfMbr](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Routing%20and%20Forwarding/nw:RtVrfMbr/) | [nxos_loopback_interface_vrf](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/loopback_interface_vrf) | [nxos_loopback_interface_vrf](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/data-sources/loopback_interface_vrf) |