Skip to content

Commit 1ca4b0a

Browse files
feat: added env var to change url for object storage management (#759)
* feat: added env var to change url for object storage management * docs: updated upcoming version
1 parent effc223 commit 1ca4b0a

File tree

7 files changed

+37
-2
lines changed

7 files changed

+37
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 6.7.1 (Upcoming)
2+
### Features
3+
- Add `IONOS_API_URL_OBJECT_STORAGE_MANAGEMENT` to set a custom API URL for the Object Storage Management Product. Setting `endpoint` or `IONOS_API_URL` does not have any effect
4+
15
## 6.7.0
26
### Fixes
37
- Fix [#735](https://github.com/ionos-cloud/terraform-provider-ionoscloud/issues/735) by reading all values for `api_subnet_allow_list`, not only non-nill values.

docs/data-sources/object_storage_accesskey.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,5 @@ The following attributes are returned by the datasource:
3535
- `accesskey` - Access key metadata is a string of 92 characters.
3636
- `canonical_user_id` - The canonical user ID which is valid for user-owned buckets.
3737
- `contract_user_id` - The contract user ID which is valid for contract-owned buckets
38+
39+
> **⚠ WARNING:** `IONOS_API_URL_OBJECT_STORAGE_MANAGEMENT` can be used to set a custom API URL for the Object Storage Management SDK. Setting `endpoint` or `IONOS_API_URL` does not have any effect

docs/data-sources/object_storage_region.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,5 @@ The following attributes are returned by the datasource:
3737
- `capability` - The capabilities of the region
3838
* `iam` - Indicates if IAM policy based access is supported
3939
* `s3select` - Indicates if S3 Select is supported
40+
41+
> **⚠ WARNING:** `IONOS_API_URL_OBJECT_STORAGE_MANAGEMENT` can be used to set a custom API URL for the Object Storage Management SDK. Setting `endpoint` or `IONOS_API_URL` does not have any effect

docs/resources/object_storage_accesskey.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ The following arguments are supported:
3333
- `create` - (Optional)[string] Time to wait for the bucket to be created. Default is `10m`.
3434
- `delete` - (Optional)[string] Time to wait for the bucket to be deleted. Default is `10m`.
3535

36+
> **⚠ WARNING:** `IONOS_API_URL_OBJECT_STORAGE_MANAGEMENT` can be used to set a custom API URL for the Object Storage Management SDK. Setting `endpoint` or `IONOS_API_URL` does not have any effect.
37+
3638
## Import
3739

3840
An object storage accesskey resource can be imported using its `resource id`, e.g.

gitbook_docs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ See the [IonosCloud Provider documentation](https://registry.terraform.io/provid
4343
| `IONOS_API_URL_KAFKA` | Sets a custom API URL for the Event Streams product. `location` field needs to be empty, otherwise it will override the custom API URL. Setting `endpoint` or `IONOS_API_URL` does not have any effect. |
4444
| `IONOS_API_URL_VPN` | Sets a custom API URL for the VPN product. `location` field needs to be empty, otherwise it will override the custom API URL. Setting `endpoint` or `IONOS_API_URL` does not have any effect. |
4545
| `IONOS_API_URL_OBJECT_STORAGE` | Sets a custom API URL for the Object Storage product. `region` field needs to be empty, otherwise it will override the custom API URL. Setting `endpoint` or `IONOS_API_URL` does not have any effect. |
46+
| `IONOS_API_URL_OBJECT_STORAGE_MANAGEMENT` | Sets a custom API URL for the Object Storage Management product. Setting `endpoint` or `IONOS_API_URL` does not have any effect. |
4647
| `IONOS_API_URL_MONITORING` | Sets a custom API URL for the Monitoring product. `location` field needs to be empty, otherwise it will override the custom API URL. Setting `endpoint` or `IONOS_API_URL` does not have any effect. |
4748

4849
### Certificate pinning:

services/objectstoragemanagement/accesskeys.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ package objectstoragemanagement
33
import (
44
"context"
55
"fmt"
6+
"os"
67
"time"
78

89
"github.com/cenkalti/backoff/v4"
910
"github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts"
1011
"github.com/hashicorp/terraform-plugin-framework/types"
1112
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
1213
objectstoragemanagement "github.com/ionos-cloud/sdk-go-object-storage-management"
14+
"github.com/ionos-cloud/terraform-provider-ionoscloud/v6/utils"
1315
)
1416

1517
// AccesskeyResourceModel is used to represent an accesskey
@@ -32,29 +34,49 @@ type AccessKeyDataSourceModel struct {
3234
ID types.String `tfsdk:"id"`
3335
}
3436

37+
var ionosAPIURLObjectStorageManagement = "IONOS_API_URL_OBJECT_STORAGE_MANAGEMENT"
38+
39+
// modifyConfigURL modifies the URL inside the client configuration.
40+
// This function is required in order to make requests to different endpoints.
41+
func (c *Client) modifyConfigURL() {
42+
clientConfig := c.client.GetConfig()
43+
if os.Getenv(ionosAPIURLObjectStorageManagement) != "" {
44+
clientConfig.Servers = objectstoragemanagement.ServerConfigurations{
45+
{
46+
URL: utils.CleanURL(os.Getenv(ionosAPIURLObjectStorageManagement)),
47+
},
48+
}
49+
return
50+
}
51+
}
52+
3553
// GetAccessKey retrieves an accesskey
3654
func (c *Client) GetAccessKey(ctx context.Context, accessKeyID string) (objectstoragemanagement.AccessKeyRead, *objectstoragemanagement.APIResponse, error) {
55+
c.modifyConfigURL()
3756
accessKey, apiResponse, err := c.client.AccesskeysApi.AccesskeysFindById(ctx, accessKeyID).Execute()
3857
apiResponse.LogInfo()
3958
return accessKey, apiResponse, err
4059
}
4160

4261
// ListAccessKeys retrieves all accesskeys
4362
func (c *Client) ListAccessKeys(ctx context.Context) (objectstoragemanagement.AccessKeyReadList, *objectstoragemanagement.APIResponse, error) {
63+
c.modifyConfigURL()
4464
accessKeys, apiResponse, err := c.client.AccesskeysApi.AccesskeysGet(ctx).Execute()
4565
apiResponse.LogInfo()
4666
return accessKeys, apiResponse, err
4767
}
4868

4969
// ListAccessKeysFilter retrieves accesskeys using the accessKeyId filter
5070
func (c *Client) ListAccessKeysFilter(ctx context.Context, accessKeyID string) (objectstoragemanagement.AccessKeyReadList, *objectstoragemanagement.APIResponse, error) {
71+
c.modifyConfigURL()
5172
accessKeys, apiResponse, err := c.client.AccesskeysApi.AccesskeysGet(ctx).FilterAccesskeyId(accessKeyID).Execute()
5273
apiResponse.LogInfo()
5374
return accessKeys, apiResponse, err
5475
}
5576

5677
// CreateAccessKey creates an accesskey
5778
func (c *Client) CreateAccessKey(ctx context.Context, accessKey objectstoragemanagement.AccessKeyCreate, timeout time.Duration) (objectstoragemanagement.AccessKeyRead, *objectstoragemanagement.APIResponse, error) {
79+
c.modifyConfigURL()
5880
accessKeyResponse, apiResponse, err := c.client.AccesskeysApi.AccesskeysPost(ctx).AccessKeyCreate(accessKey).Execute()
5981
apiResponse.LogInfo()
6082

@@ -74,6 +96,7 @@ func (c *Client) CreateAccessKey(ctx context.Context, accessKey objectstorageman
7496

7597
// UpdateAccessKey updates an accesskey
7698
func (c *Client) UpdateAccessKey(ctx context.Context, accessKeyID string, accessKey objectstoragemanagement.AccessKeyEnsure, timeout time.Duration) (objectstoragemanagement.AccessKeyRead, *objectstoragemanagement.APIResponse, error) {
99+
c.modifyConfigURL()
77100
accessKeyResponse, apiResponse, err := c.client.AccesskeysApi.AccesskeysPut(ctx, accessKeyID).AccessKeyEnsure(accessKey).Execute()
78101
apiResponse.LogInfo()
79102

@@ -93,6 +116,7 @@ func (c *Client) UpdateAccessKey(ctx context.Context, accessKeyID string, access
93116

94117
// DeleteAccessKey deletes an accesskey
95118
func (c *Client) DeleteAccessKey(ctx context.Context, accessKeyID string, timeout time.Duration) (*objectstoragemanagement.APIResponse, error) {
119+
c.modifyConfigURL()
96120
apiResponse, err := c.client.AccesskeysApi.AccesskeysDelete(ctx, accessKeyID).Execute()
97121
apiResponse.LogInfo()
98122

@@ -112,7 +136,6 @@ func (c *Client) DeleteAccessKey(ctx context.Context, accessKeyID string, timeou
112136

113137
// SetAccessKeyPropertiesToPlan sets accesskey properties from an SDK object to a AccesskeyResourceModel
114138
func SetAccessKeyPropertiesToPlan(plan *AccesskeyResourceModel, accessKey objectstoragemanagement.AccessKeyRead) {
115-
116139
if accessKey.Properties != nil {
117140
// Here we check the properties because based on the request not all are set and we do not want to overwrite with nil
118141
if accessKey.Properties.AccessKey != nil {
@@ -138,7 +161,6 @@ func SetAccessKeyPropertiesToPlan(plan *AccesskeyResourceModel, accessKey object
138161

139162
// SetAccessKeyPropertiesToDataSourcePlan sets accesskey properties from an SDK object to a AccessKeyDataSourceModel
140163
func SetAccessKeyPropertiesToDataSourcePlan(plan *AccessKeyDataSourceModel, accessKey objectstoragemanagement.AccessKeyRead) {
141-
142164
if accessKey.Properties != nil {
143165
// Here we check the properties because based on the request not all are set and we do not want to overwrite with nil
144166
if accessKey.Properties.AccessKey != nil {

services/objectstoragemanagement/regions.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@ type capability struct {
2525

2626
// GetRegion retrieves a region
2727
func (c *Client) GetRegion(ctx context.Context, regionID string, depth float32) (objectstoragemanagement.RegionRead, *objectstoragemanagement.APIResponse, error) {
28+
c.modifyConfigURL()
2829
region, apiResponse, err := c.client.RegionsApi.RegionsFindByRegion(ctx, regionID).Execute()
2930
apiResponse.LogInfo()
3031
return region, apiResponse, err
3132
}
3233

3334
// ListRegions lists all regions
3435
func (c *Client) ListRegions(ctx context.Context) (objectstoragemanagement.RegionReadList, *objectstoragemanagement.APIResponse, error) {
36+
c.modifyConfigURL()
3537
regions, apiResponse, err := c.client.RegionsApi.RegionsGet(ctx).Execute()
3638
apiResponse.LogInfo()
3739
return regions, apiResponse, err

0 commit comments

Comments
 (0)