diff --git a/docs/resources/device.md b/docs/resources/device.md index 1de6f26..920a54e 100644 --- a/docs/resources/device.md +++ b/docs/resources/device.md @@ -19,7 +19,7 @@ resource "nso_device" "example" { port = 22 authgroup = "default" admin_state = "locked" - cli_ned_id = "cisco-ios-cli-3.0:cisco-ios-cli-3.0" + cli_ned_id = "cisco-ios-cli-3.8:cisco-ios-cli-3.8" } ``` @@ -37,8 +37,6 @@ resource "nso_device" "example" { - Choices: `locked`, `unlocked`, `southbound-locked`, `config-locked`, `call-home` - `authgroup` (String) The authentication credentials used when connecting to this managed device. - `cli_ned_id` (String) CLI NED ID. -- `delete_mode` (String) Configure behavior when deleting/destroying the resource. Either delete the entire object (YANG container) being managed, or only delete the individual resource attributes configured explicitly and leave everything else as-is. Default value is `all`. - - Choices: `all`, `attributes` - `instance` (String) An instance name from the provider configuration. - `netconf_net_id` (String) NETCONF NED ID. - `port` (Number) Port for the management interface on the device. If this leaf is not configured, NCS will use a default value based on the type of device. For example, a NETCONF device uses port 830, a CLI device over SSH uses port 22, and an SNMP device uses port 161. diff --git a/docs/resources/device_config.md b/docs/resources/device_config.md index 694f16a..8233754 100644 --- a/docs/resources/device_config.md +++ b/docs/resources/device_config.md @@ -47,7 +47,6 @@ resource "nso_device_config" "access_list" { ### Required - `device` (String) An NSO device name. -- `path` (String) A RESTCONF path. ### Optional @@ -55,6 +54,7 @@ resource "nso_device_config" "access_list" { - `delete` (Boolean) Delete object during destroy operation. Default value is `true`. - `instance` (String) An instance name from the provider configuration. - `lists` (Attributes List) YANG lists. (see [below for nested schema](#nestedatt--lists)) +- `path` (String) A RESTCONF path. ### Read-Only diff --git a/docs/resources/device_group.md b/docs/resources/device_group.md index 35ab069..66d2f9b 100644 --- a/docs/resources/device_group.md +++ b/docs/resources/device_group.md @@ -15,7 +15,7 @@ This resource can manage the Device Group configuration. ```terraform resource "nso_device_group" "example" { name = "test-group1" - device_names = ["c1"] + device_names = ["ce0"] } ``` @@ -28,8 +28,6 @@ resource "nso_device_group" "example" { ### Optional -- `delete_mode` (String) Configure behavior when deleting/destroying the resource. Either delete the entire object (YANG container) being managed, or only delete the individual resource attributes configured explicitly and leave everything else as-is. Default value is `all`. - - Choices: `all`, `attributes` - `device_groups` (List of String) A list of device groups. - `device_names` (List of String) A list of device names. - `instance` (String) An instance name from the provider configuration. diff --git a/examples/resources/nso_device/resource.tf b/examples/resources/nso_device/resource.tf index 8ceb9c0..2ced5b6 100644 --- a/examples/resources/nso_device/resource.tf +++ b/examples/resources/nso_device/resource.tf @@ -4,5 +4,5 @@ resource "nso_device" "example" { port = 22 authgroup = "default" admin_state = "locked" - cli_ned_id = "cisco-ios-cli-3.0:cisco-ios-cli-3.0" + cli_ned_id = "cisco-ios-cli-3.8:cisco-ios-cli-3.8" } diff --git a/examples/resources/nso_device_group/resource.tf b/examples/resources/nso_device_group/resource.tf index 95fece9..8a36614 100644 --- a/examples/resources/nso_device_group/resource.tf +++ b/examples/resources/nso_device_group/resource.tf @@ -1,4 +1,4 @@ resource "nso_device_group" "example" { name = "test-group1" - device_names = ["c1"] + device_names = ["ce0"] } diff --git a/gen/definitions/device.yaml b/gen/definitions/device.yaml index ad5ab21..719b089 100644 --- a/gen/definitions/device.yaml +++ b/gen/definitions/device.yaml @@ -4,6 +4,7 @@ path: tailf-ncs:devices/device=%v res_description: This resource can manage the Device configuration. ds_description: This data source can read the Device configuration. no_augment_config: true +no_delete_attributes: true doc_category: Device attributes: - yang_name: name @@ -54,4 +55,4 @@ attributes: tf_name: cli_ned_id type: String description: CLI NED ID. - example: cisco-ios-cli-3.0:cisco-ios-cli-3.0 + example: cisco-ios-cli-3.8:cisco-ios-cli-3.8 diff --git a/gen/definitions/device_group.yaml b/gen/definitions/device_group.yaml index fd0b70f..cf9dc40 100644 --- a/gen/definitions/device_group.yaml +++ b/gen/definitions/device_group.yaml @@ -4,6 +4,7 @@ path: tailf-ncs:devices/device-group=%v res_description: This resource can manage the Device Group configuration. ds_description: This data source can read the Device Group configuration. no_augment_config: true +no_delete_attributes: true doc_category: Device attributes: - yang_name: name @@ -16,7 +17,7 @@ attributes: tf_name: device_names type: StringList description: A list of device names. - example: c1 + example: ce0 - yang_name: device-group tf_name: device_groups type: StringList diff --git a/internal/provider/data_source_nso_device_config.go b/internal/provider/data_source_nso_device_config.go index fcea3d5..00e9f70 100644 --- a/internal/provider/data_source_nso_device_config.go +++ b/internal/provider/data_source_nso_device_config.go @@ -86,9 +86,9 @@ func (d *DeviceConfigDataSource) Read(ctx context.Context, req datasource.ReadRe return } - path := "tailf-ncs:devices/device=" + config.Instance.ValueString() + "/config" + path := "tailf-ncs:devices/device=" + config.Device.ValueString() + "/config" if config.Path.ValueString() != "" { - path = "tailf-ncs:devices/device=" + config.Instance.ValueString() + "/config/" + config.Path.ValueString() + path = "tailf-ncs:devices/device=" + config.Device.ValueString() + "/config/" + config.Path.ValueString() } tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Read", path)) diff --git a/internal/provider/data_source_nso_device_config_test.go b/internal/provider/data_source_nso_device_config_test.go index 88573fd..4df699c 100644 --- a/internal/provider/data_source_nso_device_config_test.go +++ b/internal/provider/data_source_nso_device_config_test.go @@ -14,7 +14,7 @@ func TestAccDataSourceNsoDeviceConfig(t *testing.T) { { Config: testAccDataSourceNsoDeviceConfigConfig, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("data.nso_device_config.test", "id", "tailf-ncs:devices/device=c1/config"), + resource.TestCheckResourceAttr("data.nso_device_config.test", "id", "tailf-ncs:devices/device=ce0/config"), resource.TestCheckResourceAttr("data.nso_device_config.test", "attributes.tailf-ned-cisco-ios:hostname", "R1"), ), }, @@ -24,14 +24,14 @@ func TestAccDataSourceNsoDeviceConfig(t *testing.T) { const testAccDataSourceNsoDeviceConfigConfig = ` resource "nso_device_config" "test" { - device = "c1" + device = "ce0" attributes = { "tailf-ned-cisco-ios:hostname" = "R1" } } data "nso_device_config" "test" { - device = "c1" + device = "ce0" depends_on = [nso_device_config.test] } ` diff --git a/internal/provider/data_source_nso_device_group_test.go b/internal/provider/data_source_nso_device_group_test.go index a4a4862..76236c1 100644 --- a/internal/provider/data_source_nso_device_group_test.go +++ b/internal/provider/data_source_nso_device_group_test.go @@ -16,7 +16,7 @@ func TestAccDataSourceNsoDeviceGroup(t *testing.T) { { Config: testAccDataSourceNsoDeviceGroupConfig, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("data.nso_device_group.test", "device_names.0", "c1"), + resource.TestCheckResourceAttr("data.nso_device_group.test", "device_names.0", "ce0"), ), }, }, @@ -26,9 +26,8 @@ func TestAccDataSourceNsoDeviceGroup(t *testing.T) { const testAccDataSourceNsoDeviceGroupConfig = ` resource "nso_device_group" "test" { - delete_mode = "attributes" name = "test-group1" - device_names = ["c1"] + device_names = ["ce0"] } data "nso_device_group" "test" { diff --git a/internal/provider/data_source_nso_device_test.go b/internal/provider/data_source_nso_device_test.go index 4611157..7f31f98 100644 --- a/internal/provider/data_source_nso_device_test.go +++ b/internal/provider/data_source_nso_device_test.go @@ -20,7 +20,7 @@ func TestAccDataSourceNsoDevice(t *testing.T) { resource.TestCheckResourceAttr("data.nso_device.test", "port", "22"), resource.TestCheckResourceAttr("data.nso_device.test", "authgroup", "default"), resource.TestCheckResourceAttr("data.nso_device.test", "admin_state", "locked"), - resource.TestCheckResourceAttr("data.nso_device.test", "cli_ned_id", "cisco-ios-cli-3.0:cisco-ios-cli-3.0"), + resource.TestCheckResourceAttr("data.nso_device.test", "cli_ned_id", "cisco-ios-cli-3.8:cisco-ios-cli-3.8"), ), }, }, @@ -30,13 +30,12 @@ func TestAccDataSourceNsoDevice(t *testing.T) { const testAccDataSourceNsoDeviceConfig = ` resource "nso_device" "test" { - delete_mode = "attributes" name = "test-device01" address = "10.1.1.1" port = 22 authgroup = "default" admin_state = "locked" - cli_ned_id = "cisco-ios-cli-3.0:cisco-ios-cli-3.0" + cli_ned_id = "cisco-ios-cli-3.8:cisco-ios-cli-3.8" } data "nso_device" "test" { diff --git a/internal/provider/model_nso_device.go b/internal/provider/model_nso_device.go index e6290d6..46877f4 100644 --- a/internal/provider/model_nso_device.go +++ b/internal/provider/model_nso_device.go @@ -18,7 +18,6 @@ import ( type Device struct { Instance types.String `tfsdk:"instance"` Id types.String `tfsdk:"id"` - DeleteMode types.String `tfsdk:"delete_mode"` Name types.String `tfsdk:"name"` Address types.String `tfsdk:"address"` Port types.Int64 `tfsdk:"port"` diff --git a/internal/provider/model_nso_device_group.go b/internal/provider/model_nso_device_group.go index c09adcf..cf4cc3a 100644 --- a/internal/provider/model_nso_device_group.go +++ b/internal/provider/model_nso_device_group.go @@ -17,7 +17,6 @@ import ( type DeviceGroup struct { Instance types.String `tfsdk:"instance"` Id types.String `tfsdk:"id"` - DeleteMode types.String `tfsdk:"delete_mode"` Name types.String `tfsdk:"name"` DeviceNames types.List `tfsdk:"device_names"` DeviceGroups types.List `tfsdk:"device_groups"` diff --git a/internal/provider/resource_nso_device.go b/internal/provider/resource_nso_device.go index dfe2574..6b05318 100644 --- a/internal/provider/resource_nso_device.go +++ b/internal/provider/resource_nso_device.go @@ -49,13 +49,6 @@ func (r *DeviceResource) Schema(ctx context.Context, req resource.SchemaRequest, stringplanmodifier.UseStateForUnknown(), }, }, - "delete_mode": schema.StringAttribute{ - MarkdownDescription: helpers.NewAttributeDescription("Configure behavior when deleting/destroying the resource. Either delete the entire object (YANG container) being managed, or only delete the individual resource attributes configured explicitly and leave everything else as-is. Default value is `all`.").AddStringEnumDescription("all", "attributes").String, - Optional: true, - Validators: []validator.String{ - stringvalidator.OneOf("all", "attributes"), - }, - }, "name": schema.StringAttribute{ MarkdownDescription: helpers.NewAttributeDescription("A string uniquely identifying the managed device.").String, Required: true, @@ -292,11 +285,6 @@ func (r *DeviceResource) Delete(ctx context.Context, req resource.DeleteRequest, tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Delete", state.Id.ValueString())) deleteMode := "all" - if state.DeleteMode.ValueString() == "all" { - deleteMode = "all" - } else if state.DeleteMode.ValueString() == "attributes" { - deleteMode = "attributes" - } if deleteMode == "all" { res, err := r.clients[state.Instance.ValueString()].DeleteData(state.Id.ValueString()) diff --git a/internal/provider/resource_nso_device_config.go b/internal/provider/resource_nso_device_config.go index 270b6c7..ccf2275 100644 --- a/internal/provider/resource_nso_device_config.go +++ b/internal/provider/resource_nso_device_config.go @@ -57,7 +57,7 @@ func (r *DeviceConfigResource) Schema(ctx context.Context, req resource.SchemaRe }, "path": schema.StringAttribute{ MarkdownDescription: "A RESTCONF path.", - Required: true, + Optional: true, PlanModifiers: []planmodifier.String{ stringplanmodifier.RequiresReplace(), }, @@ -139,7 +139,7 @@ func (r *DeviceConfigResource) Create(ctx context.Context, req resource.CreateRe return } - plan.Id = plan.Path + plan.Id = types.StringValue(plan.getPath()) if plan.Attributes.IsUnknown() { plan.Attributes = types.MapNull(types.StringType) diff --git a/internal/provider/resource_nso_device_config_test.go b/internal/provider/resource_nso_device_config_test.go index 8f3c52e..2f172b5 100644 --- a/internal/provider/resource_nso_device_config_test.go +++ b/internal/provider/resource_nso_device_config_test.go @@ -15,20 +15,20 @@ func TestAccNsoDeviceConfig(t *testing.T) { { Config: testAccNsoDeviceConfigConfig_empty(), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("nso_device_config.test", "id", "tailf-ncs:devices/device=c1/config"), + resource.TestCheckResourceAttr("nso_device_config.test", "id", "tailf-ncs:devices/device=ce0/config"), ), }, { Config: testAccNsoDeviceConfigConfig_hostname("R1"), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("nso_device_config.test", "id", "tailf-ncs:devices/device=c1/config"), + resource.TestCheckResourceAttr("nso_device_config.test", "id", "tailf-ncs:devices/device=ce0/config"), resource.TestCheckResourceAttr("nso_device_config.test", "attributes.tailf-ned-cisco-ios:hostname", "R1"), ), }, { ResourceName: "nso_device_config.test", ImportState: true, - ImportStateId: "tailf-ncs:devices/device=c1/config", + ImportStateId: "tailf-ncs:devices/device=ce0/config", }, { Config: testAccNsoDeviceConfigConfig_hostname("R2"), @@ -39,8 +39,8 @@ func TestAccNsoDeviceConfig(t *testing.T) { { Config: testAccNsoDeviceConfigConfig_nested(), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("nso_device_config.nested", "lists.0.name", "rule"), - resource.TestCheckResourceAttr("nso_device_config.nested", "lists.0.items.0.seq", "10"), + resource.TestCheckResourceAttr("nso_device_config.nested", "lists.0.name", "std-access-list-rule"), + resource.TestCheckResourceAttr("nso_device_config.nested", "lists.0.items.0.rule", "permit ip any"), ), }, }, @@ -50,7 +50,7 @@ func TestAccNsoDeviceConfig(t *testing.T) { func testAccNsoDeviceConfigConfig_empty() string { return ` resource "nso_device_config" "test" { - device = "c1" + device = "ce0" } ` } @@ -58,7 +58,7 @@ func testAccNsoDeviceConfigConfig_empty() string { func testAccNsoDeviceConfigConfig_hostname(hostname string) string { return fmt.Sprintf(` resource "nso_device_config" "test" { - device = "c1" + device = "ce0" attributes = { "tailf-ned-cisco-ios:hostname" = "%s" } @@ -69,18 +69,17 @@ func testAccNsoDeviceConfigConfig_hostname(hostname string) string { func testAccNsoDeviceConfigConfig_nested() string { return ` resource "nso_device_config" "nested" { - device = "c1" - path = "tailf-ned-cisco-ios:access-list/access-list=1" + device = "ce0" + path = "tailf-ned-cisco-ios:access-list/access-list-standard-range=1" attributes = { - id = 1 + listnumber = 1 } lists = [ { - name = "rule" - key = "seq" + name = "std-access-list-rule" + key = "rule" items = [ { - seq = 10 rule = "permit ip any" } ] diff --git a/internal/provider/resource_nso_device_group.go b/internal/provider/resource_nso_device_group.go index 40bab35..6de5ba6 100644 --- a/internal/provider/resource_nso_device_group.go +++ b/internal/provider/resource_nso_device_group.go @@ -7,13 +7,11 @@ import ( "fmt" "github.com/CiscoDevNet/terraform-provider-nso/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-restconf" @@ -48,13 +46,6 @@ func (r *DeviceGroupResource) Schema(ctx context.Context, req resource.SchemaReq stringplanmodifier.UseStateForUnknown(), }, }, - "delete_mode": schema.StringAttribute{ - MarkdownDescription: helpers.NewAttributeDescription("Configure behavior when deleting/destroying the resource. Either delete the entire object (YANG container) being managed, or only delete the individual resource attributes configured explicitly and leave everything else as-is. Default value is `all`.").AddStringEnumDescription("all", "attributes").String, - Optional: true, - Validators: []validator.String{ - stringvalidator.OneOf("all", "attributes"), - }, - }, "name": schema.StringAttribute{ MarkdownDescription: helpers.NewAttributeDescription("Device group name.").String, Required: true, @@ -271,11 +262,6 @@ func (r *DeviceGroupResource) Delete(ctx context.Context, req resource.DeleteReq tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Delete", state.Id.ValueString())) deleteMode := "all" - if state.DeleteMode.ValueString() == "all" { - deleteMode = "all" - } else if state.DeleteMode.ValueString() == "attributes" { - deleteMode = "attributes" - } if deleteMode == "all" { res, err := r.clients[state.Instance.ValueString()].DeleteData(state.Id.ValueString()) diff --git a/internal/provider/resource_nso_device_group_test.go b/internal/provider/resource_nso_device_group_test.go index 628949b..d96b31f 100644 --- a/internal/provider/resource_nso_device_group_test.go +++ b/internal/provider/resource_nso_device_group_test.go @@ -17,7 +17,7 @@ func TestAccNsoDeviceGroup(t *testing.T) { Config: testAccNsoDeviceGroupConfig_all(), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("nso_device_group.test", "name", "test-group1"), - resource.TestCheckResourceAttr("nso_device_group.test", "device_names.0", "c1"), + resource.TestCheckResourceAttr("nso_device_group.test", "device_names.0", "ce0"), ), }, { @@ -41,7 +41,7 @@ func testAccNsoDeviceGroupConfig_all() string { return ` resource "nso_device_group" "test" { name = "test-group1" - device_names = ["c1"] + device_names = ["ce0"] } ` } diff --git a/internal/provider/resource_nso_device_test.go b/internal/provider/resource_nso_device_test.go index ddb6e58..d1ce875 100644 --- a/internal/provider/resource_nso_device_test.go +++ b/internal/provider/resource_nso_device_test.go @@ -21,7 +21,7 @@ func TestAccNsoDevice(t *testing.T) { resource.TestCheckResourceAttr("nso_device.test", "port", "22"), resource.TestCheckResourceAttr("nso_device.test", "authgroup", "default"), resource.TestCheckResourceAttr("nso_device.test", "admin_state", "locked"), - resource.TestCheckResourceAttr("nso_device.test", "cli_ned_id", "cisco-ios-cli-3.0:cisco-ios-cli-3.0"), + resource.TestCheckResourceAttr("nso_device.test", "cli_ned_id", "cisco-ios-cli-3.8:cisco-ios-cli-3.8"), ), }, { @@ -49,7 +49,7 @@ func testAccNsoDeviceConfig_all() string { port = 22 authgroup = "default" admin_state = "locked" - cli_ned_id = "cisco-ios-cli-3.0:cisco-ios-cli-3.0" + cli_ned_id = "cisco-ios-cli-3.8:cisco-ios-cli-3.8" } ` }