-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
cloudavenue_s3_bucket
resource/datasource
- Loading branch information
Showing
22 changed files
with
894 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
```release-note:new-resource | ||
`resource/cloudavenue_s3_bucket` - Create and manage S3 buckets. | ||
``` | ||
|
||
```release-note:new-data-source | ||
`datasource/cloudavenue_s3_bucket` - Retrieve information about S3 buckets. | ||
``` | ||
|
||
```release-note:dependency | ||
deps: bumps github.com/orange-cloudavenue/cloudavenue-sdk-go from 0.2.0 to 0.3.0 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
--- | ||
page_title: "cloudavenue_s3_bucket Data Source - cloudavenue" | ||
subcategory: "S3 (Object Storage)" | ||
description: |- | ||
The cloudavenue_s3_bucket data source allows you to retrieve information about an existing S3 bucket | ||
--- | ||
|
||
# cloudavenue_s3_bucket (Data Source) | ||
|
||
The `cloudavenue_s3_bucket` data source allows you to retrieve information about an existing S3 bucket | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
data "cloudavenue_s3_bucket" "example" { | ||
name = "example" | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `name` (String) The name of the bucket. | ||
|
||
### Optional | ||
|
||
- `object_lock` (Boolean) Indicates whether this bucket has an Object Lock configuration enabled. | ||
|
||
### Read-Only | ||
|
||
- `endpoint` (String) The endpoint URL of the bucket. | ||
- `id` (String) The ID of the S3 bucket. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
--- | ||
page_title: "cloudavenue_s3_bucket Resource - cloudavenue" | ||
subcategory: "S3 (Object Storage)" | ||
description: |- | ||
The cloudavenue_s3_bucket resource allows you to manage S3 buckets | ||
--- | ||
|
||
# cloudavenue_s3_bucket (Resource) | ||
|
||
The `cloudavenue_s3_bucket` resource allows you to manage S3 buckets | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
resource "cloudavenue_s3_bucket" "example" { | ||
name = "example" | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `name` (String) (ForceNew) The name of the bucket. A full list of bucket naming rules (may be found here)[https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucketnamingrules.html]. | ||
|
||
### Optional | ||
|
||
- `object_lock` (Boolean) (ForceNew) Indicates whether this bucket has an Object Lock configuration enabled. Value defaults to `false`. | ||
|
||
### Read-Only | ||
|
||
- `endpoint` (String) The endpoint URL of the bucket. | ||
- `id` (String) The ID of the S3 bucket. | ||
|
||
## Import | ||
|
||
Import is supported using the following syntax: | ||
```shell | ||
terraform import cloudavenue_s3_bucket.example bucketName | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
data "cloudavenue_s3_bucket" "example" { | ||
name = "example" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
terraform import cloudavenue_s3_bucket.example bucketName |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
resource "cloudavenue_s3_bucket" "example" { | ||
name = "example" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package s3 | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"time" | ||
|
||
"github.com/hashicorp/aws-sdk-go-base/tfawserr" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" | ||
) | ||
|
||
const ( | ||
categoryName = "s3" | ||
|
||
// ErrCodeObjectLockConfigurationNotFoundError object lock configuration not found. | ||
ErrCodeObjectLockConfigurationNotFoundError = "ObjectLockConfigurationNotFoundError" | ||
) | ||
|
||
// DefaultWaitRetryInterval is used to set the retry interval to 0 during acceptance tests. | ||
var DefaultWaitRetryInterval *time.Duration | ||
|
||
// NotFound returns true if the error represents a "resource not found" condition. | ||
// Specifically, NotFound returns true if the error or a wrapped error is of type | ||
// retry.NotFoundError. | ||
func NotFound(err error) bool { | ||
var e *retry.NotFoundError // nosemgrep:ci.is-not-found-error | ||
return errors.As(err, &e) | ||
} | ||
|
||
type RetryWhenConfig[T any] struct { | ||
Timeout time.Duration | ||
Interval time.Duration | ||
Function func() (T, error) | ||
} | ||
|
||
var ErrRetryWhenTimeout = errors.New("timeout reached") | ||
|
||
// retryWhen executes the function passed in the configuration object until the timeout is reached or the context is cancelled. | ||
// It will retry if the shouldRetry function returns true. It will stop if the shouldRetry function returns false. | ||
func retryWhen[T any](ctx context.Context, config *RetryWhenConfig[T], shouldRetry func(error) bool) (T, error) { //nolint: ireturn | ||
retryInterval := config.Interval | ||
if DefaultWaitRetryInterval != nil { | ||
retryInterval = *DefaultWaitRetryInterval | ||
} | ||
|
||
timer := time.NewTimer(config.Timeout) | ||
|
||
for { | ||
result, err := config.Function() | ||
if shouldRetry(err) { | ||
select { | ||
case <-timer.C: | ||
return result, ErrRetryWhenTimeout | ||
case <-ctx.Done(): | ||
return result, ctx.Err() | ||
default: | ||
time.Sleep(retryInterval) // lintignore:R018 | ||
continue | ||
} | ||
} | ||
|
||
return result, err | ||
} | ||
} | ||
|
||
// retryWhenAWSErrCodeEquals retries a function when it returns a specific AWS error. | ||
func retryWhenAWSErrCodeEquals[T any](ctx context.Context, codes []string, config *RetryWhenConfig[T]) (T, error) { //nolint: ireturn | ||
return retryWhen(ctx, config, func(err error) bool { | ||
return tfawserr.ErrCodeEquals(err, codes...) | ||
}) | ||
} | ||
|
||
// retryWhenAWSErrCodeNotEquals retries a function until it returns a specific AWS error. | ||
func retryWhenAWSErrCodeNotEquals[T any](ctx context.Context, codes []string, config *RetryWhenConfig[T]) (T, error) { //nolint: ireturn | ||
return retryWhen(ctx, config, func(err error) bool { | ||
if err == nil { | ||
return true | ||
} | ||
|
||
return !tfawserr.ErrCodeEquals(err, codes...) | ||
}) | ||
} |
Oops, something went wrong.