Skip to content

Commit

Permalink
feat: add cloudavenue_s3_bucket resource/datasource
Browse files Browse the repository at this point in the history
  • Loading branch information
azrod committed Oct 17, 2023
1 parent fec627c commit dd42a57
Show file tree
Hide file tree
Showing 22 changed files with 894 additions and 4 deletions.
11 changes: 11 additions & 0 deletions .changelog/576.txt
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
```
35 changes: 35 additions & 0 deletions docs/data-sources/s3_bucket.md
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.

41 changes: 41 additions & 0 deletions docs/resources/s3_bucket.md
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
```
3 changes: 3 additions & 0 deletions examples/data-sources/cloudavenue_s3_bucket/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data "cloudavenue_s3_bucket" "example" {
name = "example"
}
1 change: 1 addition & 0 deletions examples/resources/cloudavenue_s3_bucket/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terraform import cloudavenue_s3_bucket.example bucketName
3 changes: 3 additions & 0 deletions examples/resources/cloudavenue_s3_bucket/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
resource "cloudavenue_s3_bucket" "example" {
name = "example"
}
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ require (
github.com/FrangipaneTeam/terraform-plugin-framework-supertypes v0.1.0
github.com/FrangipaneTeam/terraform-plugin-framework-validators v1.8.1
github.com/antihax/optional v1.0.0
github.com/aws/aws-sdk-go v1.45.26
github.com/drhodes/golorem v0.0.0-20220328165741-da82e5b29246
github.com/google/uuid v1.3.1
github.com/hashicorp/aws-sdk-go-base v1.1.0
github.com/hashicorp/terraform-plugin-docs v0.16.0
github.com/hashicorp/terraform-plugin-framework v1.4.1
github.com/hashicorp/terraform-plugin-framework-timeouts v0.4.1
Expand All @@ -19,7 +21,7 @@ require (
github.com/hashicorp/terraform-plugin-log v0.9.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.29.0
github.com/iancoleman/strcase v0.3.0
github.com/orange-cloudavenue/cloudavenue-sdk-go v0.2.0
github.com/orange-cloudavenue/cloudavenue-sdk-go v0.3.0
github.com/orange-cloudavenue/infrapi-sdk-go v0.1.4-0.20231005074857-89878ea119fb
github.com/rs/zerolog v1.31.0
github.com/thanhpk/randstr v1.0.6
Expand Down Expand Up @@ -72,6 +74,7 @@ require (
github.com/imdario/mergo v0.3.15 // indirect
github.com/influxdata/influxdb-client-go/v2 v2.12.3 // indirect
github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
Expand Down
21 changes: 19 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de/go.mod h1:DCaWoU
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
github.com/armon/go-radix v1.0.0 h1:F4z6KzEeeQIMeLFa97iZU6vupzoecKdU5TX24SNppXI=
github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
github.com/aws/aws-sdk-go v1.31.9/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0=
github.com/aws/aws-sdk-go v1.45.26 h1:PJ2NJNY5N/yeobLYe1Y+xLdavBi67ZI8gvph6ftwVCg=
github.com/aws/aws-sdk-go v1.45.26/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
github.com/bgentry/speakeasy v0.1.0 h1:ByYyxL9InA1OWqxJqqp2A5pYHUrCiAL6K3J+LKSsQkY=
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA=
Expand Down Expand Up @@ -80,6 +83,7 @@ github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC
github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo=
github.com/go-resty/resty/v2 v2.10.0 h1:Qla4W/+TMmv0fOeeRqzEpXPLfTUnR5HZ1+lGs+CkiCo=
github.com/go-resty/resty/v2 v2.10.0/go.mod h1:iiP/OpA0CkcL3IGt1O0+/SIItFUbkkyw5BGXiVdTu+A=
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE=
Expand All @@ -98,6 +102,8 @@ github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4=
github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/hashicorp/aws-sdk-go-base v1.1.0 h1:27urM3JAp6v+Oj/Ea5ULZwuFPK9cO1RUdEpV+rNdSAc=
github.com/hashicorp/aws-sdk-go-base v1.1.0/go.mod h1:2fRjWDv3jJBeN6mVWFHV6hFTNeFBx2gpDLQaZNxUVAY=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I=
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
Expand Down Expand Up @@ -166,6 +172,11 @@ github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839 h1:W9WBk7
github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839/go.mod h1:xaLFMmpvUxqXtVkUJfg9QmT88cDaCJ3ZKgdZ78oO8Qo=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
github.com/jhump/protoreflect v1.15.1 h1:HUMERORf3I3ZdX05WaQ6MIpd/NJ434hTp5YiKgfCL6c=
github.com/jmespath/go-jmespath v0.3.0/go.mod h1:9QtRXoHjLGCJ5IBSaohpXITPlowMeeYCZ7fLUTSywik=
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
Expand Down Expand Up @@ -202,6 +213,7 @@ github.com/mitchellh/cli v1.1.5/go.mod h1:v8+iFts2sPIKUV1ltktPXMCC8fumSKFItNcD2c
github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw=
github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw=
github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/go-testing-interface v1.14.1 h1:jrgshOhYAUVNMAJiKbEu7EqAwgJJ2JqpQmpLJOu07cU=
github.com/mitchellh/go-testing-interface v1.14.1/go.mod h1:gfgS7OtZj6MA4U1UrDRp04twqAjfvlZyCfX3sDjEym8=
github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0=
Expand All @@ -216,8 +228,8 @@ github.com/oklog/run v1.1.0 h1:GEenZ1cK0+q0+wsJew9qUg/DyD8k3JzYsZAi5gYi2mA=
github.com/oklog/run v1.1.0/go.mod h1:sVPdnTZT1zYwAJeCMu2Th4T21pA3FPOQRfWjQlk7DVU=
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
github.com/orange-cloudavenue/cloudavenue-sdk-go v0.2.0 h1:pNCOlxzCX7Q2/8zNApgWP8VeZFwNXABNVELWElqsxQE=
github.com/orange-cloudavenue/cloudavenue-sdk-go v0.2.0/go.mod h1:8HtVSQVDVoW1pk/pFUTTOOQ2TL1SErMxV7fmke2+acg=
github.com/orange-cloudavenue/cloudavenue-sdk-go v0.3.0 h1:S5ZOzQ7Iyk6/iAebdVH+H/gNs5EokUG/27l2z4TMb4w=
github.com/orange-cloudavenue/cloudavenue-sdk-go v0.3.0/go.mod h1:XyfayrWLUBIxh49bIZUnJUUo0B2E7Vloxvo+6Zn0K2w=
github.com/orange-cloudavenue/infrapi-sdk-go v0.1.4-0.20231005074857-89878ea119fb h1:1/Wc21Tp9RnDOUTjKBm9x3wi+UgUkDc2bv0fHJc5f2o=
github.com/orange-cloudavenue/infrapi-sdk-go v0.1.4-0.20231005074857-89878ea119fb/go.mod h1:pGa9mB6s+weCi5QtNe5nicp7yL0C/e+i+3wHRh4cjBE=
github.com/peterhellberg/link v1.2.0 h1:UA5pg3Gp/E0F2WdX7GERiNrPQrM1K6CVJUUWfHa4t6c=
Expand Down Expand Up @@ -298,10 +310,12 @@ golang.org/x/mod v0.13.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco=
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
Expand Down Expand Up @@ -332,6 +346,7 @@ golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand All @@ -343,6 +358,7 @@ golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
Expand Down Expand Up @@ -388,6 +404,7 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
2 changes: 1 addition & 1 deletion internal/helpers/testsacc/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func generateRandomString(format string) string {
case "longString":
return lorem.Sentence(1, 5)
default:
return randstr.String(16)
return randstr.String(16, "abcdefghijklmnopqrstuvwxyz")
}
}

Expand Down
4 changes: 4 additions & 0 deletions internal/provider/provider_datasources.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/provider/iam"
"github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/provider/network"
"github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/provider/publicip"
"github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/provider/s3"
"github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/provider/storage"
"github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/provider/vapp"
"github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/provider/vdc"
Expand Down Expand Up @@ -83,5 +84,8 @@ func (p *cloudavenueProvider) DataSources(_ context.Context) []func() datasource

// * BACKUP
backup.NewBackupDataSource,

// * S3
s3.NewBucketDataSource,
}
}
4 changes: 4 additions & 0 deletions internal/provider/provider_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/provider/iam"
"github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/provider/network"
"github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/provider/publicip"
"github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/provider/s3"
"github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/provider/vapp"
"github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/provider/vcda"
"github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/provider/vdc"
Expand Down Expand Up @@ -76,5 +77,8 @@ func (p *cloudavenueProvider) Resources(_ context.Context) []func() resource.Res

// * BACKUP
backup.NewBackupResource,

// * S3
s3.NewBucketResource,
}
}
82 changes: 82 additions & 0 deletions internal/provider/s3/base.go
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,unused
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,unused
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,unused
return retryWhen(ctx, config, func(err error) bool {
if err == nil {
return true
}

return !tfawserr.ErrCodeEquals(err, codes...)
})
}
Loading

0 comments on commit dd42a57

Please sign in to comment.