diff --git a/CHANGELOG.md b/CHANGELOG.md index da5ee62d..989cc439 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.5.2 (unreleased) + +- Add `nxos_vpc_keepalive` resource and data source + ## 0.5.1 - Add `nxos_bgp_advertised_prefix` resource and data source diff --git a/docs/data-sources/vpc_keepalive.md b/docs/data-sources/vpc_keepalive.md new file mode 100644 index 00000000..c5c61a84 --- /dev/null +++ b/docs/data-sources/vpc_keepalive.md @@ -0,0 +1,45 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "nxos_vpc_keepalive Data Source - terraform-provider-nxos" +subcategory: "vPC" +description: |- + This data source can read the vPC keepalive configuration. + API Documentation: vpcKeepalive https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/System/vpc:Keepalive/ +--- + +# nxos_vpc_keepalive (Data Source) + +This data source can read the vPC keepalive configuration. + +- API Documentation: [vpcKeepalive](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/System/vpc:Keepalive/) + +## Example Usage + +```terraform +data "nxos_vpc_keepalive" "example" { +} +``` + + +## Schema + +### Optional + +- `device` (String) A device name from the provider configuration. + +### Read-Only + +- `destination_ip` (String) vPC Keepalive destination address. +- `flush_timeout` (Number) vPC Keepalive flush timeout. +- `id` (String) The distinguished name of the object. +- `interval` (Number) vPC Keepalive interval. +- `precedence_type` (Number) vPC Keepalive precedence type. `0` - network, `1` - internet, `2` - critical, `3` flash-override, `4` - flash, `5` - immediate, `6` - prioriy, `7` - routine. +- `precedence_value` (Number) vPC Keepalive precedence value. +- `source_ip` (String) vPC Keepalive source address. +- `timeout` (Number) vPC Keepalive timeout. +- `type_of_service_byte` (Number) vPC Keepalive type of service (ToS) byte. +- `type_of_service_configuration_type` (Number) vPC Keepalive type of service (ToS) configuration type. `0` - noCfg, `1` - tos-byte, `2` - tos-value, `3` - tos-type, `4` - precedence-type, `5` - precedence-value. +- `type_of_service_type` (Number) vPC Keepalive type of service (ToS) type. `0` - min-delay, `1` - max-throughput, `2` - max-reliability, `3` - min-monetary-cost, `4` - normal. +- `type_of_service_value` (Number) vPC Keepalive type of service (ToS) value. +- `udp_port` (Number) vPC Keepalive UDP port. +- `vrf` (String) vPC Keepalive VRF. diff --git a/docs/guides/supported_objects.md b/docs/guides/supported_objects.md index aba62cae..18f0f6c5 100644 --- a/docs/guides/supported_objects.md +++ b/docs/guides/supported_objects.md @@ -132,6 +132,7 @@ For the following DME objects a corresponding Terraform resource and data source | [vpcDom](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/System/vpc:Dom/) | [nxos_vpc_domain](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/vpc_domain) | [nxos_vpc_domain](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/data-sources/vpc_domain) | | [vpcInst](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/System/vpc:Inst/) | [nxos_vpc_instance](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/vpc_instance) | [nxos_vpc_instance](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/data-sources/vpc_instance) | | [vpcIf](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/System/vpc:If/) | [nxos_vpc_interface](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/vpc_interface) | [nxos_vpc_interface](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/data-sources/vpc_interface) | +| [vpcKeepalive](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/System/vpc:Keepalive/) | [nxos_vpc_keepalive](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/vpc_keepalive) | [nxos_vpc_keepalive](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/data-sources/vpc_keepalive) | | [l3Inst](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Layer%203/l3:Inst/) | [nxos_vrf](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/vrf) | [nxos_vrf](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/data-sources/vrf) | | [rtctrlDomAf](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Routing%20and%20Forwarding/rtctrl:DomAf/) | [nxos_vrf_address_family](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/vrf_address_family) | [nxos_vrf_address_family](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/data-sources/vrf_address_family) | | [rtctrlRttEntry](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Routing%20and%20Forwarding/rtctrl:RttEntry/) | [nxos_vrf_route_target](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/vrf_route_target) | [nxos_vrf_route_target](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/data-sources/vrf_route_target) | diff --git a/docs/resources/vpc_domain.md b/docs/resources/vpc_domain.md index e03957cc..8a32620f 100644 --- a/docs/resources/vpc_domain.md +++ b/docs/resources/vpc_domain.md @@ -8,7 +8,7 @@ description: |- Parent resources nxosvpcinstance https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/vpc_instance Child resources - nxosvpcinterface https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/vpc_interface + nxosvpcinterface https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/vpc_interfacenxosvpckeepalive https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/vpc_keepalive --- # nxos_vpc_domain (Resource) @@ -24,6 +24,7 @@ This resource can manage the vPC domain configuration. ### Child resources - [nxos_vpc_interface](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/vpc_interface) +- [nxos_vpc_keepalive](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/vpc_keepalive) ## Example Usage diff --git a/docs/resources/vpc_keepalive.md b/docs/resources/vpc_keepalive.md new file mode 100644 index 00000000..45fe8ebc --- /dev/null +++ b/docs/resources/vpc_keepalive.md @@ -0,0 +1,85 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "nxos_vpc_keepalive Resource - terraform-provider-nxos" +subcategory: "vPC" +description: |- + This resource can manage the vPC keepalive configuration. + API Documentation: vpcKeepalive https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/System/vpc:Keepalive/ + Parent resources + nxosvpcdomain https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/vpc_domain +--- + +# nxos_vpc_keepalive (Resource) + +This resource can manage the vPC keepalive configuration. + +- API Documentation: [vpcKeepalive](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/System/vpc:Keepalive/) + +### Parent resources + +- [nxos_vpc_domain](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/vpc_domain) + +## Example Usage + +```terraform +resource "nxos_vpc_keepalive" "example" { + destination_ip = "192.168.1.1" + flush_timeout = 3 + interval = 1000 + precedence_type = 0 + precedence_value = 6 + source_ip = "192.168.1.2" + timeout = 5 + type_of_service_byte = 0 + type_of_service_configuration_type = 0 + type_of_service_type = 0 + type_of_service_value = 0 + udp_port = 1234 + vrf = "management" +} +``` + + +## Schema + +### Required + +- `destination_ip` (String) vPC Keepalive destination address. +- `source_ip` (String) vPC Keepalive source address. + +### Optional + +- `device` (String) A device name from the provider configuration. +- `flush_timeout` (Number) vPC Keepalive flush timeout. + - Range: `3`-`10` +- `interval` (Number) vPC Keepalive interval. + - Range: `400`-`10000` +- `precedence_type` (Number) vPC Keepalive precedence type. `0` - network, `1` - internet, `2` - critical, `3` flash-override, `4` - flash, `5` - immediate, `6` - prioriy, `7` - routine. + - Range: `0`-`7` +- `precedence_value` (Number) vPC Keepalive precedence value. + - Range: `0`-`7` +- `timeout` (Number) vPC Keepalive timeout. + - Range: `3`-`20` +- `type_of_service_byte` (Number) vPC Keepalive type of service (ToS) byte. + - Range: `0`-`255` +- `type_of_service_configuration_type` (Number) vPC Keepalive type of service (ToS) configuration type. `0` - noCfg, `1` - tos-byte, `2` - tos-value, `3` - tos-type, `4` - precedence-type, `5` - precedence-value. + - Range: `0`-`5` +- `type_of_service_type` (Number) vPC Keepalive type of service (ToS) type. `0` - min-delay, `1` - max-throughput, `2` - max-reliability, `3` - min-monetary-cost, `4` - normal. + - Range: `0`-`4` +- `type_of_service_value` (Number) vPC Keepalive type of service (ToS) value. + - Range: `0`-`15` +- `udp_port` (Number) vPC Keepalive UDP port. + - Range: `1`-`65535` +- `vrf` (String) vPC Keepalive VRF. + +### Read-Only + +- `id` (String) The distinguished name of the object. + +## Import + +Import is supported using the following syntax: + +```shell +terraform import nxos_vpc_keepalive.example "sys/vpc/inst/dom/keepalive" +``` diff --git a/examples/data-sources/nxos_vpc_keepalive/data-source.tf b/examples/data-sources/nxos_vpc_keepalive/data-source.tf new file mode 100644 index 00000000..a5d32e9b --- /dev/null +++ b/examples/data-sources/nxos_vpc_keepalive/data-source.tf @@ -0,0 +1,2 @@ +data "nxos_vpc_keepalive" "example" { +} diff --git a/examples/resources/nxos_vpc_keepalive/import.sh b/examples/resources/nxos_vpc_keepalive/import.sh new file mode 100644 index 00000000..38468ae0 --- /dev/null +++ b/examples/resources/nxos_vpc_keepalive/import.sh @@ -0,0 +1 @@ +terraform import nxos_vpc_keepalive.example "sys/vpc/inst/dom/keepalive" diff --git a/examples/resources/nxos_vpc_keepalive/resource.tf b/examples/resources/nxos_vpc_keepalive/resource.tf new file mode 100644 index 00000000..b97fe25f --- /dev/null +++ b/examples/resources/nxos_vpc_keepalive/resource.tf @@ -0,0 +1,15 @@ +resource "nxos_vpc_keepalive" "example" { + destination_ip = "192.168.1.1" + flush_timeout = 3 + interval = 1000 + precedence_type = 0 + precedence_value = 6 + source_ip = "192.168.1.2" + timeout = 5 + type_of_service_byte = 0 + type_of_service_configuration_type = 0 + type_of_service_type = 0 + type_of_service_value = 0 + udp_port = 1234 + vrf = "management" +} diff --git a/gen/definitions/vpc_domain.yaml b/gen/definitions/vpc_domain.yaml index 74717003..297914b2 100644 --- a/gen/definitions/vpc_domain.yaml +++ b/gen/definitions/vpc_domain.yaml @@ -10,6 +10,7 @@ parents: - vPC Instance children: - vPC Interface + - vPC Keepalive attributes: - nxos_name: adminSt tf_name: admin_state diff --git a/gen/definitions/vpc_keepalive.yaml b/gen/definitions/vpc_keepalive.yaml new file mode 100644 index 00000000..f9ca7cfe --- /dev/null +++ b/gen/definitions/vpc_keepalive.yaml @@ -0,0 +1,121 @@ +--- +name: vPC Keepalive +class_name: vpcKeepalive +dn: sys/vpc/inst/dom/keepalive +ds_description: This data source can read the vPC keepalive configuration. +res_description: This resource can manage the vPC keepalive configuration. +doc_path: System/vpc:Keepalive/ +doc_category: vPC +parents: + - vPC Domain +attributes: + - nxos_name: destIp + tf_name: destination_ip + type: String + mandatory: true + description: "vPC Keepalive destination address." + example: "192.168.1.1" + - nxos_name: flushTout + tf_name: flush_timeout + type: Int64 + description: "vPC Keepalive flush timeout." + min_int: 3 + max_int: 10 + default: 3 + example: 3 + - nxos_name: interval + tf_name: interval + type: Int64 + description: "vPC Keepalive interval." + min_int: 400 + max_int: 10000 + default: 1000 + example: 1000 + - nxos_name: precType + tf_name: precedence_type + type: Int64 + description: "vPC Keepalive precedence type. `0` - network, `1` - internet, `2` - critical, `3` flash-override, `4` - flash, `5` - immediate, `6` - prioriy, `7` - routine." + min_int: 0 + max_int: 7 + default: 0 + example: 0 + - nxos_name: precValue + tf_name: precedence_value + type: Int64 + description: "vPC Keepalive precedence value." + min_int: 0 + max_int: 7 + default: 6 + example: 6 + - nxos_name: srcIp + tf_name: source_ip + type: String + mandatory: true + description: "vPC Keepalive source address." + example: "192.168.1.2" + - nxos_name: timeout + tf_name: timeout + type: Int64 + description: "vPC Keepalive timeout." + min_int: 3 + max_int: 20 + default: 5 + example: 5 + - nxos_name: tosByte + tf_name: type_of_service_byte + type: Int64 + description: "vPC Keepalive type of service (ToS) byte." + min_int: 0 + max_int: 255 + default: 0 + example: 0 + - nxos_name: tosCfgType + tf_name: type_of_service_configuration_type + type: Int64 + description: "vPC Keepalive type of service (ToS) configuration type. `0` - noCfg, `1` - tos-byte, `2` - tos-value, `3` - tos-type, `4` - precedence-type, `5` - precedence-value." + min_int: 0 + max_int: 5 + default: 0 + example: 0 + - nxos_name: tosType + tf_name: type_of_service_type + type: Int64 + description: "vPC Keepalive type of service (ToS) type. `0` - min-delay, `1` - max-throughput, `2` - max-reliability, `3` - min-monetary-cost, `4` - normal." + min_int: 0 + max_int: 4 + default: 4 + example: 0 + - nxos_name: tosValue + tf_name: type_of_service_value + type: Int64 + description: "vPC Keepalive type of service (ToS) value." + min_int: 0 + max_int: 15 + default: 0 + example: 0 + - nxos_name: udpPort + tf_name: udp_port + type: Int64 + description: "vPC Keepalive UDP port." + min_int: 1 + max_int: 65535 + example: 1234 + omit_empty_value: true + - nxos_name: vrf + tf_name: vrf + description: "vPC Keepalive VRF." + type: String + example: "management" +test_prerequisites: + - dn: sys/fm/vpc + class_name: fmVpc + no_delete: true + attributes: + - name: adminSt + value: enabled + - dn: sys/vpc/inst + class_name: vpcInst + dependencies: [0] + - dn: sys/vpc/inst/dom + class_name: vpcDom + dependencies: [1] \ No newline at end of file diff --git a/internal/provider/data_source_nxos_vpc_keepalive.go b/internal/provider/data_source_nxos_vpc_keepalive.go new file mode 100644 index 00000000..38fb9c75 --- /dev/null +++ b/internal/provider/data_source_nxos_vpc_keepalive.go @@ -0,0 +1,156 @@ +// 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 = &VPCKeepaliveDataSource{} + _ datasource.DataSourceWithConfigure = &VPCKeepaliveDataSource{} +) + +func NewVPCKeepaliveDataSource() datasource.DataSource { + return &VPCKeepaliveDataSource{} +} + +type VPCKeepaliveDataSource struct { + clients map[string]*nxos.Client +} + +func (d *VPCKeepaliveDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_vpc_keepalive" +} + +func (d *VPCKeepaliveDataSource) 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 vPC keepalive configuration.", "vpcKeepalive", "System/vpc:Keepalive/").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, + }, + "destination_ip": schema.StringAttribute{ + MarkdownDescription: "vPC Keepalive destination address.", + Computed: true, + }, + "flush_timeout": schema.Int64Attribute{ + MarkdownDescription: "vPC Keepalive flush timeout.", + Computed: true, + }, + "interval": schema.Int64Attribute{ + MarkdownDescription: "vPC Keepalive interval.", + Computed: true, + }, + "precedence_type": schema.Int64Attribute{ + MarkdownDescription: "vPC Keepalive precedence type. `0` - network, `1` - internet, `2` - critical, `3` flash-override, `4` - flash, `5` - immediate, `6` - prioriy, `7` - routine.", + Computed: true, + }, + "precedence_value": schema.Int64Attribute{ + MarkdownDescription: "vPC Keepalive precedence value.", + Computed: true, + }, + "source_ip": schema.StringAttribute{ + MarkdownDescription: "vPC Keepalive source address.", + Computed: true, + }, + "timeout": schema.Int64Attribute{ + MarkdownDescription: "vPC Keepalive timeout.", + Computed: true, + }, + "type_of_service_byte": schema.Int64Attribute{ + MarkdownDescription: "vPC Keepalive type of service (ToS) byte.", + Computed: true, + }, + "type_of_service_configuration_type": schema.Int64Attribute{ + MarkdownDescription: "vPC Keepalive type of service (ToS) configuration type. `0` - noCfg, `1` - tos-byte, `2` - tos-value, `3` - tos-type, `4` - precedence-type, `5` - precedence-value.", + Computed: true, + }, + "type_of_service_type": schema.Int64Attribute{ + MarkdownDescription: "vPC Keepalive type of service (ToS) type. `0` - min-delay, `1` - max-throughput, `2` - max-reliability, `3` - min-monetary-cost, `4` - normal.", + Computed: true, + }, + "type_of_service_value": schema.Int64Attribute{ + MarkdownDescription: "vPC Keepalive type of service (ToS) value.", + Computed: true, + }, + "udp_port": schema.Int64Attribute{ + MarkdownDescription: "vPC Keepalive UDP port.", + Computed: true, + }, + "vrf": schema.StringAttribute{ + MarkdownDescription: "vPC Keepalive VRF.", + Computed: true, + }, + }, + } +} + +func (d *VPCKeepaliveDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, _ *datasource.ConfigureResponse) { + if req.ProviderData == nil { + return + } + + d.clients = req.ProviderData.(map[string]*nxos.Client) +} + +func (d *VPCKeepaliveDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + var config VPCKeepalive + + // 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())) + + queries := []func(*nxos.Req){} + res, err := d.clients[config.Device.ValueString()].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_vpc_keepalive_test.go b/internal/provider/data_source_nxos_vpc_keepalive_test.go new file mode 100644 index 00000000..a028209a --- /dev/null +++ b/internal/provider/data_source_nxos_vpc_keepalive_test.go @@ -0,0 +1,101 @@ +// 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 TestAccDataSourceNxosVPCKeepalive(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceNxosVPCKeepalivePrerequisitesConfig + testAccDataSourceNxosVPCKeepaliveConfig, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("data.nxos_vpc_keepalive.test", "destination_ip", "192.168.1.1"), + resource.TestCheckResourceAttr("data.nxos_vpc_keepalive.test", "flush_timeout", "3"), + resource.TestCheckResourceAttr("data.nxos_vpc_keepalive.test", "interval", "1000"), + resource.TestCheckResourceAttr("data.nxos_vpc_keepalive.test", "precedence_type", "0"), + resource.TestCheckResourceAttr("data.nxos_vpc_keepalive.test", "precedence_value", "6"), + resource.TestCheckResourceAttr("data.nxos_vpc_keepalive.test", "source_ip", "192.168.1.2"), + resource.TestCheckResourceAttr("data.nxos_vpc_keepalive.test", "timeout", "5"), + resource.TestCheckResourceAttr("data.nxos_vpc_keepalive.test", "type_of_service_byte", "0"), + resource.TestCheckResourceAttr("data.nxos_vpc_keepalive.test", "type_of_service_configuration_type", "0"), + resource.TestCheckResourceAttr("data.nxos_vpc_keepalive.test", "type_of_service_type", "0"), + resource.TestCheckResourceAttr("data.nxos_vpc_keepalive.test", "type_of_service_value", "0"), + resource.TestCheckResourceAttr("data.nxos_vpc_keepalive.test", "udp_port", "1234"), + resource.TestCheckResourceAttr("data.nxos_vpc_keepalive.test", "vrf", "management"), + ), + }, + }, + }) +} + +const testAccDataSourceNxosVPCKeepalivePrerequisitesConfig = ` +resource "nxos_rest" "PreReq0" { + dn = "sys/fm/vpc" + class_name = "fmVpc" + delete = false + content = { + adminSt = "enabled" + } +} + +resource "nxos_rest" "PreReq1" { + dn = "sys/vpc/inst" + class_name = "vpcInst" + depends_on = [nxos_rest.PreReq0, ] +} + +resource "nxos_rest" "PreReq2" { + dn = "sys/vpc/inst/dom" + class_name = "vpcDom" + depends_on = [nxos_rest.PreReq1, ] +} + +` + +const testAccDataSourceNxosVPCKeepaliveConfig = ` + +resource "nxos_vpc_keepalive" "test" { + destination_ip = "192.168.1.1" + flush_timeout = 3 + interval = 1000 + precedence_type = 0 + precedence_value = 6 + source_ip = "192.168.1.2" + timeout = 5 + type_of_service_byte = 0 + type_of_service_configuration_type = 0 + type_of_service_type = 0 + type_of_service_value = 0 + udp_port = 1234 + vrf = "management" + depends_on = [nxos_rest.PreReq0, nxos_rest.PreReq1, nxos_rest.PreReq2, ] +} + +data "nxos_vpc_keepalive" "test" { + depends_on = [nxos_vpc_keepalive.test] +} +` diff --git a/internal/provider/model_nxos_vpc_keepalive.go b/internal/provider/model_nxos_vpc_keepalive.go new file mode 100644 index 00000000..fc2504a6 --- /dev/null +++ b/internal/provider/model_nxos_vpc_keepalive.go @@ -0,0 +1,169 @@ +// 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 ( + "strconv" + + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/netascode/go-nxos" + "github.com/tidwall/gjson" + "github.com/tidwall/sjson" +) + +type VPCKeepalive struct { + Device types.String `tfsdk:"device"` + Dn types.String `tfsdk:"id"` + DestinationIp types.String `tfsdk:"destination_ip"` + FlushTimeout types.Int64 `tfsdk:"flush_timeout"` + Interval types.Int64 `tfsdk:"interval"` + PrecedenceType types.Int64 `tfsdk:"precedence_type"` + PrecedenceValue types.Int64 `tfsdk:"precedence_value"` + SourceIp types.String `tfsdk:"source_ip"` + Timeout types.Int64 `tfsdk:"timeout"` + TypeOfServiceByte types.Int64 `tfsdk:"type_of_service_byte"` + TypeOfServiceConfigurationType types.Int64 `tfsdk:"type_of_service_configuration_type"` + TypeOfServiceType types.Int64 `tfsdk:"type_of_service_type"` + TypeOfServiceValue types.Int64 `tfsdk:"type_of_service_value"` + UdpPort types.Int64 `tfsdk:"udp_port"` + Vrf types.String `tfsdk:"vrf"` +} + +func (data VPCKeepalive) getDn() string { + return "sys/vpc/inst/dom/keepalive" +} + +func (data VPCKeepalive) getClassName() string { + return "vpcKeepalive" +} + +func (data VPCKeepalive) toBody() nxos.Body { + body := "" + body, _ = sjson.Set(body, data.getClassName()+".attributes", map[string]interface{}{}) + if (!data.DestinationIp.IsUnknown() && !data.DestinationIp.IsNull()) || true { + body, _ = sjson.Set(body, data.getClassName()+".attributes."+"destIp", data.DestinationIp.ValueString()) + } + if (!data.FlushTimeout.IsUnknown() && !data.FlushTimeout.IsNull()) || true { + body, _ = sjson.Set(body, data.getClassName()+".attributes."+"flushTout", strconv.FormatInt(data.FlushTimeout.ValueInt64(), 10)) + } + if (!data.Interval.IsUnknown() && !data.Interval.IsNull()) || true { + body, _ = sjson.Set(body, data.getClassName()+".attributes."+"interval", strconv.FormatInt(data.Interval.ValueInt64(), 10)) + } + if (!data.PrecedenceType.IsUnknown() && !data.PrecedenceType.IsNull()) || true { + body, _ = sjson.Set(body, data.getClassName()+".attributes."+"precType", strconv.FormatInt(data.PrecedenceType.ValueInt64(), 10)) + } + if (!data.PrecedenceValue.IsUnknown() && !data.PrecedenceValue.IsNull()) || true { + body, _ = sjson.Set(body, data.getClassName()+".attributes."+"precValue", strconv.FormatInt(data.PrecedenceValue.ValueInt64(), 10)) + } + if (!data.SourceIp.IsUnknown() && !data.SourceIp.IsNull()) || true { + body, _ = sjson.Set(body, data.getClassName()+".attributes."+"srcIp", data.SourceIp.ValueString()) + } + if (!data.Timeout.IsUnknown() && !data.Timeout.IsNull()) || true { + body, _ = sjson.Set(body, data.getClassName()+".attributes."+"timeout", strconv.FormatInt(data.Timeout.ValueInt64(), 10)) + } + if (!data.TypeOfServiceByte.IsUnknown() && !data.TypeOfServiceByte.IsNull()) || true { + body, _ = sjson.Set(body, data.getClassName()+".attributes."+"tosByte", strconv.FormatInt(data.TypeOfServiceByte.ValueInt64(), 10)) + } + if (!data.TypeOfServiceConfigurationType.IsUnknown() && !data.TypeOfServiceConfigurationType.IsNull()) || true { + body, _ = sjson.Set(body, data.getClassName()+".attributes."+"tosCfgType", strconv.FormatInt(data.TypeOfServiceConfigurationType.ValueInt64(), 10)) + } + if (!data.TypeOfServiceType.IsUnknown() && !data.TypeOfServiceType.IsNull()) || true { + body, _ = sjson.Set(body, data.getClassName()+".attributes."+"tosType", strconv.FormatInt(data.TypeOfServiceType.ValueInt64(), 10)) + } + if (!data.TypeOfServiceValue.IsUnknown() && !data.TypeOfServiceValue.IsNull()) || true { + body, _ = sjson.Set(body, data.getClassName()+".attributes."+"tosValue", strconv.FormatInt(data.TypeOfServiceValue.ValueInt64(), 10)) + } + if (!data.UdpPort.IsUnknown() && !data.UdpPort.IsNull()) || false { + body, _ = sjson.Set(body, data.getClassName()+".attributes."+"udpPort", strconv.FormatInt(data.UdpPort.ValueInt64(), 10)) + } + if (!data.Vrf.IsUnknown() && !data.Vrf.IsNull()) || true { + body, _ = sjson.Set(body, data.getClassName()+".attributes."+"vrf", data.Vrf.ValueString()) + } + + return nxos.Body{body} +} + +func (data *VPCKeepalive) fromBody(res gjson.Result, all bool) { + if !data.DestinationIp.IsNull() || all { + data.DestinationIp = types.StringValue(res.Get(data.getClassName() + ".attributes.destIp").String()) + } else { + data.DestinationIp = types.StringNull() + } + if !data.FlushTimeout.IsNull() || all { + data.FlushTimeout = types.Int64Value(res.Get(data.getClassName() + ".attributes.flushTout").Int()) + } else { + data.FlushTimeout = types.Int64Null() + } + if !data.Interval.IsNull() || all { + data.Interval = types.Int64Value(res.Get(data.getClassName() + ".attributes.interval").Int()) + } else { + data.Interval = types.Int64Null() + } + if !data.PrecedenceType.IsNull() || all { + data.PrecedenceType = types.Int64Value(res.Get(data.getClassName() + ".attributes.precType").Int()) + } else { + data.PrecedenceType = types.Int64Null() + } + if !data.PrecedenceValue.IsNull() || all { + data.PrecedenceValue = types.Int64Value(res.Get(data.getClassName() + ".attributes.precValue").Int()) + } else { + data.PrecedenceValue = types.Int64Null() + } + if !data.SourceIp.IsNull() || all { + data.SourceIp = types.StringValue(res.Get(data.getClassName() + ".attributes.srcIp").String()) + } else { + data.SourceIp = types.StringNull() + } + if !data.Timeout.IsNull() || all { + data.Timeout = types.Int64Value(res.Get(data.getClassName() + ".attributes.timeout").Int()) + } else { + data.Timeout = types.Int64Null() + } + if !data.TypeOfServiceByte.IsNull() || all { + data.TypeOfServiceByte = types.Int64Value(res.Get(data.getClassName() + ".attributes.tosByte").Int()) + } else { + data.TypeOfServiceByte = types.Int64Null() + } + if !data.TypeOfServiceConfigurationType.IsNull() || all { + data.TypeOfServiceConfigurationType = types.Int64Value(res.Get(data.getClassName() + ".attributes.tosCfgType").Int()) + } else { + data.TypeOfServiceConfigurationType = types.Int64Null() + } + if !data.TypeOfServiceType.IsNull() || all { + data.TypeOfServiceType = types.Int64Value(res.Get(data.getClassName() + ".attributes.tosType").Int()) + } else { + data.TypeOfServiceType = types.Int64Null() + } + if !data.TypeOfServiceValue.IsNull() || all { + data.TypeOfServiceValue = types.Int64Value(res.Get(data.getClassName() + ".attributes.tosValue").Int()) + } else { + data.TypeOfServiceValue = types.Int64Null() + } + if !data.UdpPort.IsNull() || all { + data.UdpPort = types.Int64Value(res.Get(data.getClassName() + ".attributes.udpPort").Int()) + } else { + data.UdpPort = types.Int64Null() + } + if !data.Vrf.IsNull() || all { + data.Vrf = types.StringValue(res.Get(data.getClassName() + ".attributes.vrf").String()) + } else { + data.Vrf = types.StringNull() + } +} diff --git a/internal/provider/provider.go b/internal/provider/provider.go index ac78b655..c7e9879c 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -392,6 +392,7 @@ func (p *NxosProvider) Resources(ctx context.Context) []func() resource.Resource NewVPCDomainResource, NewVPCInstanceResource, NewVPCInterfaceResource, + NewVPCKeepaliveResource, NewVRFResource, NewVRFAddressFamilyResource, NewVRFRouteTargetResource, @@ -525,6 +526,7 @@ func (p *NxosProvider) DataSources(ctx context.Context) []func() datasource.Data NewVPCDomainDataSource, NewVPCInstanceDataSource, NewVPCInterfaceDataSource, + NewVPCKeepaliveDataSource, NewVRFDataSource, NewVRFAddressFamilyDataSource, NewVRFRouteTargetDataSource, diff --git a/internal/provider/resource_nxos_vpc_domain.go b/internal/provider/resource_nxos_vpc_domain.go index bd63e536..bc35552a 100644 --- a/internal/provider/resource_nxos_vpc_domain.go +++ b/internal/provider/resource_nxos_vpc_domain.go @@ -58,7 +58,7 @@ func (r *VPCDomainResource) Metadata(ctx context.Context, req resource.MetadataR func (r *VPCDomainResource) 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 vPC domain configuration.", "vpcDom", "System/vpc:Dom/").AddParents("vpc_instance").AddChildren("vpc_interface").String, + MarkdownDescription: helpers.NewResourceDescription("This resource can manage the vPC domain configuration.", "vpcDom", "System/vpc:Dom/").AddParents("vpc_instance").AddChildren("vpc_interface", "vpc_keepalive").String, Attributes: map[string]schema.Attribute{ "device": schema.StringAttribute{ diff --git a/internal/provider/resource_nxos_vpc_keepalive.go b/internal/provider/resource_nxos_vpc_keepalive.go new file mode 100644 index 00000000..4ee085b2 --- /dev/null +++ b/internal/provider/resource_nxos_vpc_keepalive.go @@ -0,0 +1,276 @@ +// 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/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 = &VPCKeepaliveResource{} +var _ resource.ResourceWithImportState = &VPCKeepaliveResource{} + +func NewVPCKeepaliveResource() resource.Resource { + return &VPCKeepaliveResource{} +} + +type VPCKeepaliveResource struct { + clients map[string]*nxos.Client +} + +func (r *VPCKeepaliveResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_vpc_keepalive" +} + +func (r *VPCKeepaliveResource) 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 vPC keepalive configuration.", "vpcKeepalive", "System/vpc:Keepalive/").AddParents("vpc_domain").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(), + }, + }, + "destination_ip": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("vPC Keepalive destination address.").String, + Required: true, + }, + "flush_timeout": schema.Int64Attribute{ + MarkdownDescription: helpers.NewAttributeDescription("vPC Keepalive flush timeout.").AddIntegerRangeDescription(3, 10).String, + Optional: true, + Validators: []validator.Int64{ + int64validator.Between(3, 10), + }, + }, + "interval": schema.Int64Attribute{ + MarkdownDescription: helpers.NewAttributeDescription("vPC Keepalive interval.").AddIntegerRangeDescription(400, 10000).String, + Optional: true, + Validators: []validator.Int64{ + int64validator.Between(400, 10000), + }, + }, + "precedence_type": schema.Int64Attribute{ + MarkdownDescription: helpers.NewAttributeDescription("vPC Keepalive precedence type. `0` - network, `1` - internet, `2` - critical, `3` flash-override, `4` - flash, `5` - immediate, `6` - prioriy, `7` - routine.").AddIntegerRangeDescription(0, 7).String, + Optional: true, + Validators: []validator.Int64{ + int64validator.Between(0, 7), + }, + }, + "precedence_value": schema.Int64Attribute{ + MarkdownDescription: helpers.NewAttributeDescription("vPC Keepalive precedence value.").AddIntegerRangeDescription(0, 7).String, + Optional: true, + Validators: []validator.Int64{ + int64validator.Between(0, 7), + }, + }, + "source_ip": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("vPC Keepalive source address.").String, + Required: true, + }, + "timeout": schema.Int64Attribute{ + MarkdownDescription: helpers.NewAttributeDescription("vPC Keepalive timeout.").AddIntegerRangeDescription(3, 20).String, + Optional: true, + Validators: []validator.Int64{ + int64validator.Between(3, 20), + }, + }, + "type_of_service_byte": schema.Int64Attribute{ + MarkdownDescription: helpers.NewAttributeDescription("vPC Keepalive type of service (ToS) byte.").AddIntegerRangeDescription(0, 255).String, + Optional: true, + Validators: []validator.Int64{ + int64validator.Between(0, 255), + }, + }, + "type_of_service_configuration_type": schema.Int64Attribute{ + MarkdownDescription: helpers.NewAttributeDescription("vPC Keepalive type of service (ToS) configuration type. `0` - noCfg, `1` - tos-byte, `2` - tos-value, `3` - tos-type, `4` - precedence-type, `5` - precedence-value.").AddIntegerRangeDescription(0, 5).String, + Optional: true, + Validators: []validator.Int64{ + int64validator.Between(0, 5), + }, + }, + "type_of_service_type": schema.Int64Attribute{ + MarkdownDescription: helpers.NewAttributeDescription("vPC Keepalive type of service (ToS) type. `0` - min-delay, `1` - max-throughput, `2` - max-reliability, `3` - min-monetary-cost, `4` - normal.").AddIntegerRangeDescription(0, 4).String, + Optional: true, + Validators: []validator.Int64{ + int64validator.Between(0, 4), + }, + }, + "type_of_service_value": schema.Int64Attribute{ + MarkdownDescription: helpers.NewAttributeDescription("vPC Keepalive type of service (ToS) value.").AddIntegerRangeDescription(0, 15).String, + Optional: true, + Validators: []validator.Int64{ + int64validator.Between(0, 15), + }, + }, + "udp_port": schema.Int64Attribute{ + MarkdownDescription: helpers.NewAttributeDescription("vPC Keepalive UDP port.").AddIntegerRangeDescription(1, 65535).String, + Optional: true, + Validators: []validator.Int64{ + int64validator.Between(1, 65535), + }, + }, + "vrf": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("vPC Keepalive VRF.").String, + Optional: true, + }, + }, + } +} + +func (r *VPCKeepaliveResource) 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 *VPCKeepaliveResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + var plan VPCKeepalive + + // 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())) + + // Post object + body := plan.toBody() + _, err := r.clients[plan.Device.ValueString()].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...) +} + +func (r *VPCKeepaliveResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + var state VPCKeepalive + + // 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())) + + queries := []func(*nxos.Req){nxos.Query("rsp-prop-include", "config-only")} + res, err := r.clients[state.Device.ValueString()].GetDn(state.Dn.ValueString(), queries...) + if err != nil { + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve object, got error: %s", err)) + return + } + + state.fromBody(res, false) + + tflog.Debug(ctx, fmt.Sprintf("%s: Read finished successfully", state.Dn.ValueString())) + + diags = resp.State.Set(ctx, &state) + resp.Diagnostics.Append(diags...) +} + +func (r *VPCKeepaliveResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + var plan VPCKeepalive + + // 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())) + + body := plan.toBody() + _, err := r.clients[plan.Device.ValueString()].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 *VPCKeepaliveResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + var state VPCKeepalive + + // 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())) + + res, err := r.clients[state.Device.ValueString()].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 update object, got error: %s", err)) + return + } + } + + tflog.Debug(ctx, fmt.Sprintf("%s: Delete finished successfully", state.Dn.ValueString())) + + resp.State.RemoveResource(ctx) +} + +func (r *VPCKeepaliveResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) +} diff --git a/internal/provider/resource_nxos_vpc_keepalive_test.go b/internal/provider/resource_nxos_vpc_keepalive_test.go new file mode 100644 index 00000000..4b0693a5 --- /dev/null +++ b/internal/provider/resource_nxos_vpc_keepalive_test.go @@ -0,0 +1,113 @@ +// 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 TestAccNxosVPCKeepalive(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccNxosVPCKeepalivePrerequisitesConfig + testAccNxosVPCKeepaliveConfig_all(), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("nxos_vpc_keepalive.test", "destination_ip", "192.168.1.1"), + resource.TestCheckResourceAttr("nxos_vpc_keepalive.test", "flush_timeout", "3"), + resource.TestCheckResourceAttr("nxos_vpc_keepalive.test", "interval", "1000"), + resource.TestCheckResourceAttr("nxos_vpc_keepalive.test", "precedence_type", "0"), + resource.TestCheckResourceAttr("nxos_vpc_keepalive.test", "precedence_value", "6"), + resource.TestCheckResourceAttr("nxos_vpc_keepalive.test", "source_ip", "192.168.1.2"), + resource.TestCheckResourceAttr("nxos_vpc_keepalive.test", "timeout", "5"), + resource.TestCheckResourceAttr("nxos_vpc_keepalive.test", "type_of_service_byte", "0"), + resource.TestCheckResourceAttr("nxos_vpc_keepalive.test", "type_of_service_configuration_type", "0"), + resource.TestCheckResourceAttr("nxos_vpc_keepalive.test", "type_of_service_type", "0"), + resource.TestCheckResourceAttr("nxos_vpc_keepalive.test", "type_of_service_value", "0"), + resource.TestCheckResourceAttr("nxos_vpc_keepalive.test", "udp_port", "1234"), + resource.TestCheckResourceAttr("nxos_vpc_keepalive.test", "vrf", "management"), + ), + }, + { + ResourceName: "nxos_vpc_keepalive.test", + ImportState: true, + ImportStateId: "sys/vpc/inst/dom/keepalive", + }, + }, + }) +} + +const testAccNxosVPCKeepalivePrerequisitesConfig = ` +resource "nxos_rest" "PreReq0" { + dn = "sys/fm/vpc" + class_name = "fmVpc" + delete = false + content = { + adminSt = "enabled" + } +} + +resource "nxos_rest" "PreReq1" { + dn = "sys/vpc/inst" + class_name = "vpcInst" + depends_on = [nxos_rest.PreReq0, ] +} + +resource "nxos_rest" "PreReq2" { + dn = "sys/vpc/inst/dom" + class_name = "vpcDom" + depends_on = [nxos_rest.PreReq1, ] +} + +` + +func testAccNxosVPCKeepaliveConfig_minimum() string { + return ` + resource "nxos_vpc_keepalive" "test" { + destination_ip = "192.168.1.1" + source_ip = "192.168.1.2" + depends_on = [nxos_rest.PreReq0, nxos_rest.PreReq1, nxos_rest.PreReq2, ] + } + ` +} + +func testAccNxosVPCKeepaliveConfig_all() string { + return ` + resource "nxos_vpc_keepalive" "test" { + destination_ip = "192.168.1.1" + flush_timeout = 3 + interval = 1000 + precedence_type = 0 + precedence_value = 6 + source_ip = "192.168.1.2" + timeout = 5 + type_of_service_byte = 0 + type_of_service_configuration_type = 0 + type_of_service_type = 0 + type_of_service_value = 0 + udp_port = 1234 + vrf = "management" + depends_on = [nxos_rest.PreReq0, nxos_rest.PreReq1, nxos_rest.PreReq2, ] + } + ` +} diff --git a/templates/guides/supported_objects.md.tmpl b/templates/guides/supported_objects.md.tmpl index aba62cae..18f0f6c5 100644 --- a/templates/guides/supported_objects.md.tmpl +++ b/templates/guides/supported_objects.md.tmpl @@ -132,6 +132,7 @@ For the following DME objects a corresponding Terraform resource and data source | [vpcDom](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/System/vpc:Dom/) | [nxos_vpc_domain](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/vpc_domain) | [nxos_vpc_domain](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/data-sources/vpc_domain) | | [vpcInst](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/System/vpc:Inst/) | [nxos_vpc_instance](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/vpc_instance) | [nxos_vpc_instance](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/data-sources/vpc_instance) | | [vpcIf](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/System/vpc:If/) | [nxos_vpc_interface](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/vpc_interface) | [nxos_vpc_interface](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/data-sources/vpc_interface) | +| [vpcKeepalive](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/System/vpc:Keepalive/) | [nxos_vpc_keepalive](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/vpc_keepalive) | [nxos_vpc_keepalive](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/data-sources/vpc_keepalive) | | [l3Inst](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Layer%203/l3:Inst/) | [nxos_vrf](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/vrf) | [nxos_vrf](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/data-sources/vrf) | | [rtctrlDomAf](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Routing%20and%20Forwarding/rtctrl:DomAf/) | [nxos_vrf_address_family](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/vrf_address_family) | [nxos_vrf_address_family](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/data-sources/vrf_address_family) | | [rtctrlRttEntry](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Routing%20and%20Forwarding/rtctrl:RttEntry/) | [nxos_vrf_route_target](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/vrf_route_target) | [nxos_vrf_route_target](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/data-sources/vrf_route_target) |