Skip to content

Commit 4376651

Browse files
authored
Merge pull request #424 from NetApp/256-enhancement-netapp-ontap_aggregate
256 - enhancement - aggregate data sources
2 parents 103d0d5 + d5b21b9 commit 4376651

6 files changed

Lines changed: 110 additions & 14 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# 2.2.0 (2025-xx-xx)
2+
3+
ENHANCEMENTS:
4+
5+
- **netapp-ontap_aggregate_data_source**, **netapp-ontap_aggregates_data_source**: added `space.block_storage.available` option ([#256](https://github.com/NetApp/terraform-provider-netapp-ontap/issues/256))
6+
17
# 2.1.2 (not released)
28

39
BUG FIXES:

docs/data-sources/aggregate.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,19 @@ data "netapp-ontap_aggregate" "storage_aggregate" {
4545
- `raid_size` (Number) Sets the maximum number of drives per raid group.
4646
- `raid_type` (String)
4747
- `snaplock_type` (String) Type of snaplock for the aggregate being created.
48+
- `space` (Attributes) (see [below for nested schema](#nestedatt--space))
4849
- `state` (String) Whether the specified aggregate should be enabled or disabled. Creates aggregate if doesn't exist.
50+
51+
<a id="nestedatt--space"></a>
52+
### Nested Schema for `space`
53+
54+
Read-Only:
55+
56+
- `block_storage` (Attributes) (see [below for nested schema](#nestedatt--space--block_storage))
57+
58+
<a id="nestedatt--space--block_storage"></a>
59+
### Nested Schema for `space.block_storage`
60+
61+
Read-Only:
62+
63+
- `available` (Number) Space available in bytes.

docs/data-sources/aggregates.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,19 @@ Read-Only:
7272
- `raid_size` (Number) Sets the maximum number of drives per raid group.
7373
- `raid_type` (String)
7474
- `snaplock_type` (String) Type of snaplock for the aggregate being created.
75+
- `space` (Attributes) (see [below for nested schema](#nestedatt--storage_aggregates--space))
7576
- `state` (String) Whether the specified aggregate should be enabled or disabled. Creates aggregate if doesn't exist.
77+
78+
<a id="nestedatt--storage_aggregates--space"></a>
79+
### Nested Schema for `storage_aggregates.space`
80+
81+
Read-Only:
82+
83+
- `block_storage` (Attributes) (see [below for nested schema](#nestedatt--storage_aggregates--space--block_storage))
84+
85+
<a id="nestedatt--storage_aggregates--space--block_storage"></a>
86+
### Nested Schema for `storage_aggregates.space.block_storage`
87+
88+
Read-Only:
89+
90+
- `available` (Number) Space available in bytes.

internal/interfaces/storage_aggregate.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type StorageAggregateGetDataModelONTAP struct {
1919
DataEncryption AggregateDataEncryption `mapstructure:"data_encryption"`
2020
SnaplockType string `mapstructure:"snaplock_type"`
2121
State string `mapstructure:"state"`
22+
Space AggregateSpace `mapstructure:"space"`
2223
}
2324

2425
// StorageAggregateGetDataFilterModel describes filter model
@@ -48,6 +49,16 @@ type AggregateBlockStorageMirror struct {
4849
Enabled bool `mapstructure:"enabled"`
4950
}
5051

52+
// AggregateSpace describes space within StorageAggregateGetDataModelONTAP
53+
type AggregateSpace struct {
54+
BlockStorage AggregateSpaceBlockStorage `mapstructure:"block_storage"`
55+
}
56+
57+
// AggregateSpaceBlockStorage describes block_storage within AggregateSpace
58+
type AggregateSpaceBlockStorage struct {
59+
Available int64 `mapstructure:"available"`
60+
}
61+
5162
// StorageAggregateResourceModel describes the resource data model.
5263
type StorageAggregateResourceModel struct {
5364
Name string `mapstructure:"name,omitempty"`
@@ -94,7 +105,7 @@ func GetStorageAggregateByName(errorHandler *utils.ErrorHandler, r restclient.Re
94105
query := r.NewQuery()
95106
query.Set("name", name)
96107

97-
query.Fields([]string{"name", "node.name", "uuid", "state", "block_storage.primary.disk_class", "block_storage.primary.disk_count", "block_storage.primary.raid_size", "block_storage.primary.raid_type", "block_storage.mirror.enabled", "snaplock_type", "data_encryption.software_encryption_enabled"})
108+
query.Fields([]string{"name", "node.name", "uuid", "state", "block_storage.primary.disk_class", "block_storage.primary.disk_count", "block_storage.primary.raid_size", "block_storage.primary.raid_type", "block_storage.mirror.enabled", "snaplock_type", "data_encryption.software_encryption_enabled", "space.block_storage.available"})
98109
statusCode, response, err := r.GetNilOrOneRecord(api, query, nil)
99110
if err == nil && response == nil {
100111
err = fmt.Errorf("no response for GET %s", api)
@@ -116,7 +127,7 @@ func GetStorageAggregateByName(errorHandler *utils.ErrorHandler, r restclient.Re
116127
func GetStorageAggregates(errorHandler *utils.ErrorHandler, r restclient.RestClient, filter *StorageAggregateGetDataFilterModel) ([]StorageAggregateGetDataModelONTAP, error) {
117128
api := "storage/aggregates"
118129
query := r.NewQuery()
119-
query.Fields([]string{"name", "node.name", "uuid", "state", "block_storage.primary.disk_class", "block_storage.primary.disk_count", "block_storage.primary.raid_size", "block_storage.primary.raid_type", "block_storage.mirror.enabled", "snaplock_type", "data_encryption.software_encryption_enabled"})
130+
query.Fields([]string{"name", "node.name", "uuid", "state", "block_storage.primary.disk_class", "block_storage.primary.disk_count", "block_storage.primary.raid_size", "block_storage.primary.raid_type", "block_storage.mirror.enabled", "snaplock_type", "data_encryption.software_encryption_enabled", "space.block_storage.available"})
120131
if filter != nil {
121132
var filterMap map[string]interface{}
122133
if err := mapstructure.Decode(filter, &filterMap); err != nil {

internal/provider/storage/storage_aggregate_data_source.go

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,29 @@ type StorageAggregateDataSource struct {
4242

4343
// StorageAggregateDataSourceModel describes the data source data model.
4444
type StorageAggregateDataSourceModel struct {
45-
CxProfileName types.String `tfsdk:"cx_profile_name"`
46-
Name types.String `tfsdk:"name"`
47-
ID types.String `tfsdk:"id"`
48-
State types.String `tfsdk:"state"`
49-
Node types.String `tfsdk:"node"`
50-
DiskClass types.String `tfsdk:"disk_class"`
51-
DiskCount types.Int64 `tfsdk:"disk_count"`
52-
RaidSize types.Int64 `tfsdk:"raid_size"`
53-
RaidType types.String `tfsdk:"raid_type"`
54-
IsMirrored types.Bool `tfsdk:"is_mirrored"`
55-
SnaplockType types.String `tfsdk:"snaplock_type"`
56-
Encryption types.Bool `tfsdk:"encryption"`
45+
CxProfileName types.String `tfsdk:"cx_profile_name"`
46+
Name types.String `tfsdk:"name"`
47+
ID types.String `tfsdk:"id"`
48+
State types.String `tfsdk:"state"`
49+
Node types.String `tfsdk:"node"`
50+
DiskClass types.String `tfsdk:"disk_class"`
51+
DiskCount types.Int64 `tfsdk:"disk_count"`
52+
RaidSize types.Int64 `tfsdk:"raid_size"`
53+
RaidType types.String `tfsdk:"raid_type"`
54+
IsMirrored types.Bool `tfsdk:"is_mirrored"`
55+
SnaplockType types.String `tfsdk:"snaplock_type"`
56+
Encryption types.Bool `tfsdk:"encryption"`
57+
Space *StorageAggregateDataSourceSpace `tfsdk:"space"`
58+
}
59+
60+
// StorageAggregateDataSourceSpace describes the space model.
61+
type StorageAggregateDataSourceSpace struct {
62+
BlockStorage *StorageAggregateDataSourceSpaceBlockStorage `tfsdk:"block_storage"`
63+
}
64+
65+
// StorageAggregateDataSourceSpaceBlockStorage describes the block storage model within sapce model.
66+
type StorageAggregateDataSourceSpaceBlockStorage struct {
67+
Available types.Int64 `tfsdk:"available"`
5768
}
5869

5970
// StorageAggregateDataSourceFilterModel describes the data source data model for queries.
@@ -129,6 +140,20 @@ func (d *StorageAggregateDataSource) Schema(ctx context.Context, req datasource.
129140
MarkdownDescription: "Whether to enable software encryption. This is equivalent to -encrypt-with-aggr-key when using the CLI.Requires a VE license.",
130141
Computed: true,
131142
},
143+
"space": schema.SingleNestedAttribute{
144+
Computed: true,
145+
Attributes: map[string]schema.Attribute{
146+
"block_storage": schema.SingleNestedAttribute{
147+
Computed: true,
148+
Attributes: map[string]schema.Attribute{
149+
"available": schema.Int64Attribute{
150+
Computed: true,
151+
MarkdownDescription: "Space available in bytes.",
152+
},
153+
},
154+
},
155+
},
156+
},
132157
},
133158
}
134159
}
@@ -185,6 +210,11 @@ func (d *StorageAggregateDataSource) Read(ctx context.Context, req datasource.Re
185210
data.State = types.StringValue(restInfo.State)
186211
data.Name = types.StringValue(restInfo.Name)
187212
data.Node = types.StringValue(restInfo.Node.Name)
213+
data.Space = &StorageAggregateDataSourceSpace{
214+
BlockStorage: &StorageAggregateDataSourceSpaceBlockStorage{
215+
Available: types.Int64Value(restInfo.Space.BlockStorage.Available),
216+
},
217+
}
188218

189219
// Write logs using the tflog package
190220
// Documentation: https://terraform.io/plugin/log

internal/provider/storage/storage_aggregates_data_source.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,20 @@ func (d *StorageAggregatesDataSource) Schema(ctx context.Context, req datasource
133133
MarkdownDescription: "Whether to enable software encryption. This is equivalent to -encrypt-with-aggr-key when using the CLI.Requires a VE license.",
134134
Computed: true,
135135
},
136+
"space": schema.SingleNestedAttribute{
137+
Computed: true,
138+
Attributes: map[string]schema.Attribute{
139+
"block_storage": schema.SingleNestedAttribute{
140+
Computed: true,
141+
Attributes: map[string]schema.Attribute{
142+
"available": schema.Int64Attribute{
143+
Computed: true,
144+
MarkdownDescription: "Space available in bytes.",
145+
},
146+
},
147+
},
148+
},
149+
},
136150
},
137151
},
138152
Computed: true,
@@ -206,6 +220,11 @@ func (d *StorageAggregatesDataSource) Read(ctx context.Context, req datasource.R
206220
State: types.StringValue(record.State),
207221
Name: types.StringValue(record.Name),
208222
Node: types.StringValue(record.Node.Name),
223+
Space: &StorageAggregateDataSourceSpace{
224+
BlockStorage: &StorageAggregateDataSourceSpaceBlockStorage{
225+
Available: types.Int64Value(record.Space.BlockStorage.Available),
226+
},
227+
},
209228
}
210229
}
211230

0 commit comments

Comments
 (0)