Skip to content

Commit d3752dd

Browse files
committed
feat(resourcemanager): add created_at and updated_at attributes to resourcemanager project/folder
Signed-off-by: Mauritz Uphoff <mauritz.uphoff@stackit.cloud>
1 parent 0ed9be7 commit d3752dd

File tree

11 files changed

+276
-102
lines changed

11 files changed

+276
-102
lines changed

docs/data-sources/resourcemanager_folder.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ data "stackit_resourcemanager_folder" "example" {
2727

2828
### Read-Only
2929

30+
- `creation_time` (String) Date-time at which the folder was created.
3031
- `id` (String) Terraform's internal resource ID. It is structured as "`container_id`".
3132
- `labels` (Map of String) Labels are key-value string pairs which can be attached to a resource container. A label key must match the regex [A-ZÄÜÖa-zäüöß0-9_-]{1,64}. A label value must match the regex ^$|[A-ZÄÜÖa-zäüöß0-9_-]{1,64}.
3233
- `name` (String) The name of the folder.
3334
- `parent_container_id` (String) Parent resource identifier. Both container ID (user-friendly) and UUID are supported.
35+
- `update_time` (String) Date-time at which the folder was last modified.

docs/data-sources/resourcemanager_project.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ data "stackit_resourcemanager_project" "example" {
2929

3030
### Read-Only
3131

32+
- `creation_time` (String) Date-time at which the folder was created.
3233
- `id` (String) Terraform's internal data source. ID. It is structured as "`container_id`".
3334
- `labels` (Map of String) Labels are key-value string pairs which can be attached to a resource container. A label key must match the regex [A-ZÄÜÖa-zäüöß0-9_-]{1,64}. A label value must match the regex ^$|[A-ZÄÜÖa-zäüöß0-9_-]{1,64}
3435
- `name` (String) Project name.
3536
- `parent_container_id` (String) Parent resource identifier. Both container ID (user-friendly) and UUID are supported
37+
- `update_time` (String) Date-time at which the folder was last modified.

docs/resources/resourcemanager_folder.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,6 @@ resource "stackit_resourcemanager_folder" "example" {
3939
### Read-Only
4040

4141
- `container_id` (String) Folder container ID. Globally unique, user-friendly identifier.
42+
- `creation_time` (String) Date-time at which the folder was created.
4243
- `id` (String) Terraform's internal resource ID. It is structured as "`container_id`".
44+
- `update_time` (String) Date-time at which the folder was last modified.

docs/resources/resourcemanager_project.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,7 @@ To create a project within a STACKIT Network Area, setting the label `networkAre
5252
### Read-Only
5353

5454
- `container_id` (String) Project container ID. Globally unique, user-friendly identifier.
55+
- `creation_time` (String) Date-time at which the folder was created.
5556
- `id` (String) Terraform's internal resource ID. It is structured as "`container_id`".
5657
- `project_id` (String) Project UUID identifier. This is the ID that can be used in most of the other resources to identify the project.
58+
- `update_time` (String) Date-time at which the folder was last modified.

stackit/internal/services/resourcemanager/folder/datasource.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ func (d *folderDataSource) Schema(_ context.Context, _ datasource.SchemaRequest,
7171
"name": "The name of the folder.",
7272
"labels": "Labels are key-value string pairs which can be attached to a resource container. A label key must match the regex [A-ZÄÜÖa-zäüöß0-9_-]{1,64}. A label value must match the regex ^$|[A-ZÄÜÖa-zäüöß0-9_-]{1,64}.",
7373
"owner_email": "Email address of the owner of the folder. This value is only considered during creation. Changing it afterwards will have no effect.",
74+
"creation_time": "Date-time at which the folder was created.",
75+
"update_time": "Date-time at which the folder was last modified.",
7476
}
7577

7678
resp.Schema = schema.Schema{
@@ -119,6 +121,14 @@ func (d *folderDataSource) Schema(_ context.Context, _ datasource.SchemaRequest,
119121
),
120122
},
121123
},
124+
"creation_time": schema.StringAttribute{
125+
Description: descriptions["creation_time"],
126+
Computed: true,
127+
},
128+
"update_time": schema.StringAttribute{
129+
Description: descriptions["update_time"],
130+
Computed: true,
131+
},
122132
},
123133
}
124134
}

stackit/internal/services/resourcemanager/folder/resource.go

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ type Model struct {
4949
ContainerParentId types.String `tfsdk:"parent_container_id"`
5050
Name types.String `tfsdk:"name"`
5151
Labels types.Map `tfsdk:"labels"`
52+
CreationTime types.String `tfsdk:"creation_time"`
53+
UpdateTime types.String `tfsdk:"update_time"`
5254
}
5355

5456
type ResourceModel struct {
@@ -101,6 +103,8 @@ func (r *folderResource) Schema(_ context.Context, _ resource.SchemaRequest, res
101103
"name": "The name of the folder.",
102104
"labels": "Labels are key-value string pairs which can be attached to a resource container. A label key must match the regex [A-ZÄÜÖa-zäüöß0-9_-]{1,64}. A label value must match the regex ^$|[A-ZÄÜÖa-zäüöß0-9_-]{1,64}.",
103105
"owner_email": "Email address of the owner of the folder. This value is only considered during creation. Changing it afterwards will have no effect.",
106+
"creation_time": "Date-time at which the folder was created.",
107+
"update_time": "Date-time at which the folder was last modified.",
104108
}
105109

106110
resp.Schema = schema.Schema{
@@ -159,6 +163,14 @@ func (r *folderResource) Schema(_ context.Context, _ resource.SchemaRequest, res
159163
Description: descriptions["owner_email"],
160164
Required: true,
161165
},
166+
"creation_time": schema.StringAttribute{
167+
Description: descriptions["creation_time"],
168+
Computed: true,
169+
},
170+
"update_time": schema.StringAttribute{
171+
Description: descriptions["update_time"],
172+
Computed: true,
173+
},
162174
},
163175
}
164176
}
@@ -337,7 +349,16 @@ func (r *folderResource) ImportState(ctx context.Context, req resource.ImportSta
337349
}
338350

339351
// mapFolderFields maps folder fields from a response into the Terraform model and optionally updates state.
340-
func mapFolderFields(ctx context.Context, containerId, name *string, labels *map[string]string, containerParent *resourcemanager.Parent, model *Model, state *tfsdk.State) error { //nolint:gocritic
352+
func mapFolderFields(
353+
ctx context.Context,
354+
containerId, name *string,
355+
labels *map[string]string, //nolint:gocritic
356+
containerParent *resourcemanager.Parent,
357+
creationTime *time.Time,
358+
updateTime *time.Time,
359+
model *Model,
360+
state *tfsdk.State,
361+
) error {
341362
if containerId == nil || *containerId == "" {
342363
return fmt.Errorf("container id is present")
343364
}
@@ -371,6 +392,8 @@ func mapFolderFields(ctx context.Context, containerId, name *string, labels *map
371392
model.ContainerParentId = containerParentIdTF
372393
model.Name = types.StringPointerValue(name)
373394
model.Labels = tfLabels
395+
model.CreationTime = types.StringValue(creationTime.Format(time.RFC3339))
396+
model.UpdateTime = types.StringValue(updateTime.Format(time.RFC3339))
374397

375398
if state != nil {
376399
diags := diag.Diagnostics{}
@@ -379,6 +402,8 @@ func mapFolderFields(ctx context.Context, containerId, name *string, labels *map
379402
diags.Append(state.SetAttribute(ctx, path.Root("container_id"), model.ContainerId)...)
380403
diags.Append(state.SetAttribute(ctx, path.Root("name"), model.Name)...)
381404
diags.Append(state.SetAttribute(ctx, path.Root("labels"), model.Labels)...)
405+
diags.Append(state.SetAttribute(ctx, path.Root("creation_time"), model.CreationTime)...)
406+
diags.Append(state.SetAttribute(ctx, path.Root("update_time"), model.UpdateTime)...)
382407
if diags.HasError() {
383408
return fmt.Errorf("update terraform state: %w", core.DiagsToError(diags))
384409
}
@@ -389,12 +414,12 @@ func mapFolderFields(ctx context.Context, containerId, name *string, labels *map
389414

390415
// mapFolderCreateFields maps the Create Folder API response to the Terraform model and update the Terraform state
391416
func mapFolderCreateFields(ctx context.Context, resp *resourcemanager.FolderResponse, model *Model, state *tfsdk.State) error {
392-
return mapFolderFields(ctx, resp.ContainerId, resp.Name, resp.Labels, resp.Parent, model, state)
417+
return mapFolderFields(ctx, resp.ContainerId, resp.Name, resp.Labels, resp.Parent, resp.CreationTime, resp.UpdateTime, model, state)
393418
}
394419

395420
// mapFolderDetailsFields maps the GetDetails API response to the Terraform model and update the Terraform state
396421
func mapFolderDetailsFields(ctx context.Context, resp *resourcemanager.GetFolderDetailsResponse, model *Model, state *tfsdk.State) error {
397-
return mapFolderFields(ctx, resp.ContainerId, resp.Name, resp.Labels, resp.Parent, model, state)
422+
return mapFolderFields(ctx, resp.ContainerId, resp.Name, resp.Labels, resp.Parent, resp.CreationTime, resp.UpdateTime, model, state)
398423
}
399424

400425
func toMembersPayload(model *ResourceModel) (*[]resourcemanager.Member, error) {

0 commit comments

Comments
 (0)