-
Notifications
You must be signed in to change notification settings - Fork 9
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
[Enhancement]: Add SVM storage_limit
parameter
#328
base: integration/main
Are you sure you want to change the base?
Changes from all commits
a73284d
f48d397
26a8f49
d772227
b6a0dc7
b576f5f
9e9ea16
4880190
c8c1fba
98e9570
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ Retrieves the configuration of SVMs. | |
## Supported Platforms | ||
|
||
* On-prem ONTAP system 9.6 or higher | ||
* `storage_limit` attribute supported with ONTAP system 9.13 or higher | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to be added in the list of attributes on line 64-72 |
||
* Amazon FSx for NetApp ONTAP | ||
|
||
## Example Usage | ||
|
@@ -69,3 +70,4 @@ Read-Only: | |
- `max_volumes` (String) Maximum number of volumes that can be created on the svm. Expects an integer or unlimited | ||
- `snapshot_policy` (String) The name of the snapshot policy to manage | ||
- `subtype` (String) The subtype for svm to be created | ||
- `storage_limit` (Number) Maximum storage permitted on svm, in bytes |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,11 +21,12 @@ Create/Modify/Delete a SVM | |
## Supported Platforms | ||
|
||
* On-prem ONTAP system 9.6 or higher | ||
* `storage_limit` attribute supported with ONTAP system 9.13 or higher | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to be added in the list of attributes on line 47-63 |
||
* Amazon FSx for NetApp ONTAP | ||
|
||
## Example Usage | ||
|
||
This creates a new SVM called `tfsvm4`. In IPspace `terraformIpspace_newname`, which can have up to 200 volumes which will be cased on aggr2 | ||
This creates a new SVM called `tfsvm4` in IPspace `terraformIpspace_newname`, which can have up to 200 volumes and up to 1 GB storage, which will be cased on aggr2. | ||
|
||
```terraform | ||
resource "netapp-ontap_svm" "example" { | ||
|
@@ -35,8 +36,11 @@ resource "netapp-ontap_svm" "example" { | |
comment = "test" | ||
snapshot_policy = "default-1weekly" | ||
language = "en_us.utf_8" | ||
aggregates = ["aggr2"] | ||
aggregates = [ | ||
{ name = "aggr2" } | ||
] | ||
max_volumes = "200" | ||
storage_limit = 1073741824 | ||
}` | ||
``` | ||
|
||
|
@@ -57,6 +61,7 @@ resource "netapp-ontap_svm" "example" { | |
- `max_volumes` (String) Maximum number of volumes that can be created on the svm. Expects an integer or unlimited | ||
- `snapshot_policy` (String) The name of the snapshot policy to manage | ||
- `subtype` (String) The subtype for svm to be created | ||
- `storage_limit` (Number) Maximum storage permitted on svm, in bytes | ||
|
||
### Read-Only | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
resource "netapp-ontap_svm" "example" { | ||
cx_profile_name = "cluster2" | ||
name = "tfsvm" | ||
ipspace = "test" | ||
comment = "test" | ||
name = "tfsvm" | ||
ipspace = "test" | ||
comment = "test" | ||
snapshot_policy = "default-1weekly" | ||
//subtype = "dp_destination" | ||
language = "en_us.utf_8" | ||
aggregates = ["aggr1", "test"] | ||
max_volumes = "200" | ||
aggregates = [ | ||
{ name = "aggr1" }, | ||
{ name = "test" }, | ||
] | ||
max_volumes = "200" | ||
storage_limit = 1073741824 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ import ( | |
"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/int64default" | ||
"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" | ||
|
@@ -56,6 +57,7 @@ type SvmResourceModel struct { | |
Language types.String `tfsdk:"language"` | ||
Aggregates []Aggregate `tfsdk:"aggregates"` | ||
MaxVolumes types.String `tfsdk:"max_volumes"` | ||
StorageLimit types.Int64 `tfsdk:"storage_limit"` | ||
ID types.String `tfsdk:"id"` | ||
} | ||
|
||
|
@@ -120,6 +122,12 @@ func (r *SvmResource) Schema(ctx context.Context, req resource.SchemaRequest, re | |
MarkdownDescription: "Maximum number of volumes that can be created on the svm. Expects an integer or unlimited", | ||
Optional: true, | ||
}, | ||
"storage_limit": schema.Int64Attribute{ | ||
MarkdownDescription: "Maximum storage permitted on svm, in bytes", | ||
Optional: true, | ||
Computed: true, | ||
Default: int64default.StaticInt64(0), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is an optional parameter based on the API doc https://docs.netapp.com/us-en/ontap-restapi-9131/ontap/post-svm-svms.html#recommended-optional-properties There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without a default value, the attribute remains "unknown" after the apply - resulting in the following error:
I could manually set the value to 0 in |
||
}, | ||
"id": schema.StringAttribute{ | ||
Computed: true, | ||
MarkdownDescription: "SVM identifier", | ||
|
@@ -191,6 +199,12 @@ func (r *SvmResource) Create(ctx context.Context, req resource.CreateRequest, re | |
request.MaxVolumes = data.MaxVolumes.ValueString() | ||
} | ||
|
||
setStorageLimitEmpty := true | ||
if !data.StorageLimit.Equal(types.Int64Value(0)) { | ||
setStorageLimitEmpty = false | ||
request.Storage.Limit = int(data.StorageLimit.ValueInt64()) | ||
} | ||
|
||
setAggrEmpty := false | ||
if len(data.Aggregates) != 0 { | ||
aggregates := []interfaces.Aggregate{} | ||
|
@@ -214,7 +228,14 @@ func (r *SvmResource) Create(ctx context.Context, req resource.CreateRequest, re | |
// error reporting done inside NewClient | ||
return | ||
} | ||
svm, err := interfaces.CreateSvm(errorHandler, *client, request, setAggrEmpty, setCommentEmpty) | ||
svm, err := interfaces.CreateSvm( | ||
errorHandler, | ||
*client, | ||
request, | ||
setAggrEmpty, | ||
setCommentEmpty, | ||
setStorageLimitEmpty, | ||
) | ||
if err != nil { | ||
return | ||
} | ||
|
@@ -244,12 +265,23 @@ func (r *SvmResource) Read(ctx context.Context, req resource.ReadRequest, resp * | |
// error reporting done inside NewClient | ||
return | ||
} | ||
|
||
cluster, err := interfaces.GetCluster(errorHandler, *client) | ||
if err != nil { | ||
// error reporting done inside GetCluster | ||
return | ||
} | ||
if cluster == nil { | ||
errorHandler.MakeAndReportError("No cluster found", "cluster not found") | ||
return | ||
} | ||
|
||
tflog.Debug(ctx, fmt.Sprintf("read a svm resource: %#v", data)) | ||
var svm *interfaces.SvmGetDataSourceModel | ||
if data.ID.ValueString() != "" { | ||
svm, err = interfaces.GetSvm(errorHandler, *client, data.ID.ValueString()) | ||
} else { | ||
svm, err = interfaces.GetSvmByNameDataSource(errorHandler, *client, data.Name.ValueString()) | ||
svm, err = interfaces.GetSvmByNameDataSource(errorHandler, *client, data.Name.ValueString(), cluster.Version) | ||
} | ||
if err != nil { | ||
return | ||
|
@@ -295,6 +327,8 @@ func (r *SvmResource) Read(ctx context.Context, req resource.ReadRequest, resp * | |
data.MaxVolumes = types.StringValue(svm.MaxVolumes) | ||
} | ||
|
||
data.StorageLimit = types.Int64Value(int64(svm.Storage.Limit)) | ||
|
||
// Save updated data into Terraform state | ||
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) | ||
} | ||
|
@@ -375,6 +409,10 @@ func (r *SvmResource) Update(ctx context.Context, req resource.UpdateRequest, re | |
request.MaxVolumes = data.MaxVolumes.ValueString() | ||
} | ||
|
||
if !data.StorageLimit.Equal(state.StorageLimit) { | ||
request.Storage.Limit = int(data.StorageLimit.ValueInt64()) | ||
} | ||
|
||
// aggregates can be modified as empty list | ||
aggregates := []interfaces.Aggregate{} | ||
if len(data.Aggregates) != 0 { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be added in the list of attributes on line 37-46