Skip to content

Commit d3fce24

Browse files
committed
feat(objectstorage): Min/Max acceptance tests
Signed-off-by: Alexander Dahmen <alexander.dahmen@inovex.de>
1 parent ab7245c commit d3fce24

12 files changed

Lines changed: 179 additions & 122 deletions

File tree

docs/data-sources/objectstorage_credentials_group.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ data "stackit_objectstorage_credentials_group" "example" {
2424

2525
### Required
2626

27+
- `credentials_group_id` (String) The credentials group ID.
2728
- `project_id` (String) Object Storage Project ID to which the credentials group is associated.
2829

2930
### Optional
3031

31-
- `credentials_group_id` (String) The credentials group ID.
32-
- `name` (String) The credentials group's display name.
3332
- `region` (String) The resource region. If not defined, the provider region is used.
3433

3534
### Read-Only
3635

3736
- `id` (String) Terraform's internal data source identifier. It is structured as "`project_id`,`credentials_group_id`".
37+
- `name` (String) The credentials group's display name.
3838
- `urn` (String) Credentials group uniform resource name (URN)

stackit/internal/services/objectstorage/bucket/resource.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,16 +304,17 @@ func (r *bucketResource) Delete(ctx context.Context, req resource.DeleteRequest,
304304
// The expected format of the resource import identifier is: project_id,name
305305
func (r *bucketResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
306306
idParts := strings.Split(req.ID, core.Separator)
307-
if len(idParts) != 2 || idParts[0] == "" || idParts[1] == "" {
307+
if len(idParts) != 3 || idParts[0] == "" || idParts[1] == "" || idParts[2] == "" {
308308
core.LogAndAddError(ctx, &resp.Diagnostics,
309309
"Error importing bucket",
310-
fmt.Sprintf("Expected import identifier with format [project_id],[name], got %q", req.ID),
310+
fmt.Sprintf("Expected import identifier with format [project_id],[region],[name], got %q", req.ID),
311311
)
312312
return
313313
}
314314

315315
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("project_id"), idParts[0])...)
316-
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("name"), idParts[1])...)
316+
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("region"), idParts[1])...)
317+
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("name"), idParts[2])...)
317318
tflog.Info(ctx, "ObjectStorage bucket state imported")
318319
}
319320

