diff --git a/CHANGELOG.md b/CHANGELOG.md index f6c0ef99..be002e48 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # 2.3.0 +DOCUMENTATION: + +- **netapp-ontap_lun**: updated documentation, added attribute validation ([#498](https://github.com/NetApp/terraform-provider-netapp-ontap/issues/498)) + ENHANCEMENTS: - **netapp-ontap_lun**: added `space.scsi_thin_provisioning_support_enabled` option. ([#496](https://github.com/NetApp/terraform-provider-netapp-ontap/issues/496)) diff --git a/docs/data-sources/lun.md b/docs/data-sources/lun.md index 4905b577..5b469a14 100644 --- a/docs/data-sources/lun.md +++ b/docs/data-sources/lun.md @@ -50,6 +50,7 @@ data "netapp-ontap_lun" "storage_lun" { - `id` (String) Lun uuid - `os_type` (String) OS type for lun - `qos_policy` (Attributes) (see [below for nested schema](#nestedatt--qos_policy)) +- `serial_number` (String) Serial number for lun - `space` (Attributes) (see [below for nested schema](#nestedatt--space)) diff --git a/docs/data-sources/luns.md b/docs/data-sources/luns.md index 50134c9a..0ac4bdcf 100644 --- a/docs/data-sources/luns.md +++ b/docs/data-sources/luns.md @@ -65,6 +65,7 @@ Read-Only: - `name` (String) StorageLun name - `os_type` (String) OS type for lun - `qos_policy` (Attributes) (see [below for nested schema](#nestedatt--storage_luns--qos_policy)) +- `serial_number` (String) Serial number for lun - `space` (Attributes) (see [below for nested schema](#nestedatt--storage_luns--space)) - `svm_name` (String) StorageLun svm name diff --git a/docs/resources/lun.md b/docs/resources/lun.md index f77e01a0..7173eb45 100644 --- a/docs/resources/lun.md +++ b/docs/resources/lun.md @@ -29,13 +29,13 @@ Create/Modify/Delete a lun resource resource "netapp-ontap_lun" "storage_lun" { # required to know which system to interface with cx_profile_name = "cluster4" - name = "ACC-import-lun" + name = "/vol/vol1/lun1" + logical_unit = "lun1" svm_name = "carchi-test" - volume_name = "lunTest" + volume_name = "vol1" os_type = "linux" size = 1048576 } - ``` @@ -44,14 +44,15 @@ resource "netapp-ontap_lun" "storage_lun" { ### Required - `cx_profile_name` (String) Connection profile name -- `name` (String) Lun name or location.logical_unit -- `os_type` (String) OS type -- `size` (Number) Size of the lun in byte if size_unit is not provided, otherwise size in the specified `size_unit` -- `svm_name` (String) SVM name -- `volume_name` (String) Volume name +- `os_type` (String) The operating system type of the LUN +- `size` (Number) Size of the lun in byte if size_unit is not provided, otherwise size in the specified unit +- `svm_name` (String) The name of the SVM in which the LUN is located +- `volume_name` (String) The volume in which the LUN is located ### Optional +- `logical_unit` (String) The base name component of the LUN +- `name` (String) Path for the LUN you want to create or modify. Example of correct LUN path: /vol/vol1/lun1. At least one of `name` or `logical_unit` must be provided. - `qos_policy_name` (String) QoS policy name - `scsi_thin_provisioning_support_enabled` (Boolean) Specifies the value for the space allocation attribute, which determines if the LUN supports the SCSI Thin Provisioning features - `size_unit` (String) The unit used to interpret the size parameter @@ -59,6 +60,7 @@ resource "netapp-ontap_lun" "storage_lun" { ### Read-Only - `id` (String) StorageLun UUID +- `serial_number` (String) Serial number for lun ## Import @@ -102,14 +104,14 @@ This will generate a file called generated.tf, which will contain the configurat # __generated__ by Terraform # Please review these resources and move them into your main configuration files. -# __generated__ by Terraform from "ACC-import-lun,lunTest,carchi-test,cluster4" +# __generated__ by Terraform from "ACC-import-lun,vol1,carchi-test,cluster4" resource "netapp-ontap_lun" "lun_import" { cx_profile_name = "cluster4" - name = "ACC-import-lun" + name = "/vol/vol1/ACC-import-lun" os_type = "linux" qos_policy_name = null size = 1048576 svm_name = "carchi-test" - volume_name = "lunTest" + volume_name = "vol1" } ``` diff --git a/internal/provider/storage/storage_lun_resource.go b/internal/provider/storage/storage_lun_resource.go index 2b3e4f54..db055318 100644 --- a/internal/provider/storage/storage_lun_resource.go +++ b/internal/provider/storage/storage_lun_resource.go @@ -14,6 +14,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource/schema/boolplanmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-plugin-framework-validators/resourcevalidator" "github.com/hashicorp/terraform-plugin-log/tflog" "github.com/netapp/terraform-provider-netapp-ontap/internal/interfaces" "github.com/netapp/terraform-provider-netapp-ontap/internal/utils" @@ -79,7 +80,7 @@ func (r *StorageLunResource) Schema(ctx context.Context, req resource.SchemaRequ Required: true, }, "name": schema.StringAttribute{ - MarkdownDescription: "Lun name", + MarkdownDescription: "Path for the LUN you want to create or modify. Example of correct LUN path: /vol/vol1/lun1", Optional: true, Computed: true, PlanModifiers: []planmodifier.String{ @@ -87,7 +88,7 @@ func (r *StorageLunResource) Schema(ctx context.Context, req resource.SchemaRequ }, }, "logical_unit": schema.StringAttribute{ - MarkdownDescription: "Logical unit for lun", + MarkdownDescription: "The base name component of the LUN", Optional: true, Computed: true, PlanModifiers: []planmodifier.String{ @@ -95,15 +96,15 @@ func (r *StorageLunResource) Schema(ctx context.Context, req resource.SchemaRequ }, }, "svm_name": schema.StringAttribute{ - MarkdownDescription: "SVM name", + MarkdownDescription: "The name of the SVM in which the LUN is located", Required: true, }, "volume_name": schema.StringAttribute{ - MarkdownDescription: "Volume name", + MarkdownDescription: "The volume in which the LUN is located", Required: true, }, "os_type": schema.StringAttribute{ - MarkdownDescription: "OS type", + MarkdownDescription: "The operating system type of the LUN", Required: true, }, "size": schema.Int64Attribute{ @@ -160,6 +161,16 @@ func (r *StorageLunResource) Configure(ctx context.Context, req resource.Configu r.config.ProviderConfig = config } +// ConfigValidators validates entire resource configurations +func (d *StorageLunResource) ConfigValidators(ctx context.Context) []resource.ConfigValidator { + return []resource.ConfigValidator{ + resourcevalidator.AtLeastOneOf( + path.MatchRoot("name"), + path.MatchRoot("logical_unit"), + ), + } +} + // Read refreshes the Terraform state with the latest data. func (r *StorageLunResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { var data StorageLunResourceModel