Skip to content

Commit 9d5cf31

Browse files
aaygoyalNagaRajuPasunuri
authored andcommitted
Added - Support for Allow admins to specify user Quotas for their filesystems
1 parent 242d83b commit 9d5cf31

19 files changed

+1286
-3
lines changed

examples/storage/fss/data_sources.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,17 @@ data "oci_file_storage_outbound_connectors" "outbound_connectors" {
132132
#id = var.outbound_connector_id
133133
#state = var.outbound_connector_state
134134
}
135+
136+
# Gets the list of quota rules for a file-system and principal_type
137+
data "oci_file_storage_file_system_quota_rules" "file_system_quota_rules" {
138+
#Required
139+
file_system_id = oci_file_storage_file_system.my_fs_simple_quota_rule.id
140+
principal_type = var.my_simple_quota_rule_principal_type
141+
}
142+
143+
# Gets the quota rule for a file-system id and quota-rule id
144+
data "oci_file_storage_file_system_quota_rule" "file_system_quota_rule" {
145+
#Required
146+
file_system_id = oci_file_storage_file_system.my_fs_simple_quota_rule.id
147+
quota_rule_id = oci_file_storage_file_system_quota_rule.my_simple_quota_rule.id
148+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
resource "oci_file_storage_file_system" "my_fs_simple_quota_rule" {
2+
#Required
3+
availability_domain = data.oci_identity_availability_domain.ad.name
4+
compartment_id = var.compartment_ocid
5+
6+
#Optional
7+
display_name = var.file_system_simple_qr_display_name
8+
are_quota_rules_enabled = var.quota_rule_enabled
9+
10+
}
11+
12+
resource "oci_file_storage_file_system_quota_rule" "my_simple_quota_rule" {
13+
#Required
14+
file_system_id = oci_file_storage_file_system.my_fs_simple_quota_rule.id
15+
is_hard_quota = var.my_simple_quota_rule_is_hard_quota
16+
principal_type = var.my_simple_quota_rule_principal_type
17+
quota_limit_in_gigabytes = var.my_simple_quota_rule_quota_limit_in_gigabytes
18+
19+
#Optional
20+
display_name = var.my_simple_quota_rule_display_name
21+
}

examples/storage/fss/variables.tf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ variable "clone_attach_status_value" {
6262
default= "DETACH"
6363
}
6464

65+
variable "quota_rule_enabled" {
66+
default = "false"
67+
}
68+
6569
variable "file_system_with_snapshot_policy_display_name" {
6670
default = "my_fs_with_snapshot_policy"
6771
}
@@ -315,3 +319,23 @@ variable "locks_message" {
315319
variable "is_lock_override" {
316320
default = true
317321
}
322+
323+
variable "file_system_simple_qr_display_name" {
324+
default= "my_fs_simple_quota_rule"
325+
}
326+
327+
variable "my_simple_quota_rule_is_hard_quota" {
328+
default = "false"
329+
}
330+
331+
variable "my_simple_quota_rule_principal_type" {
332+
default = "FILE_SYSTEM_LEVEL"
333+
}
334+
335+
variable "my_simple_quota_rule_quota_limit_in_gigabytes" {
336+
default = "10"
337+
}
338+
339+
variable "my_simple_quota_rule_display_name" {
340+
default = "my_simple_quota_rule"
341+
}

internal/integrationtest/file_storage_file_system_quota_rule_test.go

Lines changed: 314 additions & 0 deletions
Large diffs are not rendered by default.

internal/integrationtest/file_storage_file_system_test.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ var (
5252
FileStorageFileSystemRepresentation = map[string]interface{}{
5353
"availability_domain": acctest.Representation{RepType: acctest.Required, Create: `${data.oci_identity_availability_domains.test_availability_domains.availability_domains.0.name}`},
5454
"compartment_id": acctest.Representation{RepType: acctest.Required, Create: `${var.compartment_id}`},
55+
"are_quota_rules_enabled": acctest.Representation{RepType: acctest.Optional, Create: `false`, Update: `false`},
5556
"clone_attach_status": acctest.Representation{RepType: acctest.Optional, Create: `DETACH`},
5657
"defined_tags": acctest.Representation{RepType: acctest.Optional, Create: `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "value")}`, Update: `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "updatedValue")}`},
5758
"display_name": acctest.Representation{RepType: acctest.Optional, Create: `media-files-1`, Update: `displayName2`},
@@ -165,6 +166,7 @@ func TestFileStorageFileSystemResource_basic(t *testing.T) {
165166
Config: config + compartmentIdVariableStr + FileStorageFileSystemResourceDependencies +
166167
acctest.GenerateResourceFromRepresentationMap("oci_file_storage_file_system", "test_file_system2", acctest.Optional, acctest.Create, FileStorageFileSystemRepresentationWithDeleteLock),
167168
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
169+
resource.TestCheckResourceAttr(resourceName, "are_quota_rules_enabled", "false"),
168170
resource.TestCheckResourceAttrSet(resourceName, "availability_domain"),
169171
resource.TestCheckResourceAttr(resourceName, "clone_attach_status", "ATTACHED"),
170172
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentId),
@@ -203,8 +205,9 @@ func TestFileStorageFileSystemResource_basic(t *testing.T) {
203205
"compartment_id": acctest.Representation{RepType: acctest.Required, Create: `${var.compartment_id_for_update}`},
204206
})),
205207
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
208+
resource.TestCheckResourceAttr(resourceName, "are_quota_rules_enabled", "false"),
206209
resource.TestCheckResourceAttrSet(resourceName, "availability_domain"),
207-
resource.TestCheckResourceAttr(resourceName, "clone_attach_status", "DETACHING"),
210+
resource.TestCheckResourceAttr(resourceName, "clone_attach_status", "ATTACHED"),
208211
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentIdU),
209212
resource.TestCheckResourceAttr(resourceName, "display_name", "media-files-1"),
210213
resource.TestCheckResourceAttrSet(resourceName, "filesystem_snapshot_policy_id"),
@@ -262,8 +265,9 @@ func TestFileStorageFileSystemResource_basic(t *testing.T) {
262265
Config: config + compartmentIdVariableStr + FileStorageFileSystemResourceDependencies +
263266
acctest.GenerateResourceFromRepresentationMap("oci_file_storage_file_system", "test_file_system2", acctest.Optional, acctest.Update, FileStorageFileSystemRepresentation),
264267
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
268+
resource.TestCheckResourceAttr(resourceName, "are_quota_rules_enabled", "false"),
265269
resource.TestCheckResourceAttrSet(resourceName, "availability_domain"),
266-
resource.TestCheckResourceAttr(resourceName, "clone_attach_status", "DETACHING"),
270+
resource.TestCheckResourceAttr(resourceName, "clone_attach_status", "ATTACHED"),
267271
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentId),
268272
resource.TestCheckResourceAttr(resourceName, "display_name", "displayName2"),
269273
resource.TestCheckResourceAttrSet(resourceName, "filesystem_snapshot_policy_id"),
@@ -304,14 +308,18 @@ func TestFileStorageFileSystemResource_basic(t *testing.T) {
304308

305309
resource.TestCheckResourceAttr(datasourceName, "file_systems.#", "1"),
306310
resource.TestCheckResourceAttrSet(datasourceName, "file_systems.0.availability_domain"),
307-
resource.TestCheckResourceAttr(datasourceName, "file_systems.0.clone_attach_status", "DETACHING"),
311+
resource.TestCheckResourceAttr(datasourceName, "file_systems.0.clone_attach_status", "ATTACHED"),
308312
resource.TestCheckResourceAttr(datasourceName, "file_systems.0.compartment_id", compartmentId),
309313
resource.TestCheckResourceAttr(datasourceName, "file_systems.0.display_name", "displayName2"),
310314
resource.TestCheckResourceAttr(datasourceName, "file_systems.0.freeform_tags.%", "1"),
311315

312316
acctest.TestCheckResourceAttributesEqual(datasourceName, "file_systems.0.id", "oci_file_storage_file_system.test_file_system2", "id"),
313317
resource.TestCheckResourceAttrSet(datasourceName, "file_systems.0.is_clone_parent"),
314318
resource.TestCheckResourceAttrSet(datasourceName, "file_systems.0.is_hydrated"),
319+
resource.TestCheckResourceAttr(datasourceName, "file_systems.0.locks.#", "1"),
320+
resource.TestCheckResourceAttr(datasourceName, "file_systems.0.locks.0.message", "message"),
321+
resource.TestCheckResourceAttrSet(datasourceName, "file_systems.0.metered_bytes"),
322+
resource.TestCheckResourceAttrSet(datasourceName, "file_systems.0.quota_enforcement_state"),
315323
acctest.TestCheckResourceAttributesEqual(datasourceName, "file_systems.0.kms_key_id", "oci_file_storage_file_system.test_file_system2", "kms_key_id"),
316324
acctest.TestCheckResourceAttributesEqual(datasourceName, "file_systems.0.metered_bytes", "oci_file_storage_file_system.test_file_system2", "metered_bytes"),
317325
resource.TestCheckResourceAttr(datasourceName, "file_systems.0.source_details.#", "1"),

internal/service/file_storage/file_storage_export.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
package file_storage
22

33
import (
4+
"fmt"
5+
46
oci_file_storage "github.com/oracle/oci-go-sdk/v65/filestorage"
57

68
tf_export "github.com/oracle/terraform-provider-oci/internal/commonexport"
79
)
810

911
func init() {
12+
13+
exportFileStorageFileSystemQuotaRuleHints.GetIdFn = getFileStorageFileSystemQuotaRuleId
1014
exportFileStorageMountTargetHints.RequireResourceRefresh = true
1115
tf_export.RegisterCompartmentGraphs("file_storage", fileStorageResourceGraph)
1216
tf_export.BuildAvailabilityResourceGraph("oci_identity_availability_domain", customAssociationFileStorageIdentityAvailabilityDomain)
@@ -15,6 +19,16 @@ func init() {
1519

1620
// Custom overrides for generating composite IDs within the resource discovery framework
1721

22+
func getFileStorageFileSystemQuotaRuleId(resource *tf_export.OCIResource) (string, error) {
23+
24+
fileSystemId := resource.Parent.Id
25+
quotaRuleId, ok := resource.SourceAttributes["quota_rule_id"].(string)
26+
if !ok {
27+
return "", fmt.Errorf("[ERROR] unable to find quotaRuleId for FileStorage FileSystemQuotaRule")
28+
}
29+
return GetFileSystemQuotaRuleCompositeId(fileSystemId, quotaRuleId), nil
30+
}
31+
1832
// Hints for discovering and exporting this resource to configuration and state files
1933
var exportFileStorageFileSystemHints = &tf_export.TerraformResourceHints{
2034
ResourceClass: "oci_file_storage_file_system",
@@ -93,6 +107,13 @@ var exportFileStorageOutboundConnectorHints = &tf_export.TerraformResourceHints{
93107
},
94108
}
95109

110+
var exportFileStorageFileSystemQuotaRuleHints = &tf_export.TerraformResourceHints{
111+
ResourceClass: "oci_file_storage_file_system_quota_rule",
112+
DatasourceClass: "oci_file_storage_file_system_quota_rules",
113+
DatasourceItemsAttr: "quota_rules",
114+
ResourceAbbreviation: "file_system_quota_rule",
115+
}
116+
96117
var fileStorageResourceGraph = tf_export.TerraformResourceGraph{
97118
"oci_identity_compartment": {
98119
{TerraformResourceHints: exportFileStorageExportHints},
@@ -137,6 +158,7 @@ var customAssociationFileStorageFileSystem = []tf_export.TerraformResourceAssoci
137158
TerraformResourceHints: exportFileStorageSnapshotHints,
138159
DatasourceQueryParams: map[string]string{
139160
"file_system_id": "id",
161+
"quota_rule_id": "id",
140162
},
141163
},
142164
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
// Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
2+
// Licensed under the Mozilla Public License v2.0
3+
4+
package file_storage
5+
6+
import (
7+
"context"
8+
9+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
10+
oci_file_storage "github.com/oracle/oci-go-sdk/v65/filestorage"
11+
12+
"github.com/oracle/terraform-provider-oci/internal/client"
13+
"github.com/oracle/terraform-provider-oci/internal/tfresource"
14+
)
15+
16+
func FileStorageFileSystemQuotaRuleDataSource() *schema.Resource {
17+
fieldMap := make(map[string]*schema.Schema)
18+
fieldMap["file_system_id"] = &schema.Schema{
19+
Type: schema.TypeString,
20+
Required: true,
21+
}
22+
fieldMap["quota_rule_id"] = &schema.Schema{
23+
Type: schema.TypeString,
24+
Optional: true,
25+
}
26+
fieldMap["are_violators_only"] = &schema.Schema{
27+
Type: schema.TypeString,
28+
Optional: true,
29+
}
30+
return tfresource.GetSingularDataSourceItemSchema(FileStorageFileSystemQuotaRuleResource(), fieldMap, readSingularFileStorageFileSystemQuotaRule)
31+
}
32+
33+
func readSingularFileStorageFileSystemQuotaRule(d *schema.ResourceData, m interface{}) error {
34+
sync := &FileStorageFileSystemQuotaRuleDataSourceCrud{}
35+
sync.D = d
36+
sync.Client = m.(*client.OracleClients).FileStorageClient()
37+
38+
return tfresource.ReadResource(sync)
39+
}
40+
41+
type FileStorageFileSystemQuotaRuleDataSourceCrud struct {
42+
D *schema.ResourceData
43+
Client *oci_file_storage.FileStorageClient
44+
Res *oci_file_storage.GetQuotaRuleResponse
45+
}
46+
47+
func (s *FileStorageFileSystemQuotaRuleDataSourceCrud) VoidState() {
48+
s.D.SetId("")
49+
}
50+
51+
func (s *FileStorageFileSystemQuotaRuleDataSourceCrud) Get() error {
52+
request := oci_file_storage.GetQuotaRuleRequest{}
53+
54+
if fileSystemId, ok := s.D.GetOkExists("file_system_id"); ok {
55+
tmp := fileSystemId.(string)
56+
request.FileSystemId = &tmp
57+
}
58+
59+
if quotaRuleId, ok := s.D.GetOkExists("quota_rule_id"); ok {
60+
tmp := quotaRuleId.(string)
61+
request.QuotaRuleId = &tmp
62+
}
63+
64+
request.RequestMetadata.RetryPolicy = tfresource.GetRetryPolicy(false, "file_storage")
65+
66+
response, err := s.Client.GetQuotaRule(context.Background(), request)
67+
if err != nil {
68+
return err
69+
}
70+
71+
s.Res = &response
72+
return nil
73+
}
74+
75+
func (s *FileStorageFileSystemQuotaRuleDataSourceCrud) SetData() error {
76+
if s.Res == nil {
77+
return nil
78+
}
79+
80+
s.D.SetId(*s.Res.Id)
81+
82+
if s.Res.DisplayName != nil {
83+
s.D.Set("display_name", *s.Res.DisplayName)
84+
}
85+
86+
if s.Res.IsHardQuota != nil {
87+
s.D.Set("is_hard_quota", *s.Res.IsHardQuota)
88+
}
89+
90+
if s.Res.PrincipalId != nil {
91+
s.D.Set("principal_id", *s.Res.PrincipalId)
92+
}
93+
94+
s.D.Set("principal_type", s.Res.PrincipalType)
95+
96+
if s.Res.QuotaLimitInGigabytes != nil {
97+
s.D.Set("quota_limit_in_gigabytes", *s.Res.QuotaLimitInGigabytes)
98+
}
99+
100+
if s.Res.TimeCreated != nil {
101+
s.D.Set("time_created", s.Res.TimeCreated.String())
102+
}
103+
104+
if s.Res.TimeUpdated != nil {
105+
s.D.Set("time_updated", s.Res.TimeUpdated.String())
106+
}
107+
108+
return nil
109+
}

0 commit comments

Comments
 (0)