@@ -331,6 +332,7 @@ func mapFields(bucketResp *objectstorage.GetBucketResponse, model *Model, region
331332

332333
idParts := []string{
333334
model.ProjectId.ValueString(),
335+
region,
334336
model.Name.ValueString(),
335337
}
336338
model.Id = types.StringValue(

stackit/internal/services/objectstorage/bucket/resource_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ func (c *objectStorageClientMocked) EnableServiceExecute(_ context.Context, proj
2727
}
2828

2929
func TestMapFields(t *testing.T) {
30+
const testRegion = "eu01"
31+
id := fmt.Sprintf("%s,%s,%s", "pid", testRegion, "bname")
3032
tests := []struct {
3133
description string
3234
input *objectstorage.GetBucketResponse
@@ -39,7 +41,7 @@ func TestMapFields(t *testing.T) {
3941
Bucket: &objectstorage.Bucket{},
4042
},
4143
Model{
42-
Id: types.StringValue("pid,bname"),
44+
Id: types.StringValue(id),
4345
Name: types.StringValue("bname"),
4446
ProjectId: types.StringValue("pid"),
4547
URLPathStyle: types.StringNull(),
@@ -57,7 +59,7 @@ func TestMapFields(t *testing.T) {
5759
},
5860
},
5961
Model{
60-
Id: types.StringValue("pid,bname"),
62+
Id: types.StringValue(id),
6163
Name: types.StringValue("bname"),
6264
ProjectId: types.StringValue("pid"),
6365
URLPathStyle: types.StringValue("url/path/style"),
@@ -75,7 +77,7 @@ func TestMapFields(t *testing.T) {
7577
},
7678
},
7779
Model{
78-
Id: types.StringValue("pid,bname"),
80+
Id: types.StringValue(id),
7981
Name: types.StringValue("bname"),
8082
ProjectId: types.StringValue("pid"),
8183
URLPathStyle: types.StringValue(""),

stackit/internal/services/objectstorage/credential/datasource.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ func mapDataSourceFields(credentialResp *objectstorage.AccessKey, model *DataSou
208208

209209
idParts := []string{
210210
model.ProjectId.ValueString(),
211+
region,
211212
model.CredentialsGroupId.ValueString(),
212213
credentialId,
213214
}

stackit/internal/services/objectstorage/credential/datasource_test.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package objectstorage
22

33
import (
4+
"fmt"
45
"testing"
56
"time"
67

@@ -13,6 +14,8 @@ import (
1314
func TestMapDatasourceFields(t *testing.T) {
1415
now := time.Now()
1516

17+
const testRegion = "eu01"
18+
id := fmt.Sprintf("%s,%s,%s", "pid", testRegion, "cgid,cid")
1619
tests := []struct {
1720
description string
1821
input *objectstorage.AccessKey
@@ -23,7 +26,7 @@ func TestMapDatasourceFields(t *testing.T) {
2326
"default_values",
2427
&objectstorage.AccessKey{},
2528
DataSourceModel{
26-
Id: types.StringValue("pid,cgid,cid"),
29+
Id: types.StringValue(id),
2730
ProjectId: types.StringValue("pid"),
2831
CredentialsGroupId: types.StringValue("cgid"),
2932
CredentialId: types.StringValue("cid"),
@@ -40,7 +43,7 @@ func TestMapDatasourceFields(t *testing.T) {
4043
Expires: utils.Ptr(now.Format(time.RFC3339)),
4144
},
4245
DataSourceModel{
43-
Id: types.StringValue("pid,cgid,cid"),
46+
Id: types.StringValue(id),
4447
ProjectId: types.StringValue("pid"),
4548
CredentialsGroupId: types.StringValue("cgid"),
4649
CredentialId: types.StringValue("cid"),
@@ -56,7 +59,7 @@ func TestMapDatasourceFields(t *testing.T) {
5659
DisplayName: utils.Ptr(""),
5760
},
5861
DataSourceModel{
59-
Id: types.StringValue("pid,cgid,cid"),
62+
Id: types.StringValue(id),
6063
ProjectId: types.StringValue("pid"),
6164
CredentialsGroupId: types.StringValue("cgid"),
6265
CredentialId: types.StringValue("cid"),
@@ -72,7 +75,7 @@ func TestMapDatasourceFields(t *testing.T) {
7275
Expires: utils.Ptr(now.Format(time.RFC3339Nano)),
7376
},
7477
DataSourceModel{
75-
Id: types.StringValue("pid,cgid,cid"),
78+
Id: types.StringValue(id),
7679
ProjectId: types.StringValue("pid"),
7780
CredentialsGroupId: types.StringValue("cgid"),
7881
CredentialId: types.StringValue("cid"),

stackit/internal/services/objectstorage/credential/resource.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -424,17 +424,18 @@ func (r *credentialResource) Delete(ctx context.Context, req resource.DeleteRequ
424424
// The expected format of the resource import identifier is: project_id,credentials_group_id,credential_id
425425
func (r *credentialResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
426426
idParts := strings.Split(req.ID, core.Separator)
427-
if len(idParts) != 3 || idParts[0] == "" || idParts[1] == "" || idParts[2] == "" {
427+
if len(idParts) != 4 || idParts[0] == "" || idParts[1] == "" || idParts[2] == "" || idParts[3] == "" {
428428
core.LogAndAddError(ctx, &resp.Diagnostics,
429429
"Error importing credential",
430-
fmt.Sprintf("Expected import identifier with format [project_id],[credentials_group_id],[credential_id], got %q", req.ID),
430+
fmt.Sprintf("Expected import identifier with format [project_id],[region],[credentials_group_id],[credential_id], got %q", req.ID),
431431
)
432432
return
433433
}
434434

435435
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("project_id"), idParts[0])...)
436-
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("credentials_group_id"), idParts[1])...)
437-
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("credential_id"), idParts[2])...)
436+
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("region"), idParts[1])...)
437+
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("credentials_group_id"), idParts[2])...)
438+
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("credential_id"), idParts[3])...)
438439
tflog.Info(ctx, "ObjectStorage credential state imported")
439440
}
440441

@@ -507,6 +508,7 @@ func mapFields(credentialResp *objectstorage.CreateAccessKeyResponse, model *Mod
507508

508509
idParts := []string{
509510
model.ProjectId.ValueString(),
511+
region,
510512
model.CredentialsGroupId.ValueString(),
511513
credentialId,
512514
}
@@ -551,6 +553,7 @@ func readCredentials(ctx context.Context, model *Model, region string, client *o
551553

552554
idParts := []string{
553555
projectId,
556+
region,
554557
credentialsGroupId,
555558
credentialId,
556559
}

stackit/internal/services/objectstorage/credential/resource_test.go

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ func (c *objectStorageClientMocked) EnableServiceExecute(_ context.Context, proj
3232

3333
func TestMapFields(t *testing.T) {
3434
now := time.Now()
35-
35+
const testRegion = "eu01"
36+
id := fmt.Sprintf("%s,%s,%s", "pid", testRegion, "cgid,cid")
3637
tests := []struct {
3738
description string
3839
input *objectstorage.CreateAccessKeyResponse
@@ -43,7 +44,7 @@ func TestMapFields(t *testing.T) {
4344
"default_values",
4445
&objectstorage.CreateAccessKeyResponse{},
4546
Model{
46-
Id: types.StringValue("pid,cgid,cid"),
47+
Id: types.StringValue(id),
4748
ProjectId: types.StringValue("pid"),
4849
CredentialsGroupId: types.StringValue("cgid"),
4950
CredentialId: types.StringValue("cid"),
@@ -64,7 +65,7 @@ func TestMapFields(t *testing.T) {
6465
SecretAccessKey: utils.Ptr("secret-key"),
6566
},
6667
Model{
67-
Id: types.StringValue("pid,cgid,cid"),
68+
Id: types.StringValue(id),
6869
ProjectId: types.StringValue("pid"),
6970
CredentialsGroupId: types.StringValue("cgid"),
7071
CredentialId: types.StringValue("cid"),
@@ -84,7 +85,7 @@ func TestMapFields(t *testing.T) {
8485
SecretAccessKey: utils.Ptr(""),
8586
},
8687
Model{
87-
Id: types.StringValue("pid,cgid,cid"),
88+
Id: types.StringValue(id),
8889
ProjectId: types.StringValue("pid"),
8990
CredentialsGroupId: types.StringValue("cgid"),
9091
CredentialId: types.StringValue("cid"),
@@ -102,7 +103,7 @@ func TestMapFields(t *testing.T) {
102103
Expires: utils.Ptr(now.Format(time.RFC3339Nano)),
103104
},
104105
Model{
105-
Id: types.StringValue("pid,cgid,cid"),
106+
Id: types.StringValue(id),
106107
ProjectId: types.StringValue("pid"),
107108
CredentialsGroupId: types.StringValue("cgid"),
108109
CredentialId: types.StringValue("cid"),
@@ -153,6 +154,8 @@ func TestMapFields(t *testing.T) {
153154
}
154155

155156
func TestEnableProject(t *testing.T) {
157+
const testRegion = "eu01"
158+
id := fmt.Sprintf("%s,%s,%s", "pid", testRegion, "cgid,cid")
156159
tests := []struct {
157160
description string
158161
expected Model
@@ -162,7 +165,7 @@ func TestEnableProject(t *testing.T) {
162165
{
163166
"default_values",
164167
Model{
165-
Id: types.StringValue("pid,cgid,cid"),
168+
Id: types.StringValue(id),
166169
ProjectId: types.StringValue("pid"),
167170
CredentialsGroupId: types.StringValue("cgid"),
168171
CredentialId: types.StringValue("cid"),
@@ -177,7 +180,7 @@ func TestEnableProject(t *testing.T) {
177180
{
178181
"error_response",
179182
Model{
180-
Id: types.StringValue("pid,cgid,cid"),
183+
Id: types.StringValue(id),
181184
ProjectId: types.StringValue("pid"),
182185
CredentialsGroupId: types.StringValue("cgid"),
183186
CredentialId: types.StringValue("cid"),
@@ -213,7 +216,8 @@ func TestEnableProject(t *testing.T) {
213216

214217
func TestReadCredentials(t *testing.T) {
215218
now := time.Now()
216-
219+
const testRegion = "eu01"
220+
id := fmt.Sprintf("%s,%s,%s", "pid", testRegion, "cgid,cid")
217221
tests := []struct {
218222
description string
219223
mockedResp *objectstorage.ListAccessKeysResponse
@@ -238,7 +242,7 @@ func TestReadCredentials(t *testing.T) {
238242
},
239243
},
240244
Model{
241-
Id: types.StringValue("pid,cgid,cid"),
245+
Id: types.StringValue(id),
242246
ProjectId: types.StringValue("pid"),
243247
CredentialsGroupId: types.StringValue("cgid"),
244248
CredentialId: types.StringValue("cid"),
@@ -274,7 +278,7 @@ func TestReadCredentials(t *testing.T) {
274278
},
275279
},
276280
Model{
277-
Id: types.StringValue("pid,cgid,cid"),
281+
Id: types.StringValue(id),
278282
ProjectId: types.StringValue("pid"),
279283
CredentialsGroupId: types.StringValue("cgid"),
280284
CredentialId: types.StringValue("cid"),
@@ -310,7 +314,7 @@ func TestReadCredentials(t *testing.T) {
310314
},
311315
},
312316
Model{
313-
Id: types.StringValue("pid,cgid,cid"),
317+
Id: types.StringValue(id),
314318
ProjectId: types.StringValue("pid"),
315319
CredentialsGroupId: types.StringValue("cgid"),
316320
CredentialId: types.StringValue("cid"),

stackit/internal/services/objectstorage/credentialsgroup/datasource.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ func (r *credentialsGroupDataSource) Schema(_ context.Context, _ datasource.Sche
7777
},
7878
"credentials_group_id": schema.StringAttribute{
7979
Description: descriptions["credentials_group_id"],
80-
Optional: true,
81-
Computed: true,
80+
Required: true,
8281
},
8382
"project_id": schema.StringAttribute{
8483
Description: descriptions["project_id"],
@@ -90,7 +89,6 @@ func (r *credentialsGroupDataSource) Schema(_ context.Context, _ datasource.Sche
9089
},
9190
"name": schema.StringAttribute{
9291
Description: descriptions["name"],
93-
Optional: true,
9492
Computed: true,
9593
},
9694
"urn": schema.StringAttribute{

stackit/internal/services/objectstorage/credentialsgroup/resource.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -291,16 +291,17 @@ func (r *credentialsGroupResource) Delete(ctx context.Context, req resource.Dele
291291
// The expected format of the resource import identifier is: project_id, credentials_group_id
292292
func (r *credentialsGroupResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
293293
idParts := strings.Split(req.ID, core.Separator)
294-
if len(idParts) != 2 || idParts[0] == "" || idParts[1] == "" {
294+
if len(idParts) != 3 || idParts[0] == "" || idParts[1] == "" || idParts[2] == "" {
295295
core.LogAndAddError(ctx, &resp.Diagnostics,
296296
"Error importing credentialsGroup",
297-
fmt.Sprintf("Expected import identifier with format [project_id],[credentials_group_id], got %q", req.ID),
297+
fmt.Sprintf("Expected import identifier with format [project_id],[region],[credentials_group_id], got %q", req.ID),
298298
)
299299
return
300300
}
301301

302302
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("project_id"), idParts[0])...)
303-
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("credentials_group_id"), idParts[1])...)
303+
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("region"), idParts[1])...)
304+
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("credentials_group_id"), idParts[2])...)
304305
tflog.Info(ctx, "ObjectStorage credentials group state imported")
305306
}
306307

@@ -316,15 +317,15 @@ func mapFields(credentialsGroupResp *objectstorage.CreateCredentialsGroupRespons
316317
}
317318
credentialsGroup := credentialsGroupResp.CredentialsGroup
318319

319-
err := mapCredentialsGroup(*credentialsGroup, model)
320+
err := mapCredentialsGroup(*credentialsGroup, model, region)
320321
if err != nil {
321322
return err
322323
}
323324
model.Region = types.StringValue(region)
324325
return nil
325326
}
326327

327-
func mapCredentialsGroup(credentialsGroup objectstorage.CredentialsGroup, model *Model) error {
328+
func mapCredentialsGroup(credentialsGroup objectstorage.CredentialsGroup, model *Model, region string) error {
328329
var credentialsGroupId string
329330
if !coreutils.IsUndefined(model.CredentialsGroupId) {
330331
credentialsGroupId = model.CredentialsGroupId.ValueString()
@@ -336,6 +337,7 @@ func mapCredentialsGroup(credentialsGroup objectstorage.CredentialsGroup, model
336337

337338
idParts := []string{
338339
model.ProjectId.ValueString(),
340+
region,
339341
credentialsGroupId,
340342
}
341343
model.Id = types.StringValue(
@@ -392,7 +394,7 @@ func readCredentialsGroups(ctx context.Context, model *Model, region string, cli
392394
continue
393395
}
394396
found = true
395-
err = mapCredentialsGroup(credentialsGroup, model)
397+
err = mapCredentialsGroup(credentialsGroup, model, region)
396398
if err != nil {
397399
return found, err
398400
}

0 commit comments

Comments
 (0)