Skip to content

Commit bc2d5ff

Browse files
committed
fixup
Signed-off-by: Alexander Dahmen <alexander.dahmen@inovex.de>
1 parent 958b44c commit bc2d5ff

7 files changed

Lines changed: 88 additions & 37 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/credential/resource.go

Lines changed: 6 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
}

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: 5 additions & 3 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

@@ -336,6 +337,7 @@ func mapCredentialsGroup(credentialsGroup objectstorage.CredentialsGroup, model
336337

337338
idParts := []string{
338339
model.ProjectId.ValueString(),
340+
model.Region.ValueString(),
339341
credentialsGroupId,
340342
}
341343
model.Id = types.StringValue(

stackit/internal/services/objectstorage/objectstorage_acc_test.go

Lines changed: 64 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"strings"
88
"testing"
9+
"time"
910

1011
"github.com/hashicorp/terraform-plugin-testing/config"
1112
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
@@ -27,7 +28,7 @@ var testConfigVarsMin = config.Variables{
2728
"project_id": config.StringVariable(testutil.ProjectId),
2829
"objectstorage_bucket_name": config.StringVariable(fmt.Sprintf("tf-acc-test-%s", acctest.RandStringFromCharSet(20, acctest.CharSetAlpha))),
2930
"objectstorage_credentials_group_name": config.StringVariable(fmt.Sprintf("tf-acc-test-%s", acctest.RandStringFromCharSet(20, acctest.CharSetAlpha))),
30-
"expiration_timestamp": config.StringVariable("2027-01-02T03:04:05Z"),
31+
"expiration_timestamp": config.StringVariable(fmt.Sprintf("%d-01-02T03:04:05Z", time.Now().Year()+1)),
3132
}
3233

3334
func TestAccObjectStorageResourceMin(t *testing.T) {
@@ -62,33 +63,53 @@ func TestAccObjectStorageResourceMin(t *testing.T) {
6263
"stackit_objectstorage_credentials_group.credentials_group", "credentials_group_id",
6364
),
6465
resource.TestCheckResourceAttrSet("stackit_objectstorage_credential.credential", "credential_id"),
65-
resource.TestCheckResourceAttr("stackit_objectstorage_credential.credential", "expiration_timestamp", testutil.ConvertConfigVariable(testConfigVarsMin["expiration_timestamp"])),
6666
resource.TestCheckResourceAttrSet("stackit_objectstorage_credential.credential", "name"),
6767
resource.TestCheckResourceAttrSet("stackit_objectstorage_credential.credential", "access_key"),
6868
resource.TestCheckResourceAttrSet("stackit_objectstorage_credential.credential", "secret_access_key"),
69+
70+
// credential_time data
71+
resource.TestCheckResourceAttrPair(
72+
"stackit_objectstorage_credential.credential_time", "project_id",
73+
"stackit_objectstorage_credentials_group.credentials_group", "project_id",
74+
),
75+
resource.TestCheckResourceAttrPair(
76+
"stackit_objectstorage_credential.credential_time", "credentials_group_id",
77+
"stackit_objectstorage_credentials_group.credentials_group", "credentials_group_id",
78+
),
79+
resource.TestCheckResourceAttrSet("stackit_objectstorage_credential.credential_time", "credential_id"),
80+
resource.TestCheckResourceAttr("stackit_objectstorage_credential.credential_time", "expiration_timestamp", testutil.ConvertConfigVariable(testConfigVarsMin["expiration_timestamp"])),
81+
resource.TestCheckResourceAttrSet("stackit_objectstorage_credential.credential_time", "name"),
82+
resource.TestCheckResourceAttrSet("stackit_objectstorage_credential.credential_time", "access_key"),
83+
resource.TestCheckResourceAttrSet("stackit_objectstorage_credential.credential_time", "secret_access_key"),
6984
),
7085
},
7186
// Data source
7287
{
7388
ConfigVariables: testConfigVarsMin,
7489
Config: fmt.Sprintf(`
75-
%s
90+
%s
7691
77-
data "stackit_objectstorage_bucket" "bucket" {
78-
project_id = stackit_objectstorage_bucket.bucket.project_id
79-
name = stackit_objectstorage_bucket.bucket.name
80-
}
92+
data "stackit_objectstorage_bucket" "bucket" {
93+
project_id = stackit_objectstorage_bucket.bucket.project_id
94+
name = stackit_objectstorage_bucket.bucket.name
95+
}
8196
82-
data "stackit_objectstorage_credentials_group" "credentials_group" {
83-
project_id = stackit_objectstorage_credentials_group.credentials_group.project_id
84-
credentials_group_id = stackit_objectstorage_credentials_group.credentials_group.credentials_group_id
85-
}
97+
data "stackit_objectstorage_credentials_group" "credentials_group" {
98+
project_id = stackit_objectstorage_credentials_group.credentials_group.project_id
99+
credentials_group_id = stackit_objectstorage_credentials_group.credentials_group.credentials_group_id
100+
}
101+
102+
data "stackit_objectstorage_credential" "credential" {
103+
project_id = stackit_objectstorage_credential.credential.project_id
104+
credentials_group_id = stackit_objectstorage_credential.credential.credentials_group_id
105+
credential_id = stackit_objectstorage_credential.credential.credential_id
106+
}
86107
87-
data "stackit_objectstorage_credential" "credential" {
88-
project_id = stackit_objectstorage_credential.credential.project_id
89-
credentials_group_id = stackit_objectstorage_credential.credential.credentials_group_id
90-
credential_id = stackit_objectstorage_credential.credential.credential_id
91-
}`,
108+
data "stackit_objectstorage_credential" "credential_time" {
109+
project_id = stackit_objectstorage_credential.credential_time.project_id
110+
credentials_group_id = stackit_objectstorage_credential.credential_time.credentials_group_id
111+
credential_id = stackit_objectstorage_credential.credential_time.credential_id
112+
}`,
92113
testutil.ObjectStorageProviderConfig()+resourceMinConfig,
93114
),
94115
Check: resource.ComposeAggregateTestCheckFunc(
@@ -143,6 +164,28 @@ func TestAccObjectStorageResourceMin(t *testing.T) {
143164
"stackit_objectstorage_credential.credential", "expiration_timestamp",
144165
"data.stackit_objectstorage_credential.credential", "expiration_timestamp",
145166
),
167+
168+
// Credential_time data
169+
resource.TestCheckResourceAttrPair(
170+
"stackit_objectstorage_credential.credential_time", "project_id",
171+
"data.stackit_objectstorage_credential.credential_time", "project_id",
172+
),
173+
resource.TestCheckResourceAttrPair(
174+
"stackit_objectstorage_credential.credential_time", "credentials_group_id",
175+
"data.stackit_objectstorage_credential.credential_time", "credentials_group_id",
176+
),
177+
resource.TestCheckResourceAttrPair(
178+
"stackit_objectstorage_credential.credential_time", "credential_id",
179+
"data.stackit_objectstorage_credential.credential_time", "credential_id",
180+
),
181+
resource.TestCheckResourceAttrPair(
182+
"stackit_objectstorage_credential.credential_time", "name",
183+
"data.stackit_objectstorage_credential.credential_time", "name",
184+
),
185+
resource.TestCheckResourceAttrPair(
186+
"stackit_objectstorage_credential.credential_time", "expiration_timestamp",
187+
"data.stackit_objectstorage_credential.credential_time", "expiration_timestamp",
188+
),
146189
),
147190
},
148191
// Import
@@ -159,11 +202,10 @@ func TestAccObjectStorageResourceMin(t *testing.T) {
159202
return "", fmt.Errorf("couldn't find attribute credentials_group_id")
160203
}
161204

162-
return fmt.Sprintf("%s,%s", testutil.ProjectId, credentialsGroupId), nil
205+
return fmt.Sprintf("%s,%s,%s", testutil.ProjectId, testutil.Region, credentialsGroupId), nil
163206
},
164-
ImportState: true,
165-
ImportStateVerify: true,
166-
ImportStateVerifyIgnore: []string{"region"},
207+
ImportState: true,
208+
ImportStateVerify: true,
167209
},
168210
{
169211
ConfigVariables: testConfigVarsMin,
@@ -181,11 +223,11 @@ func TestAccObjectStorageResourceMin(t *testing.T) {
181223
if !ok {
182224
return "", fmt.Errorf("couldn't find attribute credential_id")
183225
}
184-
return fmt.Sprintf("%s,%s,%s", testutil.ProjectId, credentialsGroupId, credentialId), nil
226+
return fmt.Sprintf("%s,%s,%s,%s", testutil.ProjectId, testutil.Region, credentialsGroupId, credentialId), nil
185227
},
186228
ImportState: true,
187229
ImportStateVerify: true,
188-
ImportStateVerifyIgnore: []string{"access_key", "secret_access_key", "region"},
230+
ImportStateVerifyIgnore: []string{"access_key", "secret_access_key"},
189231
},
190232
// Deletion is done by the framework implicitly
191233
},

stackit/internal/services/objectstorage/testfiles/resource-min.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,10 @@ resource "stackit_objectstorage_credentials_group" "credentials_group" {
1717
resource "stackit_objectstorage_credential" "credential" {
1818
project_id = stackit_objectstorage_credentials_group.credentials_group.project_id
1919
credentials_group_id = stackit_objectstorage_credentials_group.credentials_group.credentials_group_id
20+
}
21+
22+
resource "stackit_objectstorage_credential" "credential_time" {
23+
project_id = stackit_objectstorage_credentials_group.credentials_group.project_id
24+
credentials_group_id = stackit_objectstorage_credentials_group.credentials_group.credentials_group_id
2025
expiration_timestamp = var.expiration_timestamp
2126
}

0 commit comments

Comments
 (0)