Skip to content

498 - docs - netapp-ontap_lun resource #516

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 17, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# 2.3.0 (2025-xx-xx)
# 2.2.1

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2.3.0?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I didn't get your question.
I've added the bug fixes and doc changes under 2.2.1 and enhancements under 2.3.0 in the change log.
Do I need to make any changes here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I re-create this PR for stable-2.2.0 branch?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are releasing enhancements along with bugs, we will not be having any 2.2.1, so change to 2.3.0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@suhasbshekar I've updated the changelog under 2.3.0 section.

DOCUMENTATION:

- **netapp-ontap_lun**: updated documentation, added attribute validation ([#498](https://github.com/NetApp/terraform-provider-netapp-ontap/issues/498))

# 2.2.0 (2025-05-01)

Expand Down
1 change: 1 addition & 0 deletions docs/data-sources/lun.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))

<a id="nestedatt--location"></a>
Expand Down
1 change: 1 addition & 0 deletions docs/data-sources/luns.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
25 changes: 13 additions & 12 deletions docs/resources/lun.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +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

}

```

<!-- schema generated by tfplugindocs -->
Expand All @@ -45,20 +44,22 @@ 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
- `size_unit` (String) The unit used to interpret the size parameter

### Read-Only

- `id` (String) StorageLun UUID
- `serial_number` (String) Serial number for lun

## Import

Expand Down Expand Up @@ -102,14 +103,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"
}
```
21 changes: 16 additions & 5 deletions internal/provider/storage/storage_lun_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"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"
Expand Down Expand Up @@ -77,31 +78,31 @@ 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{
stringplanmodifier.UseStateForUnknown(),
},
},
"logical_unit": schema.StringAttribute{
MarkdownDescription: "Logical unit for lun",
MarkdownDescription: "The base name component of the LUN",
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
"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{
Expand Down Expand Up @@ -150,6 +151,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
Expand Down
10 changes: 5 additions & 5 deletions internal/provider/storage/storage_lun_resource_alias_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestAccStorageLunResouceAlias(t *testing.T) {
{
ResourceName: "netapp-ontap_storage_lun_resource.example",
ImportState: true,
ImportStateId: fmt.Sprintf("%s,%s,%s,%s", "/vol/tf_acc_volume/tf_acc_lun", "tf_acc_volume", "tf_acc_svm", "cluster4"),
ImportStateId: fmt.Sprintf("%s,%s,%s,%s", "/vol/tf_acc_volume/tf_acc_lun", "tf_acc_volume", "tf_acc_svm", "cluster5"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("netapp-ontap_storage_lun_resource.example", "name", "tf_acc_lun"),
resource.TestCheckResourceAttr("netapp-ontap_storage_lun_resource.example", "os_type", "linux"),
Expand Down Expand Up @@ -110,7 +110,7 @@ func testAccStorageLunResourceConfigAlias(logicalUnit string, svmname string, vo
provider "netapp-ontap" {
connection_profiles = [
{
name = "cluster4"
name = "cluster5"
hostname = "%s"
username = "%s"
password = "%s"
Expand All @@ -121,7 +121,7 @@ provider "netapp-ontap" {

resource "netapp-ontap_storage_lun_resource" "example" {
# required to know which system to interface with
cx_profile_name = "cluster4"
cx_profile_name = "cluster5"
logical_unit = "%s"
svm_name = "%s"
volume_name = "%s"
Expand All @@ -142,7 +142,7 @@ func testAccStorageLunResourceWithSizeUnitConfigAlias(logicalUnit string, svmnam
provider "netapp-ontap" {
connection_profiles = [
{
name = "cluster4"
name = "cluster5"
hostname = "%s"
username = "%s"
password = "%s"
Expand All @@ -153,7 +153,7 @@ provider "netapp-ontap" {

resource "netapp-ontap_storage_lun_resource" "example_size" {
# required to know which system to interface with
cx_profile_name = "cluster4"
cx_profile_name = "cluster5"
logical_unit = "%s"
svm_name = "%s"
volume_name = "%s"
Expand Down
14 changes: 7 additions & 7 deletions internal/provider/storage/storage_lun_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestAccStorageLunResouce(t *testing.T) {
{
ResourceName: "netapp-ontap_lun.example",
ImportState: true,
ImportStateId: fmt.Sprintf("%s,%s,%s,%s", "/vol/tf_acc_volume/tf_acc_lun", "tf_acc_volume", "tf_acc_svm", "cluster4"),
ImportStateId: fmt.Sprintf("%s,%s,%s,%s", "/vol/tf_acc_volume/tf_acc_lun", "tf_acc_volume", "tf_acc_svm", "cluster5"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("netapp-ontap_lun.example", "name", "ACC-import-lun"),
resource.TestCheckResourceAttr("netapp-ontap_lun.example", "os_type", "linux"),
Expand Down Expand Up @@ -110,7 +110,7 @@ func testAccStorageLunResourceConfig(logicalUnit string, svmname string, volumeN
provider "netapp-ontap" {
connection_profiles = [
{
name = "cluster4"
name = "cluster5"
hostname = "%s"
username = "%s"
password = "%s"
Expand All @@ -121,7 +121,7 @@ provider "netapp-ontap" {

resource "netapp-ontap_lun" "example" {
# required to know which system to interface with
cx_profile_name = "cluster4"
cx_profile_name = "cluster5"
logical_unit = "%s"
svm_name = "%s"
volume_name = "%s"
Expand All @@ -130,7 +130,7 @@ resource "netapp-ontap_lun" "example" {
}`, host, admin, password, logicalUnit, svmname, volumeName, osType, size)
}

func testAccStorageLunResourceWithSizeUnitConfig(logicalUnit string, svmname string, volumeName string, osType string, size int64, size_unit string) string {
func testAccStorageLunResourceWithSizeUnitConfig(logicalUnit string, svmname string, volumeName string, osType string, size int64, sizeUnit string) string {
host := os.Getenv("TF_ACC_NETAPP_HOST")
admin := os.Getenv("TF_ACC_NETAPP_USER")
password := os.Getenv("TF_ACC_NETAPP_PASS")
Expand All @@ -142,7 +142,7 @@ func testAccStorageLunResourceWithSizeUnitConfig(logicalUnit string, svmname str
provider "netapp-ontap" {
connection_profiles = [
{
name = "cluster4"
name = "cluster5"
hostname = "%s"
username = "%s"
password = "%s"
Expand All @@ -153,12 +153,12 @@ provider "netapp-ontap" {

resource "netapp-ontap_lun" "example_size" {
# required to know which system to interface with
cx_profile_name = "cluster4"
cx_profile_name = "cluster5"
logical_unit = "%s"
svm_name = "%s"
volume_name = "%s"
os_type = "%s"
size = "%d"
size_unit = "%s"
}`, host, admin, password, logicalUnit, svmname, volumeName, osType, size, size_unit)
}`, host, admin, password, logicalUnit, svmname, volumeName, osType, size, sizeUnit)
}
Loading