Skip to content

Commit

Permalink
feat: added env var to change url for object storage management (#759)
Browse files Browse the repository at this point in the history
* feat: added env var to change url for object storage management

* docs: updated upcoming version
  • Loading branch information
rmocanu-ionos authored Feb 5, 2025
1 parent effc223 commit 1ca4b0a
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 6.7.1 (Upcoming)
### Features
- 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

## 6.7.0
### Fixes
- 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.
Expand Down
2 changes: 2 additions & 0 deletions docs/data-sources/object_storage_accesskey.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ The following attributes are returned by the datasource:
- `accesskey` - Access key metadata is a string of 92 characters.
- `canonical_user_id` - The canonical user ID which is valid for user-owned buckets.
- `contract_user_id` - The contract user ID which is valid for contract-owned buckets

> **⚠ 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
2 changes: 2 additions & 0 deletions docs/data-sources/object_storage_region.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ The following attributes are returned by the datasource:
- `capability` - The capabilities of the region
* `iam` - Indicates if IAM policy based access is supported
* `s3select` - Indicates if S3 Select is supported

> **⚠ 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
2 changes: 2 additions & 0 deletions docs/resources/object_storage_accesskey.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ The following arguments are supported:
- `create` - (Optional)[string] Time to wait for the bucket to be created. Default is `10m`.
- `delete` - (Optional)[string] Time to wait for the bucket to be deleted. Default is `10m`.

> **⚠ 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.
## Import

An object storage accesskey resource can be imported using its `resource id`, e.g.
Expand Down
1 change: 1 addition & 0 deletions gitbook_docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ See the [IonosCloud Provider documentation](https://registry.terraform.io/provid
| `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. |
| `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. |
| `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. |
| `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. |
| `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. |

### Certificate pinning:
Expand Down
26 changes: 24 additions & 2 deletions services/objectstoragemanagement/accesskeys.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ package objectstoragemanagement
import (
"context"
"fmt"
"os"
"time"

"github.com/cenkalti/backoff/v4"
"github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
objectstoragemanagement "github.com/ionos-cloud/sdk-go-object-storage-management"
"github.com/ionos-cloud/terraform-provider-ionoscloud/v6/utils"
)

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

var ionosAPIURLObjectStorageManagement = "IONOS_API_URL_OBJECT_STORAGE_MANAGEMENT"

// modifyConfigURL modifies the URL inside the client configuration.
// This function is required in order to make requests to different endpoints.
func (c *Client) modifyConfigURL() {
clientConfig := c.client.GetConfig()
if os.Getenv(ionosAPIURLObjectStorageManagement) != "" {
clientConfig.Servers = objectstoragemanagement.ServerConfigurations{
{
URL: utils.CleanURL(os.Getenv(ionosAPIURLObjectStorageManagement)),
},
}
return
}
}

// GetAccessKey retrieves an accesskey
func (c *Client) GetAccessKey(ctx context.Context, accessKeyID string) (objectstoragemanagement.AccessKeyRead, *objectstoragemanagement.APIResponse, error) {
c.modifyConfigURL()
accessKey, apiResponse, err := c.client.AccesskeysApi.AccesskeysFindById(ctx, accessKeyID).Execute()
apiResponse.LogInfo()
return accessKey, apiResponse, err
}

// ListAccessKeys retrieves all accesskeys
func (c *Client) ListAccessKeys(ctx context.Context) (objectstoragemanagement.AccessKeyReadList, *objectstoragemanagement.APIResponse, error) {
c.modifyConfigURL()
accessKeys, apiResponse, err := c.client.AccesskeysApi.AccesskeysGet(ctx).Execute()
apiResponse.LogInfo()
return accessKeys, apiResponse, err
}

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

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

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

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

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

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

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

// SetAccessKeyPropertiesToPlan sets accesskey properties from an SDK object to a AccesskeyResourceModel
func SetAccessKeyPropertiesToPlan(plan *AccesskeyResourceModel, accessKey objectstoragemanagement.AccessKeyRead) {

if accessKey.Properties != nil {
// Here we check the properties because based on the request not all are set and we do not want to overwrite with nil
if accessKey.Properties.AccessKey != nil {
Expand All @@ -138,7 +161,6 @@ func SetAccessKeyPropertiesToPlan(plan *AccesskeyResourceModel, accessKey object

// SetAccessKeyPropertiesToDataSourcePlan sets accesskey properties from an SDK object to a AccessKeyDataSourceModel
func SetAccessKeyPropertiesToDataSourcePlan(plan *AccessKeyDataSourceModel, accessKey objectstoragemanagement.AccessKeyRead) {

if accessKey.Properties != nil {
// Here we check the properties because based on the request not all are set and we do not want to overwrite with nil
if accessKey.Properties.AccessKey != nil {
Expand Down
2 changes: 2 additions & 0 deletions services/objectstoragemanagement/regions.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ type capability struct {

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

// ListRegions lists all regions
func (c *Client) ListRegions(ctx context.Context) (objectstoragemanagement.RegionReadList, *objectstoragemanagement.APIResponse, error) {
c.modifyConfigURL()
regions, apiResponse, err := c.client.RegionsApi.RegionsGet(ctx).Execute()
apiResponse.LogInfo()
return regions, apiResponse, err
Expand Down

0 comments on commit 1ca4b0a

Please sign in to comment.