@@ -2,86 +2,53 @@ package objectstorage_test
22
33import (
44 "context"
5+ _ "embed"
56 "fmt"
67 "strings"
78 "testing"
89
10+ "github.com/hashicorp/terraform-plugin-testing/config"
911 "github.com/hashicorp/terraform-plugin-testing/helper/acctest"
1012 "github.com/hashicorp/terraform-plugin-testing/helper/resource"
1113 "github.com/hashicorp/terraform-plugin-testing/terraform"
12- "github.com/stackitcloud/stackit-sdk-go/core/config"
14+
15+ stackitSdkConfig "github.com/stackitcloud/stackit-sdk-go/core/config"
1316 "github.com/stackitcloud/stackit-sdk-go/core/utils"
1417 "github.com/stackitcloud/stackit-sdk-go/services/objectstorage"
1518 "github.com/stackitcloud/stackit-sdk-go/services/objectstorage/wait"
1619 "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core"
1720 "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/testutil"
1821)
1922
20- // Bucket resource data
21- var bucketResource = map [string ]string {
22- "project_id" : testutil .ProjectId ,
23- "name" : fmt .Sprintf ("acc-test-%s" , acctest .RandStringFromCharSet (20 , acctest .CharSetAlpha )),
24- }
25-
26- // Credentials group resource data
27- var credentialsGroupResource = map [string ]string {
28- "project_id" : testutil .ProjectId ,
29- "name" : fmt .Sprintf ("acc-test-%s" , acctest .RandStringFromCharSet (20 , acctest .CharSetAlpha )),
30- }
31-
32- // Credential resource data
33- var credentialResource = map [string ]string {
34- "expiration_timestamp" : "2027-01-02T03:04:05Z" ,
35- }
36-
37- func resourceConfig () string {
38- return fmt .Sprintf (`
39- %s
23+ //go:embed testfiles/resource-min.tf
24+ var resourceMinConfig string
4025
41- resource "stackit_objectstorage_bucket" "bucket" {
42- project_id = "%s"
43- name = "%s"
44- }
45-
46- resource "stackit_objectstorage_credentials_group" "credentials_group" {
47- project_id = "%s"
48- name = "%s"
49- }
50-
51- resource "stackit_objectstorage_credential" "credential" {
52- project_id = stackit_objectstorage_credentials_group.credentials_group.project_id
53- credentials_group_id = stackit_objectstorage_credentials_group.credentials_group.credentials_group_id
54- expiration_timestamp = "%s"
55- }
56- ` ,
57- testutil .ObjectStorageProviderConfig (),
58- bucketResource ["project_id" ],
59- bucketResource ["name" ],
60- credentialsGroupResource ["project_id" ],
61- credentialsGroupResource ["name" ],
62- credentialResource ["expiration_timestamp" ],
63- )
26+ var testConfigVarsMin = config.Variables {
27+ "project_id" : config .StringVariable (testutil .ProjectId ),
28+ "objectstorage_bucket_name" : config .StringVariable (fmt .Sprintf ("tf-acc-test-%s" , acctest .RandStringFromCharSet (20 , acctest .CharSetAlpha ))),
29+ "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" ),
6431}
6532
66- func TestAccObjectStorageResource (t * testing.T ) {
33+ func TestAccObjectStorageResourceMin (t * testing.T ) {
6734 resource .Test (t , resource.TestCase {
6835 ProtoV6ProviderFactories : testutil .TestAccProtoV6ProviderFactories ,
6936 CheckDestroy : testAccCheckObjectStorageDestroy ,
7037 Steps : []resource.TestStep {
71-
7238 // Creation
7339 {
74- Config : resourceConfig (),
40+ ConfigVariables : testConfigVarsMin ,
41+ Config : testutil .ObjectStorageProviderConfig () + resourceMinConfig ,
7542 Check : resource .ComposeAggregateTestCheckFunc (
7643 // Bucket data
77- resource .TestCheckResourceAttr ("stackit_objectstorage_bucket.bucket" , "project_id" , bucketResource ["project_id" ]),
78- resource .TestCheckResourceAttr ("stackit_objectstorage_bucket.bucket" , "name" , bucketResource [ "name" ] ),
44+ resource .TestCheckResourceAttr ("stackit_objectstorage_bucket.bucket" , "project_id" , testutil . ConvertConfigVariable ( testConfigVarsMin ["project_id" ]) ),
45+ resource .TestCheckResourceAttr ("stackit_objectstorage_bucket.bucket" , "name" , testutil . ConvertConfigVariable ( testConfigVarsMin [ "objectstorage_bucket_name" ]) ),
7946 resource .TestCheckResourceAttrSet ("stackit_objectstorage_bucket.bucket" , "url_path_style" ),
8047 resource .TestCheckResourceAttrSet ("stackit_objectstorage_bucket.bucket" , "url_virtual_hosted_style" ),
8148
8249 // Credentials group data
83- resource .TestCheckResourceAttr ("stackit_objectstorage_credentials_group.credentials_group" , "project_id" , credentialsGroupResource ["project_id" ]),
84- resource .TestCheckResourceAttr ("stackit_objectstorage_credentials_group.credentials_group" , "name" , credentialsGroupResource [ "name" ] ),
50+ resource .TestCheckResourceAttr ("stackit_objectstorage_credentials_group.credentials_group" , "project_id" , testutil . ConvertConfigVariable ( testConfigVarsMin ["project_id" ]) ),
51+ resource .TestCheckResourceAttr ("stackit_objectstorage_credentials_group.credentials_group" , "name" , testutil . ConvertConfigVariable ( testConfigVarsMin [ "objectstorage_credentials_group_name" ]) ),
8552 resource .TestCheckResourceAttrSet ("stackit_objectstorage_credentials_group.credentials_group" , "credentials_group_id" ),
8653 resource .TestCheckResourceAttrSet ("stackit_objectstorage_credentials_group.credentials_group" , "urn" ),
8754
@@ -95,37 +62,38 @@ func TestAccObjectStorageResource(t *testing.T) {
9562 "stackit_objectstorage_credentials_group.credentials_group" , "credentials_group_id" ,
9663 ),
9764 resource .TestCheckResourceAttrSet ("stackit_objectstorage_credential.credential" , "credential_id" ),
98- resource .TestCheckResourceAttr ("stackit_objectstorage_credential.credential" , "expiration_timestamp" , credentialResource ["expiration_timestamp" ]),
65+ resource .TestCheckResourceAttr ("stackit_objectstorage_credential.credential" , "expiration_timestamp" , testutil . ConvertConfigVariable ( testConfigVarsMin ["expiration_timestamp" ]) ),
9966 resource .TestCheckResourceAttrSet ("stackit_objectstorage_credential.credential" , "name" ),
10067 resource .TestCheckResourceAttrSet ("stackit_objectstorage_credential.credential" , "access_key" ),
10168 resource .TestCheckResourceAttrSet ("stackit_objectstorage_credential.credential" , "secret_access_key" ),
10269 ),
10370 },
10471 // Data source
10572 {
73+ ConfigVariables : testConfigVarsMin ,
10674 Config : fmt .Sprintf (`
107- %s
75+ %s
10876
109- data "stackit_objectstorage_bucket" "bucket" {
110- project_id = stackit_objectstorage_bucket.bucket.project_id
111- name = stackit_objectstorage_bucket.bucket.name
112- }
113-
114- data "stackit_objectstorage_credentials_group" "credentials_group" {
115- project_id = stackit_objectstorage_credentials_group.credentials_group.project_id
116- credentials_group_id = stackit_objectstorage_credentials_group.credentials_group.credentials_group_id
117- }
118-
119- data "stackit_objectstorage_credential" "credential" {
120- project_id = stackit_objectstorage_credential.credential.project_id
121- credentials_group_id = stackit_objectstorage_credential.credential.credentials_group_id
122- credential_id = stackit_objectstorage_credential.credential.credential_id
123- }` ,
124- resourceConfig () ,
77+ data "stackit_objectstorage_bucket" "bucket" {
78+ project_id = stackit_objectstorage_bucket.bucket.project_id
79+ name = stackit_objectstorage_bucket.bucket.name
80+ }
81+
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+ }
86+
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+ }` ,
92+ testutil . ObjectStorageProviderConfig () + resourceMinConfig ,
12593 ),
12694 Check : resource .ComposeAggregateTestCheckFunc (
12795 // Bucket data
128- resource .TestCheckResourceAttr ("data.stackit_objectstorage_bucket.bucket" , "project_id" , bucketResource ["project_id" ]),
96+ resource .TestCheckResourceAttr ("data.stackit_objectstorage_bucket.bucket" , "project_id" , testutil . ConvertConfigVariable ( testConfigVarsMin ["project_id" ]) ),
12997 resource .TestCheckResourceAttrPair (
13098 "stackit_objectstorage_bucket.bucket" , "name" ,
13199 "data.stackit_objectstorage_bucket.bucket" , "name" ,
@@ -140,7 +108,7 @@ func TestAccObjectStorageResource(t *testing.T) {
140108 ),
141109
142110 // Credentials group data
143- resource .TestCheckResourceAttr ("data.stackit_objectstorage_credentials_group.credentials_group" , "project_id" , credentialsGroupResource ["project_id" ]),
111+ resource .TestCheckResourceAttr ("data.stackit_objectstorage_credentials_group.credentials_group" , "project_id" , testutil . ConvertConfigVariable ( testConfigVarsMin ["project_id" ]) ),
144112 resource .TestCheckResourceAttrPair (
145113 "stackit_objectstorage_credentials_group.credentials_group" , "credentials_group_id" ,
146114 "data.stackit_objectstorage_credentials_group.credentials_group" , "credentials_group_id" ,
@@ -179,7 +147,8 @@ func TestAccObjectStorageResource(t *testing.T) {
179147 },
180148 // Import
181149 {
182- ResourceName : "stackit_objectstorage_credentials_group.credentials_group" ,
150+ ConfigVariables : testConfigVarsMin ,
151+ ResourceName : "stackit_objectstorage_credentials_group.credentials_group" ,
183152 ImportStateIdFunc : func (s * terraform.State ) (string , error ) {
184153 r , ok := s .RootModule ().Resources ["stackit_objectstorage_credentials_group.credentials_group" ]
185154 if ! ok {
@@ -197,7 +166,8 @@ func TestAccObjectStorageResource(t *testing.T) {
197166 ImportStateVerifyIgnore : []string {"region" },
198167 },
199168 {
200- ResourceName : "stackit_objectstorage_credential.credential" ,
169+ ConfigVariables : testConfigVarsMin ,
170+ ResourceName : "stackit_objectstorage_credential.credential" ,
201171 ImportStateIdFunc : func (s * terraform.State ) (string , error ) {
202172 r , ok := s .RootModule ().Resources ["stackit_objectstorage_credential.credential" ]
203173 if ! ok {
@@ -228,11 +198,11 @@ func testAccCheckObjectStorageDestroy(s *terraform.State) error {
228198 var err error
229199 if testutil .ObjectStorageCustomEndpoint == "" {
230200 client , err = objectstorage .NewAPIClient (
231- config .WithRegion ("eu01" ),
201+ stackitSdkConfig .WithRegion ("eu01" ),
232202 )
233203 } else {
234204 client , err = objectstorage .NewAPIClient (
235- config .WithEndpoint (testutil .ObjectStorageCustomEndpoint ),
205+ stackitSdkConfig .WithEndpoint (testutil .ObjectStorageCustomEndpoint ),
236206 )
237207 }
238208 if err != nil {
0 commit comments