Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions docs/data-sources/sfs_export_policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ data "stackit_sfs_export_policy" "example" {
### Read-Only

- `id` (String) Terraform's internal resource ID. It is structured as "`project_id`,`region`,`policy_id`".
- `labels` (Map of String) Labels are key-value string pairs which can be attached to an export policy
- `name` (String) Name of the export policy.
- `rules` (Attributes List) (see [below for nested schema](#nestedatt--rules))

Expand Down
1 change: 1 addition & 0 deletions docs/data-sources/sfs_resource_pool.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ data "stackit_sfs_resource_pool" "resourcepool" {
- `availability_zone` (String) Availability zone.
- `id` (String) Terraform's internal resource ID. It is structured as "`project_id`,`resource_pool_id`".
- `ip_acl` (List of String) List of IPs that can mount the resource pool in read-only; IPs must have a subnet mask (e.g. "172.16.0.0/24" for a range of IPs, or "172.16.0.250/32" for a specific IP).
- `labels` (Map of String) Labels are key-value string pairs which can be attached to a resource pool
- `name` (String) Name of the resource pool.
- `performance_class` (String) Name of the performance class.
- `performance_class_downgradable_at` (String) Time when the performance class can be downgraded again.
Expand Down
1 change: 1 addition & 0 deletions docs/data-sources/sfs_share.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Note that if this is not set, the Share can only be mounted in read only by
clients with IPs matching the IP ACL of the Resource Pool hosting this Share.
You can also assign a Share Export Policy after creating the Share
- `id` (String) Terraform's internal resource ID. It is structured as "`project_id`,`share_id`".
- `labels` (Map of String) Labels are key-value string pairs which can be attached to a share
- `mount_path` (String) Mount path of the Share, used to mount the Share
- `name` (String) Name of the Share
- `space_hard_limit_gigabytes` (Number) Space hard limit for the Share.
Expand Down
4 changes: 4 additions & 0 deletions docs/resources/sfs_export_policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ resource "stackit_sfs_export_policy" "example" {
order = 1
}
]
labels = {
"foo" = "bar"
}
}

# Only use the import statement, if you want to import an existing export policy
Expand All @@ -44,6 +47,7 @@ import {

### Optional

- `labels` (Map of String) Labels are key-value string pairs which can be attached to the resource.
- `region` (String) The resource region. If not defined, the provider region is used.
- `rules` (Attributes List) (see [below for nested schema](#nestedatt--rules))

Expand Down
4 changes: 4 additions & 0 deletions docs/resources/sfs_resource_pool.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ resource "stackit_sfs_resource_pool" "resourcepool" {
"192.168.42.2/32"
]
snapshots_are_visible = true
labels = {
"foo" = "bar"
}
}

# Only use the import statement, if you want to import an existing resource pool
Expand All @@ -50,6 +53,7 @@ import {

### Optional

- `labels` (Map of String) Labels are key-value string pairs which can be attached to the resource.
- `region` (String) The resource region. If not defined, the provider region is used.
- `snapshot_policy` (Attributes) Name of the snapshot policy. (see [below for nested schema](#nestedatt--snapshot_policy))
- `snapshots_are_visible` (Boolean) If set to true, snapshots are visible and accessible to users. (default: false)
Expand Down
4 changes: 4 additions & 0 deletions docs/resources/sfs_share.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ resource "stackit_sfs_share" "example" {
name = "my-nfs-share"
export_policy = "high-performance-class"
space_hard_limit_gigabytes = 32
labels = {
"foo" = "bar"
}
}

# Only use the import statement, if you want to import an existing sfs share
Expand Down Expand Up @@ -49,6 +52,7 @@ import {
Note that if this is set to an empty string, the Share can only be mounted in read only by
clients with IPs matching the IP ACL of the Resource Pool hosting this Share.
You can also assign a Share Export Policy after creating the Share
- `labels` (Map of String) Labels are key-value string pairs which can be attached to the resource.
- `region` (String) The resource region. If not defined, the provider region is used.

### Read-Only
Expand Down
5 changes: 4 additions & 1 deletion examples/resources/stackit_sfs_export_policy/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ resource "stackit_sfs_export_policy" "example" {
order = 1
}
]
labels = {
"foo" = "bar"
}
}

# Only use the import statement, if you want to import an existing export policy
import {
to = stackit_sfs_export_policy.example
id = "${var.project_id},${var.region},${var.policy_id}"
}
}
5 changes: 4 additions & 1 deletion examples/resources/stackit_sfs_resource_pool/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ resource "stackit_sfs_resource_pool" "resourcepool" {
"192.168.42.2/32"
]
snapshots_are_visible = true
labels = {
"foo" = "bar"
}
}

# Only use the import statement, if you want to import an existing resource pool
import {
to = stackit_sfs_resource_pool.resourcepool
id = "${var.project_id},${var.region},${var.resource_pool_id}"
}
}
5 changes: 4 additions & 1 deletion examples/resources/stackit_sfs_share/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ resource "stackit_sfs_share" "example" {
name = "my-nfs-share"
export_policy = "high-performance-class"
space_hard_limit_gigabytes = 32
labels = {
"foo" = "bar"
}
}

# Only use the import statement, if you want to import an existing sfs share
import {
to = stackit_sfs_resource_pool.resourcepool
id = "${var.project_id},${var.region},${var.resource_pool_id},${var.share_id}"
}
}
5 changes: 5 additions & 0 deletions stackit/internal/services/sfs/export-policy/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ func (d *exportPolicyDataSource) Schema(_ context.Context, _ datasource.SchemaRe
Description: "Name of the export policy.",
Computed: true,
},
"labels": schema.MapAttribute{
Description: "Labels are key-value string pairs which can be attached to an export policy",
ElementType: types.StringType,
Computed: true,
},
"rules": schema.ListNestedAttribute{
Computed: true,
NestedObject: schema.NestedAttributeObject{
Expand Down
37 changes: 31 additions & 6 deletions stackit/internal/services/sfs/export-policy/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type Model struct {
ProjectId types.String `tfsdk:"project_id"`
ExportPolicyId types.String `tfsdk:"policy_id"`
Name types.String `tfsdk:"name"`
Labels types.Map `tfsdk:"labels"`
Rules types.List `tfsdk:"rules"`
Region types.String `tfsdk:"region"`
}
Expand Down Expand Up @@ -188,6 +189,12 @@ func (r *exportPolicyResource) Schema(_ context.Context, _ resource.SchemaReques
stringvalidator.LengthAtLeast(1),
},
},
"labels": schema.MapAttribute{
Description: "Labels are key-value string pairs which can be attached to the resource.",
ElementType: types.StringType,
Optional: true,
Validators: validate.LabelValidators(),
},
"rules": schema.ListNestedAttribute{
Computed: true,
Optional: true,
Expand Down Expand Up @@ -269,7 +276,7 @@ func (r *exportPolicyResource) Create(ctx context.Context, req resource.CreateRe
}
}

payload, err := toCreatePayload(&model, rules)
payload, err := toCreatePayload(ctx, &model, rules)
if err != nil {
core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating export policy", fmt.Sprintf("Creating API payload: %v", err))
return
Expand Down Expand Up @@ -400,7 +407,7 @@ func (r *exportPolicyResource) Update(ctx context.Context, req resource.UpdateRe
}
}

payload, err := toUpdatePayload(&model, rules)
payload, err := toUpdatePayload(ctx, &model, rules)
if err != nil {
core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating export policy", fmt.Sprintf("Creating API payload: %v", err))
return
Expand Down Expand Up @@ -511,6 +518,12 @@ func mapFields(ctx context.Context, resp *sfs.GetShareExportPolicyResponse, mode
return fmt.Errorf("export policy id not present")
}

labels, err := utils.MapLabels(ctx, resp.ShareExportPolicy.Labels, model.Labels)
if err != nil {
return err
}
model.Labels = labels

// iterate over Rules from response
if resp.ShareExportPolicy.Rules != nil {
rulesList := []attr.Value{}
Expand Down Expand Up @@ -564,14 +577,19 @@ func mapFields(ctx context.Context, resp *sfs.GetShareExportPolicyResponse, mode
}

// Build a CreateShareExportPolicyPayload from provider's model
func toCreatePayload(model *Model, rules []rulesModel) (*sfs.CreateShareExportPolicyPayload, error) {
func toCreatePayload(ctx context.Context, model *Model, rules []rulesModel) (*sfs.CreateShareExportPolicyPayload, error) {
if model == nil {
return nil, fmt.Errorf("nil model")
}
if rules == nil {
return nil, fmt.Errorf("nil rules")
}

labels, err := utils.LabelsToPayload(ctx, model.Labels)
if err != nil {
return nil, err
}

// iterate over rules
var tempRules []sfs.CreateShareExportPolicyRequestRule
for _, rule := range rules {
Expand All @@ -593,7 +611,8 @@ func toCreatePayload(model *Model, rules []rulesModel) (*sfs.CreateShareExportPo

// name and rules
result := &sfs.CreateShareExportPolicyPayload{
Name: model.Name.ValueString(),
Name: model.Name.ValueString(),
Labels: &labels,
}

// Rules should only be set if tempRules has value. Otherwise, the payload would contain `{ "rules": null }` what should be prevented
Expand All @@ -604,14 +623,19 @@ func toCreatePayload(model *Model, rules []rulesModel) (*sfs.CreateShareExportPo
return result, nil
}

func toUpdatePayload(model *Model, rules []rulesModel) (*sfs.UpdateShareExportPolicyPayload, error) {
func toUpdatePayload(ctx context.Context, model *Model, rules []rulesModel) (*sfs.UpdateShareExportPolicyPayload, error) {
if model == nil {
return nil, fmt.Errorf("nil model")
}
if rules == nil {
return nil, fmt.Errorf("nil rules")
}

labels, err := utils.LabelsToPayload(ctx, model.Labels)
if err != nil {
return nil, err
}

// iterate over rules
tempRules := make([]sfs.UpdateShareExportPolicyBodyRule, len(rules))
for i, rule := range rules {
Expand All @@ -635,7 +659,8 @@ func toUpdatePayload(model *Model, rules []rulesModel) (*sfs.UpdateShareExportPo
result := &sfs.UpdateShareExportPolicyPayload{
// Rules should *+never** result in a payload where they are defined as null, e.g. `{ "rules": null }`. Instead,
// they should either be set to an array (with values or empty) or they shouldn't be present in the payload.
Rules: tempRules,
Rules: tempRules,
Labels: &labels,
}
return result, nil
}
Loading
Loading