Skip to content

Commit c257ac4

Browse files
authored
Fix/stackittpr 102 objectstorage handling region in individual resources (#711)
* Revert "fix: make resource/data-source specific region attribute read-only (#682)" This reverts commit 3e8dcc5. * fix: Support individual regions * fix: review findings
1 parent 81f876a commit c257ac4

105 files changed

Lines changed: 176 additions & 143 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CONTRIBUTION.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func (r *barResource) Configure(ctx context.Context, req resource.ConfigureReque
124124
} else {
125125
apiClient, err = foo.NewAPIClient(
126126
config.WithCustomAuth(providerData.RoundTripper),
127-
config.WithRegion(providerData.Region),
127+
config.WithRegion(providerData.DefaultRegion),
128128
)
129129
}
130130

docs/data-sources/objectstorage_bucket.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ data "stackit_objectstorage_bucket" "example" {
2626

2727
- `name` (String) The bucket name. It must be DNS conform.
2828
- `project_id` (String) STACKIT Project ID to which the bucket is associated.
29+
30+
### Optional
31+
2932
- `region` (String) The resource region. If not defined, the provider region is used.
3033

3134
### Read-Only

docs/data-sources/objectstorage_credential.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ data "stackit_objectstorage_credentials_group" "example" {
2828
- `credential_id` (String) The credential ID.
2929
- `credentials_group_id` (String) The credential group ID.
3030
- `project_id` (String) STACKIT Project ID to which the credential group is associated.
31+
32+
### Optional
33+
3134
- `region` (String) The resource region. If not defined, the provider region is used.
3235

3336
### Read-Only

docs/data-sources/objectstorage_credentials_group.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ data "stackit_objectstorage_credentials_group" "example" {
2525
### Required
2626

2727
- `project_id` (String) Object Storage Project ID to which the credentials group is associated.
28-
- `region` (String) The resource region. If not defined, the provider region is used.
2928

3029
### Optional
3130

3231
- `credentials_group_id` (String) The credentials group ID.
3332
- `name` (String) The credentials group's display name.
33+
- `region` (String) The resource region. If not defined, the provider region is used.
3434

3535
### Read-Only
3636

docs/index.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ Note: AWS specific checks must be skipped as they do not work on STACKIT. For de
154154
- `argus_custom_endpoint` (String, Deprecated) Custom endpoint for the Argus service
155155
- `authorization_custom_endpoint` (String) Custom endpoint for the Membership service
156156
- `credentials_path` (String) Path of JSON from where the credentials are read. Takes precedence over the env var `STACKIT_CREDENTIALS_PATH`. Default value is `~/.stackit/credentials.json`.
157+
- `default_region` (String) Region will be used as the default location for regional services. Not all services require a region, some are global
157158
- `dns_custom_endpoint` (String) Custom endpoint for the DNS service
158159
- `enable_beta_resources` (Boolean) Enable beta resources. Default is false.
159160
- `iaas_custom_endpoint` (String) Custom endpoint for the IaaS service
@@ -169,7 +170,7 @@ Note: AWS specific checks must be skipped as they do not work on STACKIT. For de
169170
- `private_key_path` (String) Path for the private RSA key used for authentication, relevant for the key flow. It takes precedence over the private key that is included in the service account key.
170171
- `rabbitmq_custom_endpoint` (String) Custom endpoint for the RabbitMQ service
171172
- `redis_custom_endpoint` (String) Custom endpoint for the Redis service
172-
- `region` (String) Region will be used as the default location for regional services. Not all services require a region, some are global
173+
- `region` (String, Deprecated) Region will be used as the default location for regional services. Not all services require a region, some are global
173174
- `resourcemanager_custom_endpoint` (String) Custom endpoint for the Resource Manager service
174175
- `secretsmanager_custom_endpoint` (String) Custom endpoint for the Secrets Manager service
175176
- `server_backup_custom_endpoint` (String) Custom endpoint for the Server Backup service

stackit/internal/core/core.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ import (
1414
const Separator = ","
1515

1616
type ProviderData struct {
17-
RoundTripper http.RoundTripper
18-
ServiceAccountEmail string // Deprecated: ServiceAccountEmail is not required and will be removed after 12th June 2025.
17+
RoundTripper http.RoundTripper
18+
ServiceAccountEmail string // Deprecated: ServiceAccountEmail is not required and will be removed after 12th June 2025.
19+
// Deprecated: Use DefaultRegion instead
1920
Region string
21+
DefaultRegion string
2022
ArgusCustomEndpoint string
2123
AuthorizationCustomEndpoint string
2224
DnsCustomEndpoint string
@@ -41,6 +43,17 @@ type ProviderData struct {
4143
EnableBetaResources bool
4244
}
4345

46+
// GetRegion returns the effective region for the provider, falling back to the deprecated _region_ attribute
47+
func (pd *ProviderData) GetRegion() string {
48+
if pd.DefaultRegion != "" {
49+
return pd.DefaultRegion
50+
} else if pd.Region != "" {
51+
return pd.Region
52+
}
53+
// final fallback
54+
return "eu01"
55+
}
56+
4457
// DiagsToError Converts TF diagnostics' errors into an error with a human-readable description.
4558
// If there are no errors, the output is nil
4659
func DiagsToError(diags diag.Diagnostics) error {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func (r *credentialResource) Configure(ctx context.Context, req resource.Configu
7373
} else {
7474
apiClient, err = argus.NewAPIClient(
7575
config.WithCustomAuth(providerData.RoundTripper),
76-
config.WithRegion(providerData.Region),
76+
config.WithRegion(providerData.GetRegion()),
7777
)
7878
}
7979

stackit/internal/services/argus/instance/datasource.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func (d *instanceDataSource) Configure(ctx context.Context, req datasource.Confi
6262
} else {
6363
apiClient, err = argus.NewAPIClient(
6464
config.WithCustomAuth(providerData.RoundTripper),
65-
config.WithRegion(providerData.Region),
65+
config.WithRegion(providerData.GetRegion()),
6666
)
6767
}
6868
if err != nil {

stackit/internal/services/argus/instance/resource.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ func (r *instanceResource) Configure(ctx context.Context, req resource.Configure
362362
} else {
363363
apiClient, err = argus.NewAPIClient(
364364
config.WithCustomAuth(providerData.RoundTripper),
365-
config.WithRegion(providerData.Region),
365+
config.WithRegion(providerData.GetRegion()),
366366
)
367367
}
368368

stackit/internal/services/argus/scrapeconfig/datasource.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func (d *scrapeConfigDataSource) Configure(ctx context.Context, req datasource.C
6464
} else {
6565
apiClient, err = argus.NewAPIClient(
6666
config.WithCustomAuth(providerData.RoundTripper),
67-
config.WithRegion(providerData.Region),
67+
config.WithRegion(providerData.GetRegion()),
6868
)
6969
}
7070
if err != nil {

0 commit comments

Comments
 (0)