From 6f0d56fa9563b5fc50a2a72f3bc45e89c133f5b2 Mon Sep 17 00:00:00 2001 From: Rafael Muller Date: Tue, 3 Dec 2024 13:38:17 -0500 Subject: [PATCH] Add feature ngmvpn (#277) --- docs/data-sources/feature_ngmvpn.md | 33 +++ docs/guides/supported_objects.md | 1 + docs/resources/feature_ngmvpn.md | 46 ++++ .../nxos_feature_ngmvpn/data-source.tf | 2 + .../resources/nxos_feature_ngmvpn/import.sh | 1 + .../resources/nxos_feature_ngmvpn/resource.tf | 3 + gen/definitions/feature_ngmvpn.yaml | 19 ++ .../data_source_nxos_feature_ngmvpn.go | 108 +++++++++ .../data_source_nxos_feature_ngmvpn_test.go | 52 +++++ .../provider/model_nxos_feature_ngmvpn.go | 66 ++++++ internal/provider/provider.go | 2 + .../provider/resource_nxos_feature_ngmvpn.go | 221 ++++++++++++++++++ .../resource_nxos_feature_ngmvpn_test.go | 62 +++++ templates/guides/supported_objects.md.tmpl | 1 + 14 files changed, 617 insertions(+) create mode 100644 docs/data-sources/feature_ngmvpn.md create mode 100644 docs/resources/feature_ngmvpn.md create mode 100644 examples/data-sources/nxos_feature_ngmvpn/data-source.tf create mode 100644 examples/resources/nxos_feature_ngmvpn/import.sh create mode 100644 examples/resources/nxos_feature_ngmvpn/resource.tf create mode 100644 gen/definitions/feature_ngmvpn.yaml create mode 100644 internal/provider/data_source_nxos_feature_ngmvpn.go create mode 100644 internal/provider/data_source_nxos_feature_ngmvpn_test.go create mode 100644 internal/provider/model_nxos_feature_ngmvpn.go create mode 100644 internal/provider/resource_nxos_feature_ngmvpn.go create mode 100644 internal/provider/resource_nxos_feature_ngmvpn_test.go diff --git a/docs/data-sources/feature_ngmvpn.md b/docs/data-sources/feature_ngmvpn.md new file mode 100644 index 00000000..946faa82 --- /dev/null +++ b/docs/data-sources/feature_ngmvpn.md @@ -0,0 +1,33 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "nxos_feature_ngmvpn Data Source - terraform-provider-nxos" +subcategory: "Feature" +description: |- + This data source can read the Next Generation Multicast VPN Feature. + API Documentation: fmNgmvpn https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Feature%20Management/fm:NgMvpn/ +--- + +# nxos_feature_ngmvpn (Data Source) + +This data source can read the Next Generation Multicast VPN Feature. + +- API Documentation: [fmNgmvpn](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Feature%20Management/fm:NgMvpn/) + +## Example Usage + +```terraform +data "nxos_feature_ngmvpn" "example" { +} +``` + + +## Schema + +### Optional + +- `device` (String) A device name from the provider configuration. + +### Read-Only + +- `admin_state` (String) Administrative state. +- `id` (String) The distinguished name of the object. diff --git a/docs/guides/supported_objects.md b/docs/guides/supported_objects.md index 0f976d6c..ae36e1ab 100644 --- a/docs/guides/supported_objects.md +++ b/docs/guides/supported_objects.md @@ -55,6 +55,7 @@ For the following DME objects a corresponding Terraform resource and data source | [fmLldp](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Feature%20Management/fm:Lldp/) | [nxos_feature_lldp](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/feature_lldp) | [nxos_feature_lldp](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/data-sources/feature_lldp) | | [fmMacsec](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Feature%20Management/fm:Macsec/) | [nxos_feature_macsec](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/feature_macsec) | [nxos_feature_macsec](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/data-sources/feature_macsec) | | [fmNetflow](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Feature%20Management/fm:Netflow/) | [nxos_feature_netflow](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/feature_netflow) | [nxos_feature_netflow](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/data-sources/feature_netflow) | +| [fmNgmvpn](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Feature%20Management/fm:NgMvpn/) | [nxos_feature_ngmvpn](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/feature_ngmvpn) | [nxos_feature_ngmvpn](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/data-sources/feature_ngmvpn) | | [fmNvo](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Feature%20Management/fm:Nvo/) | [nxos_feature_nv_overlay](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/feature_nv_overlay) | [nxos_feature_nv_overlay](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/data-sources/feature_nv_overlay) | | [fmOspf](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Feature%20Management/fm:Ospf/) | [nxos_feature_ospf](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/feature_ospf) | [nxos_feature_ospf](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/data-sources/feature_ospf) | | [fmOspfv3](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Feature%20Management/fm:Ospfv3/) | [nxos_feature_ospfv3](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/feature_ospfv3) | [nxos_feature_ospfv3](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/data-sources/feature_ospfv3) | diff --git a/docs/resources/feature_ngmvpn.md b/docs/resources/feature_ngmvpn.md new file mode 100644 index 00000000..603e27a9 --- /dev/null +++ b/docs/resources/feature_ngmvpn.md @@ -0,0 +1,46 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "nxos_feature_ngmvpn Resource - terraform-provider-nxos" +subcategory: "Feature" +description: |- + This resource can manage the Next Generation Multicast VPN Feature. + API Documentation: fmNgmvpn https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Feature%20Management/fm:NgMvpn/ +--- + +# nxos_feature_ngmvpn (Resource) + +This resource can manage the Next Generation Multicast VPN Feature. + +- API Documentation: [fmNgmvpn](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Feature%20Management/fm:NgMvpn/) + +## Example Usage + +```terraform +resource "nxos_feature_ngmvpn" "example" { + admin_state = "enabled" +} +``` + + +## Schema + +### Required + +- `admin_state` (String) Administrative state. + - Choices: `enabled`, `disabled` + +### Optional + +- `device` (String) A device name from the provider configuration. + +### Read-Only + +- `id` (String) The distinguished name of the object. + +## Import + +Import is supported using the following syntax: + +```shell +terraform import nxos_feature_ngmvpn.example "sys/fm/ngmvpn" +``` diff --git a/examples/data-sources/nxos_feature_ngmvpn/data-source.tf b/examples/data-sources/nxos_feature_ngmvpn/data-source.tf new file mode 100644 index 00000000..5e188731 --- /dev/null +++ b/examples/data-sources/nxos_feature_ngmvpn/data-source.tf @@ -0,0 +1,2 @@ +data "nxos_feature_ngmvpn" "example" { +} diff --git a/examples/resources/nxos_feature_ngmvpn/import.sh b/examples/resources/nxos_feature_ngmvpn/import.sh new file mode 100644 index 00000000..585f16a9 --- /dev/null +++ b/examples/resources/nxos_feature_ngmvpn/import.sh @@ -0,0 +1 @@ +terraform import nxos_feature_ngmvpn.example "sys/fm/ngmvpn" diff --git a/examples/resources/nxos_feature_ngmvpn/resource.tf b/examples/resources/nxos_feature_ngmvpn/resource.tf new file mode 100644 index 00000000..dffa69cc --- /dev/null +++ b/examples/resources/nxos_feature_ngmvpn/resource.tf @@ -0,0 +1,3 @@ +resource "nxos_feature_ngmvpn" "example" { + admin_state = "enabled" +} diff --git a/gen/definitions/feature_ngmvpn.yaml b/gen/definitions/feature_ngmvpn.yaml new file mode 100644 index 00000000..01be48e3 --- /dev/null +++ b/gen/definitions/feature_ngmvpn.yaml @@ -0,0 +1,19 @@ +--- +name: Feature ngMVPN +class_name: fmNgmvpn +dn: sys/fm/ngmvpn +ds_description: This data source can read the Next Generation Multicast VPN Feature. +res_description: This resource can manage the Next Generation Multicast VPN Feature. +doc_path: Feature%20Management/fm:NgMvpn/ +doc_category: Feature +attributes: + - nxos_name: adminSt + tf_name: admin_state + type: String + mandatory: true + description: "Administrative state." + enum_values: + - enabled + - disabled + example: enabled + delete_value: disabled diff --git a/internal/provider/data_source_nxos_feature_ngmvpn.go b/internal/provider/data_source_nxos_feature_ngmvpn.go new file mode 100644 index 00000000..e6338806 --- /dev/null +++ b/internal/provider/data_source_nxos_feature_ngmvpn.go @@ -0,0 +1,108 @@ +// 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 = &FeatureNgMVPNDataSource{} + _ datasource.DataSourceWithConfigure = &FeatureNgMVPNDataSource{} +) + +func NewFeatureNgMVPNDataSource() datasource.DataSource { + return &FeatureNgMVPNDataSource{} +} + +type FeatureNgMVPNDataSource struct { + clients map[string]*nxos.Client +} + +func (d *FeatureNgMVPNDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_feature_ngmvpn" +} + +func (d *FeatureNgMVPNDataSource) 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 Next Generation Multicast VPN Feature.", "fmNgmvpn", "Feature%20Management/fm:NgMvpn/").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, + }, + "admin_state": schema.StringAttribute{ + MarkdownDescription: "Administrative state.", + Computed: true, + }, + }, + } +} + +func (d *FeatureNgMVPNDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, _ *datasource.ConfigureResponse) { + if req.ProviderData == nil { + return + } + + d.clients = req.ProviderData.(map[string]*nxos.Client) +} + +func (d *FeatureNgMVPNDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + var config FeatureNgMVPN + + // 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_feature_ngmvpn_test.go b/internal/provider/data_source_nxos_feature_ngmvpn_test.go new file mode 100644 index 00000000..55022fd1 --- /dev/null +++ b/internal/provider/data_source_nxos_feature_ngmvpn_test.go @@ -0,0 +1,52 @@ +// 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 TestAccDataSourceNxosFeatureNgMVPN(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceNxosFeatureNgMVPNConfig, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("data.nxos_feature_ngmvpn.test", "admin_state", "enabled"), + ), + }, + }, + }) +} + +const testAccDataSourceNxosFeatureNgMVPNConfig = ` + +resource "nxos_feature_ngmvpn" "test" { + admin_state = "enabled" +} + +data "nxos_feature_ngmvpn" "test" { + depends_on = [nxos_feature_ngmvpn.test] +} +` diff --git a/internal/provider/model_nxos_feature_ngmvpn.go b/internal/provider/model_nxos_feature_ngmvpn.go new file mode 100644 index 00000000..47feefec --- /dev/null +++ b/internal/provider/model_nxos_feature_ngmvpn.go @@ -0,0 +1,66 @@ +// 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 ( + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/netascode/go-nxos" + "github.com/tidwall/gjson" + "github.com/tidwall/sjson" +) + +type FeatureNgMVPN struct { + Device types.String `tfsdk:"device"` + Dn types.String `tfsdk:"id"` + AdminState types.String `tfsdk:"admin_state"` +} + +func (data FeatureNgMVPN) getDn() string { + return "sys/fm/ngmvpn" +} + +func (data FeatureNgMVPN) getClassName() string { + return "fmNgmvpn" +} + +func (data FeatureNgMVPN) toBody() nxos.Body { + body := "" + body, _ = sjson.Set(body, data.getClassName()+".attributes", map[string]interface{}{}) + if (!data.AdminState.IsUnknown() && !data.AdminState.IsNull()) || true { + body, _ = sjson.Set(body, data.getClassName()+".attributes."+"adminSt", data.AdminState.ValueString()) + } + + return nxos.Body{body} +} + +func (data *FeatureNgMVPN) fromBody(res gjson.Result, all bool) { + if !data.AdminState.IsNull() || all { + data.AdminState = types.StringValue(res.Get(data.getClassName() + ".attributes.adminSt").String()) + } else { + data.AdminState = types.StringNull() + } +} + +func (data FeatureNgMVPN) toDeleteBody() nxos.Body { + body := "" + body, _ = sjson.Set(body, data.getClassName()+".attributes."+"adminSt", "disabled") + + return nxos.Body{body} +} diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 4d69bcab..3fd8c84d 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -316,6 +316,7 @@ func (p *NxosProvider) Resources(ctx context.Context) []func() resource.Resource NewFeatureLLDPResource, NewFeatureMACsecResource, NewFeatureNetflowResource, + NewFeatureNgMVPNResource, NewFeatureNVOverlayResource, NewFeatureOSPFResource, NewFeatureOSPFv3Resource, @@ -453,6 +454,7 @@ func (p *NxosProvider) DataSources(ctx context.Context) []func() datasource.Data NewFeatureLLDPDataSource, NewFeatureMACsecDataSource, NewFeatureNetflowDataSource, + NewFeatureNgMVPNDataSource, NewFeatureNVOverlayDataSource, NewFeatureOSPFDataSource, NewFeatureOSPFv3DataSource, diff --git a/internal/provider/resource_nxos_feature_ngmvpn.go b/internal/provider/resource_nxos_feature_ngmvpn.go new file mode 100644 index 00000000..386691df --- /dev/null +++ b/internal/provider/resource_nxos_feature_ngmvpn.go @@ -0,0 +1,221 @@ +// 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/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 = &FeatureNgMVPNResource{} +var _ resource.ResourceWithImportState = &FeatureNgMVPNResource{} + +func NewFeatureNgMVPNResource() resource.Resource { + return &FeatureNgMVPNResource{} +} + +type FeatureNgMVPNResource struct { + clients map[string]*nxos.Client +} + +func (r *FeatureNgMVPNResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_feature_ngmvpn" +} + +func (r *FeatureNgMVPNResource) 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 Next Generation Multicast VPN Feature.", "fmNgmvpn", "Feature%20Management/fm:NgMvpn/").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(), + }, + }, + "admin_state": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Administrative state.").AddStringEnumDescription("enabled", "disabled").String, + Required: true, + Validators: []validator.String{ + stringvalidator.OneOf("enabled", "disabled"), + }, + }, + }, + } +} + +func (r *FeatureNgMVPNResource) 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 *FeatureNgMVPNResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + var plan FeatureNgMVPN + + // 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...) + + helpers.SetFlagImporting(ctx, false, resp.Private, &resp.Diagnostics) +} + +func (r *FeatureNgMVPNResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + var state FeatureNgMVPN + + // 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 + } + + imp, diags := helpers.IsFlagImporting(ctx, req) + if resp.Diagnostics.Append(diags...); resp.Diagnostics.HasError() { + return + } + state.fromBody(res, imp) + + 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 *FeatureNgMVPNResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + var plan FeatureNgMVPN + + // 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 *FeatureNgMVPNResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + var state FeatureNgMVPN + + // 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())) + + body := state.toDeleteBody() + + if len(body.Str) > 0 { + _, err := r.clients[state.Device.ValueString()].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 := 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 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 *FeatureNgMVPNResource) 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_feature_ngmvpn_test.go b/internal/provider/resource_nxos_feature_ngmvpn_test.go new file mode 100644 index 00000000..14ea6e2f --- /dev/null +++ b/internal/provider/resource_nxos_feature_ngmvpn_test.go @@ -0,0 +1,62 @@ +// 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 TestAccNxosFeatureNgMVPN(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccNxosFeatureNgMVPNConfig_all(), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("nxos_feature_ngmvpn.test", "admin_state", "enabled"), + ), + }, + { + ResourceName: "nxos_feature_ngmvpn.test", + ImportState: true, + ImportStateId: "sys/fm/ngmvpn", + }, + }, + }) +} + +func testAccNxosFeatureNgMVPNConfig_minimum() string { + return ` + resource "nxos_feature_ngmvpn" "test" { + admin_state = "enabled" + } + ` +} + +func testAccNxosFeatureNgMVPNConfig_all() string { + return ` + resource "nxos_feature_ngmvpn" "test" { + admin_state = "enabled" + } + ` +} diff --git a/templates/guides/supported_objects.md.tmpl b/templates/guides/supported_objects.md.tmpl index 0f976d6c..ae36e1ab 100644 --- a/templates/guides/supported_objects.md.tmpl +++ b/templates/guides/supported_objects.md.tmpl @@ -55,6 +55,7 @@ For the following DME objects a corresponding Terraform resource and data source | [fmLldp](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Feature%20Management/fm:Lldp/) | [nxos_feature_lldp](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/feature_lldp) | [nxos_feature_lldp](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/data-sources/feature_lldp) | | [fmMacsec](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Feature%20Management/fm:Macsec/) | [nxos_feature_macsec](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/feature_macsec) | [nxos_feature_macsec](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/data-sources/feature_macsec) | | [fmNetflow](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Feature%20Management/fm:Netflow/) | [nxos_feature_netflow](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/feature_netflow) | [nxos_feature_netflow](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/data-sources/feature_netflow) | +| [fmNgmvpn](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Feature%20Management/fm:NgMvpn/) | [nxos_feature_ngmvpn](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/feature_ngmvpn) | [nxos_feature_ngmvpn](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/data-sources/feature_ngmvpn) | | [fmNvo](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Feature%20Management/fm:Nvo/) | [nxos_feature_nv_overlay](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/feature_nv_overlay) | [nxos_feature_nv_overlay](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/data-sources/feature_nv_overlay) | | [fmOspf](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Feature%20Management/fm:Ospf/) | [nxos_feature_ospf](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/feature_ospf) | [nxos_feature_ospf](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/data-sources/feature_ospf) | | [fmOspfv3](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Feature%20Management/fm:Ospfv3/) | [nxos_feature_ospfv3](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/feature_ospfv3) | [nxos_feature_ospfv3](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/data-sources/feature_ospfv3) |