diff --git a/docs/data-sources/feature_ngoam.md b/docs/data-sources/feature_ngoam.md new file mode 100644 index 00000000..3fc76054 --- /dev/null +++ b/docs/data-sources/feature_ngoam.md @@ -0,0 +1,33 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "nxos_feature_ngoam Data Source - terraform-provider-nxos" +subcategory: "Feature" +description: |- + This data source can read the VXLAN operations, administration, and maintenance feature. + API Documentation: fmNgoam https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Feature%20Management/fm:Ngoam/ +--- + +# nxos_feature_ngoam (Data Source) + +This data source can read the VXLAN operations, administration, and maintenance feature. + +- API Documentation: [fmNgoam](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Feature%20Management/fm:Ngoam/) + +## Example Usage + +```terraform +data "nxos_feature_ngoam" "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 ae36e1ab..7bf2e3aa 100644 --- a/docs/guides/supported_objects.md +++ b/docs/guides/supported_objects.md @@ -56,6 +56,7 @@ For the following DME objects a corresponding Terraform resource and data source | [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) | +| [fmNgoam](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Feature%20Management/fm:Ngoam/) | [nxos_feature_ngoam](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/feature_ngoam) | [nxos_feature_ngoam](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/data-sources/feature_ngoam) | | [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_ngoam.md b/docs/resources/feature_ngoam.md new file mode 100644 index 00000000..2537cc30 --- /dev/null +++ b/docs/resources/feature_ngoam.md @@ -0,0 +1,46 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "nxos_feature_ngoam Resource - terraform-provider-nxos" +subcategory: "Feature" +description: |- + This resource can manage the VXLAN operations, administration, and maintenance feature. + API Documentation: fmNgoam https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Feature%20Management/fm:Ngoam/ +--- + +# nxos_feature_ngoam (Resource) + +This resource can manage the VXLAN operations, administration, and maintenance feature. + +- API Documentation: [fmNgoam](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Feature%20Management/fm:Ngoam/) + +## Example Usage + +```terraform +resource "nxos_feature_ngoam" "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_ngoam.example "sys/fm/ngoam" +``` diff --git a/examples/data-sources/nxos_feature_ngoam/data-source.tf b/examples/data-sources/nxos_feature_ngoam/data-source.tf new file mode 100644 index 00000000..48a1ed21 --- /dev/null +++ b/examples/data-sources/nxos_feature_ngoam/data-source.tf @@ -0,0 +1,2 @@ +data "nxos_feature_ngoam" "example" { +} diff --git a/examples/resources/nxos_feature_ngoam/import.sh b/examples/resources/nxos_feature_ngoam/import.sh new file mode 100644 index 00000000..ee53695a --- /dev/null +++ b/examples/resources/nxos_feature_ngoam/import.sh @@ -0,0 +1 @@ +terraform import nxos_feature_ngoam.example "sys/fm/ngoam" diff --git a/examples/resources/nxos_feature_ngoam/resource.tf b/examples/resources/nxos_feature_ngoam/resource.tf new file mode 100644 index 00000000..e62f31e4 --- /dev/null +++ b/examples/resources/nxos_feature_ngoam/resource.tf @@ -0,0 +1,3 @@ +resource "nxos_feature_ngoam" "example" { + admin_state = "enabled" +} diff --git a/gen/definitions/feature_ngoam.yaml b/gen/definitions/feature_ngoam.yaml new file mode 100644 index 00000000..60640e1f --- /dev/null +++ b/gen/definitions/feature_ngoam.yaml @@ -0,0 +1,19 @@ +--- +name: Feature NGOAM +class_name: fmNgoam +dn: sys/fm/ngoam +ds_description: This data source can read the VXLAN operations, administration, and maintenance feature. +res_description: This resource can manage the VXLAN operations, administration, and maintenance feature. +doc_path: Feature%20Management/fm:Ngoam/ +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_ngoam.go b/internal/provider/data_source_nxos_feature_ngoam.go new file mode 100644 index 00000000..c9e8ab2a --- /dev/null +++ b/internal/provider/data_source_nxos_feature_ngoam.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 = &FeatureNGOAMDataSource{} + _ datasource.DataSourceWithConfigure = &FeatureNGOAMDataSource{} +) + +func NewFeatureNGOAMDataSource() datasource.DataSource { + return &FeatureNGOAMDataSource{} +} + +type FeatureNGOAMDataSource struct { + clients map[string]*nxos.Client +} + +func (d *FeatureNGOAMDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_feature_ngoam" +} + +func (d *FeatureNGOAMDataSource) 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 VXLAN operations, administration, and maintenance feature.", "fmNgoam", "Feature%20Management/fm:Ngoam/").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 *FeatureNGOAMDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, _ *datasource.ConfigureResponse) { + if req.ProviderData == nil { + return + } + + d.clients = req.ProviderData.(map[string]*nxos.Client) +} + +func (d *FeatureNGOAMDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + var config FeatureNGOAM + + // 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_ngoam_test.go b/internal/provider/data_source_nxos_feature_ngoam_test.go new file mode 100644 index 00000000..56364fbc --- /dev/null +++ b/internal/provider/data_source_nxos_feature_ngoam_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 TestAccDataSourceNxosFeatureNGOAM(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceNxosFeatureNGOAMConfig, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("data.nxos_feature_ngoam.test", "admin_state", "enabled"), + ), + }, + }, + }) +} + +const testAccDataSourceNxosFeatureNGOAMConfig = ` + +resource "nxos_feature_ngoam" "test" { + admin_state = "enabled" +} + +data "nxos_feature_ngoam" "test" { + depends_on = [nxos_feature_ngoam.test] +} +` diff --git a/internal/provider/model_nxos_feature_ngoam.go b/internal/provider/model_nxos_feature_ngoam.go new file mode 100644 index 00000000..968c7bb4 --- /dev/null +++ b/internal/provider/model_nxos_feature_ngoam.go @@ -0,0 +1,69 @@ +// 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 FeatureNGOAM struct { + Device types.String `tfsdk:"device"` + Dn types.String `tfsdk:"id"` + AdminState types.String `tfsdk:"admin_state"` +} + +func (data FeatureNGOAM) getDn() string { + return "sys/fm/ngoam" +} + +func (data FeatureNGOAM) getClassName() string { + return "fmNgoam" +} + +func (data FeatureNGOAM) 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.AdminState.IsUnknown() && !data.AdminState.IsNull()) || true { + body, _ = sjson.Set(body, data.getClassName()+".attributes."+"adminSt", data.AdminState.ValueString()) + } + + return nxos.Body{body} +} + +func (data *FeatureNGOAM) 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 FeatureNGOAM) 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 3fd8c84d..ff5f60a8 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -317,6 +317,7 @@ func (p *NxosProvider) Resources(ctx context.Context) []func() resource.Resource NewFeatureMACsecResource, NewFeatureNetflowResource, NewFeatureNgMVPNResource, + NewFeatureNGOAMResource, NewFeatureNVOverlayResource, NewFeatureOSPFResource, NewFeatureOSPFv3Resource, @@ -455,6 +456,7 @@ func (p *NxosProvider) DataSources(ctx context.Context) []func() datasource.Data NewFeatureMACsecDataSource, NewFeatureNetflowDataSource, NewFeatureNgMVPNDataSource, + NewFeatureNGOAMDataSource, NewFeatureNVOverlayDataSource, NewFeatureOSPFDataSource, NewFeatureOSPFv3DataSource, diff --git a/internal/provider/resource_nxos_feature_ngoam.go b/internal/provider/resource_nxos_feature_ngoam.go new file mode 100644 index 00000000..db4c1df7 --- /dev/null +++ b/internal/provider/resource_nxos_feature_ngoam.go @@ -0,0 +1,222 @@ +// 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 = &FeatureNGOAMResource{} +var _ resource.ResourceWithImportState = &FeatureNGOAMResource{} + +func NewFeatureNGOAMResource() resource.Resource { + return &FeatureNGOAMResource{} +} + +type FeatureNGOAMResource struct { + clients map[string]*nxos.Client +} + +func (r *FeatureNGOAMResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_feature_ngoam" +} + +func (r *FeatureNGOAMResource) 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 VXLAN operations, administration, and maintenance feature.", "fmNgoam", "Feature%20Management/fm:Ngoam/").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 *FeatureNGOAMResource) 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 *FeatureNGOAMResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + var plan FeatureNGOAM + + // 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(false) + _, 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 *FeatureNGOAMResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + var state FeatureNGOAM + + // 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 *FeatureNGOAMResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + var plan FeatureNGOAM + + // 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(false) + + _, 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 *FeatureNGOAMResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + var state FeatureNGOAM + + // 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 *FeatureNGOAMResource) 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_ngoam_test.go b/internal/provider/resource_nxos_feature_ngoam_test.go new file mode 100644 index 00000000..e40089eb --- /dev/null +++ b/internal/provider/resource_nxos_feature_ngoam_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 TestAccNxosFeatureNGOAM(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccNxosFeatureNGOAMConfig_all(), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("nxos_feature_ngoam.test", "admin_state", "enabled"), + ), + }, + { + ResourceName: "nxos_feature_ngoam.test", + ImportState: true, + ImportStateId: "sys/fm/ngoam", + }, + }, + }) +} + +func testAccNxosFeatureNGOAMConfig_minimum() string { + return ` + resource "nxos_feature_ngoam" "test" { + admin_state = "enabled" + } + ` +} + +func testAccNxosFeatureNGOAMConfig_all() string { + return ` + resource "nxos_feature_ngoam" "test" { + admin_state = "enabled" + } + ` +} diff --git a/templates/guides/supported_objects.md.tmpl b/templates/guides/supported_objects.md.tmpl index ae36e1ab..7bf2e3aa 100644 --- a/templates/guides/supported_objects.md.tmpl +++ b/templates/guides/supported_objects.md.tmpl @@ -56,6 +56,7 @@ For the following DME objects a corresponding Terraform resource and data source | [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) | +| [fmNgoam](https://pubhub.devnetcloud.com/media/dme-docs-10-2-2/docs/Feature%20Management/fm:Ngoam/) | [nxos_feature_ngoam](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/resources/feature_ngoam) | [nxos_feature_ngoam](https://registry.terraform.io/providers/CiscoDevNet/nxos/latest/docs/data-sources/feature_ngoam) | | [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) |