Skip to content

Commit 4caecf1

Browse files
committed
feat(obj): add lifecycle documentation
1 parent bc639d8 commit 4caecf1

6 files changed

+2523
-1519
lines changed

docs/guides/migration_guide_v2.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ The [above example](#scaleway_server-gt-scaleway_instance_server) shows how this
296296

297297
The `scaleway_bucket` was moved to the `object` product in the `storage` product category.
298298

299-
It's behaviour remained the same, but we also added an [`acl` attribute](../resources/object_bucket.md#acl).
299+
It's behaviour remained the same, but we also added an [`acl` attribute](../resources/object_bucket.md#the-acl).
300300
This attribute takes canned ACLs.
301301

302302
### LoadBalancer

docs/resources/object_bucket.md

+120-1
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,106 @@ resource "scaleway_object_bucket" "some_bucket" {
2121
}
2222
```
2323

24+
### Using object lifecycle
25+
26+
```hcl
27+
resource "scaleway_object_bucket" "main"{
28+
name = "mybuckectid"
29+
region = "fr-par"
30+
acl = "private"
31+
32+
# This lifecycle configuration rule will make that all objects that got a filter key that start with (path1/) be transferred
33+
# from their default storage class (STANDARD, ONEZONE_IA) to GLACIER after 120 days counting
34+
# from their creation and then 365 days after that they will be expired and deleted.
35+
lifecycle_rule {
36+
id = "id1"
37+
prefix = "path1/"
38+
enabled = true
39+
40+
expiration {
41+
days = 365
42+
}
43+
44+
transition {
45+
days = 120
46+
storage_class = "GLACIER"
47+
}
48+
}
49+
50+
# This lifecycle configuration rule specifies that all objects (identified by the key name prefix (path2/) in the rule)
51+
# from their creation and then 50 days after that they will be expired and deleted.
52+
lifecycle_rule {
53+
id = "id2"
54+
prefix = "path2/"
55+
enabled = true
56+
57+
expiration {
58+
days = "50"
59+
}
60+
}
61+
62+
# This lifecycle configuration rule remove any object with (path3/) prefix that match
63+
# with the tags one day after creation.
64+
lifecycle_rule {
65+
id = "id3"
66+
prefix = "path3/"
67+
enabled = false
68+
69+
tags = {
70+
"tagKey" = "tagValue"
71+
"terraform" = "hashicorp"
72+
}
73+
74+
expiration {
75+
days = "1"
76+
}
77+
}
78+
79+
# This lifecycle configuration rule specifies a tag-based filter (tag1/value1).
80+
# This rule directs Scaleway S3 to transition objects S3 Glacier class soon after creation.
81+
# It is also disable temporaly.
82+
lifecycle_rule {
83+
id = "id4"
84+
enabled = true
85+
86+
tags = {
87+
"tag1" = "value1"
88+
}
89+
90+
transition {
91+
days = 0
92+
storage_class = "GLACIER"
93+
}
94+
}
95+
96+
# This lifecycle configuration rule specifies with the AbortIncompleteMultipartUpload action to
97+
# stop incomplete multipart uploads (identified by the key name prefix (path5/) in the rule)
98+
# if they aren't completed within a specified number of days after initiation.
99+
# Note: It's not recommended using prefix/ for AbortIncompleteMultipartUpload as any incomplete multipart upload will be billed
100+
lifecycle_rule {
101+
# prefix = "path5/"
102+
enabled = true
103+
abort_incomplete_multipart_upload_days = 30
104+
}
105+
}
106+
```
107+
24108
## Arguments Reference
25109

110+
26111
The following arguments are supported:
27112

28113
* `name` - (Required) The name of the bucket.
29114
* `tags` - (Optional) A list of tags (key / value) for the bucket.
30-
* `acl` - (Optional) The [canned ACL](https://docs.aws.amazon.com/AmazonS3/latest/userguide/acl_overview.html#canned-acl) you want to apply to the bucket.
115+
* `acl` - (Optional) The canned ACL you want to apply to the bucket.
31116
* `region` - (Optional) The [region](https://developers.scaleway.com/en/quickstart/#region-definition) in which the bucket should be created.
32117
* `versioning` - (Optional) A state of [versioning](https://docs.aws.amazon.com/AmazonS3/latest/dev/Versioning.html) (documented below)
33118
* `cors_rule` - (Optional) A rule of [Cross-Origin Resource Sharing](https://docs.aws.amazon.com/AmazonS3/latest/dev/cors.html) (documented below).
34119

120+
## The ACL
121+
122+
Please check the [canned ACL](https://docs.aws.amazon.com/AmazonS3/latest/userguide/acl_overview.html#canned-acl)
123+
35124
The `CORS` object supports the following:
36125

37126
* `allowed_headers` (Optional) Specifies which headers are allowed.
@@ -40,6 +129,35 @@ The `CORS` object supports the following:
40129
* `expose_headers` (Optional) Specifies expose header in the response.
41130
* `max_age_seconds` (Optional) Specifies time in seconds that browser can cache the response for a preflight request.
42131

132+
The `lifecycle_rule` (Optional) object supports the following:
133+
134+
* `id` - (Optional) Unique identifier for the rule. Must be less than or equal to 255 characters in length.
135+
* `prefix` - (Optional) Object key prefix identifying one or more objects to which the rule applies.
136+
* `tags` - (Optional) Specifies object tags key and value.
137+
* `enabled` - (Required) The element value can be either Enabled or Disabled. If a rule is disabled, Scaleway S3 doesn't perform any of the actions defined in the rule.
138+
139+
* `abort_incomplete_multipart_upload_days` (Optional) Specifies the number of days after initiating a multipart upload when the multipart upload must be completed.
140+
141+
* ~> **Important:** It's not recommended using `prefix` for `AbortIncompleteMultipartUpload` as any incomplete multipart upload will be billed
142+
143+
* `expiration` - (Optional) Specifies a period in the object's expire (documented below).
144+
* `transition` - (Optional) Specifies a period in the object's transitions (documented below).
145+
146+
At least one of `abort_incomplete_multipart_upload_days`, `expiration`, `transition` must be specified.
147+
148+
The `expiration` object supports the following
149+
150+
* `days` (Optional) Specifies the number of days after object creation when the specific rule action takes effect.
151+
152+
~> **Important:** If versioning is enabled, this rule only deletes the current version of an object.
153+
154+
The `transition` object supports the following
155+
156+
* `days` (Optional) Specifies the number of days after object creation when the specific rule action takes effect.
157+
* `storage_class` (Required) Specifies the Scaleway [storage class](https://www.scaleway.com/en/docs/storage/object/concepts/#storage-class) `STANDARD`, `GLACIER`, `ONEZONE_IA` to which you want the object to transition.
158+
159+
~> **Important:** `ONEZONE_IA` is only available in `fr-par` region. The storage class `GLACIER` is not available in `pl-waw` region.
160+
43161
The `versioning` object supports the following:
44162

45163
* `enabled` - (Optional) Enable versioning. Once you version-enable a bucket, it can never return to an unversioned state. You can, however, suspend versioning on that bucket.
@@ -50,6 +168,7 @@ In addition to all above arguments, the following attribute is exported:
50168

51169
* `id` - The unique name of the bucket.
52170
* `endpoint` - The endpoint URL of the bucket
171+
* `region` - The Scaleway region this bucket resides in.
53172

54173
## Import
55174

go.sum

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj
6767
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
6868
github.com/aws/aws-sdk-go v1.15.78/go.mod h1:E3/ieXAlvM0XWO57iftYVDLLvQ824smPP3ATZkfNZeM=
6969
github.com/aws/aws-sdk-go v1.25.3/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
70+
github.com/aws/aws-sdk-go v1.31.9/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0=
7071
github.com/aws/aws-sdk-go v1.42.48 h1:8ZVBAsA9X2eCpSr/8SrWDk4BOT91wRdqxpAog875+K0=
7172
github.com/aws/aws-sdk-go v1.42.48/go.mod h1:OGr6lGMAKGlG9CVrYnWYDKIyb829c6EVBRjxqjmPepc=
7273
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d h1:xDfNPAt8lFiC1UJrqV3uuy861HCTo708pDMbjHHdCas=

scaleway/resource_object_bucket.go

+33-21
Original file line numberDiff line numberDiff line change
@@ -93,19 +93,22 @@ func resourceScalewayObjectBucket() *schema.Resource {
9393
},
9494
},
9595
"lifecycle_rule": {
96-
Type: schema.TypeList,
97-
Optional: true,
96+
Type: schema.TypeList,
97+
Optional: true,
98+
Description: "Lifecycle configuration is a set of rules that define actions that Scaleway Object Storage applies to a group of objects",
9899
Elem: &schema.Resource{
99100
Schema: map[string]*schema.Schema{
100101
"id": {
101102
Type: schema.TypeString,
102103
Optional: true,
103104
Computed: true,
104105
ValidateFunc: validation.StringLenBetween(0, 255),
106+
Description: "Unique identifier for the rule",
105107
},
106108
"prefix": {
107-
Type: schema.TypeString,
108-
Optional: true,
109+
Type: schema.TypeString,
110+
Optional: true,
111+
Description: "The prefix identifying one or more objects to which the rule applies",
109112
},
110113
"tags": {
111114
Type: schema.TypeMap,
@@ -116,42 +119,49 @@ func resourceScalewayObjectBucket() *schema.Resource {
116119
Description: "The tags associated with the bucket lifecycle",
117120
},
118121
"enabled": {
119-
Type: schema.TypeBool,
120-
Required: true,
122+
Type: schema.TypeBool,
123+
Required: true,
124+
Description: "Specifies if the configuration rule is Enabled or Disabled",
121125
},
122126
"abort_incomplete_multipart_upload_days": {
123-
Type: schema.TypeInt,
124-
Optional: true,
127+
Type: schema.TypeInt,
128+
Optional: true,
129+
Description: "Specifies the number of days after initiating a multipart upload when the multipart upload must be completed",
125130
},
126131
"expiration": {
127-
Type: schema.TypeList,
128-
Optional: true,
129-
MaxItems: 1,
132+
Type: schema.TypeList,
133+
Optional: true,
134+
MaxItems: 1,
135+
Description: "Specifies a period in the object's expire",
130136
Elem: &schema.Resource{
131137
Schema: map[string]*schema.Schema{
132138
"days": {
133139
Type: schema.TypeInt,
134140
Required: true,
135141
ValidateFunc: validation.IntAtLeast(0),
142+
Description: "Specifies the number of days after object creation when the specific rule action takes effect",
136143
},
137144
},
138145
},
139146
},
140147
"transition": {
141-
Type: schema.TypeSet,
142-
Optional: true,
143-
Set: transitionHash,
148+
Type: schema.TypeSet,
149+
Optional: true,
150+
Set: transitionHash,
151+
Description: "Define when objects transition to another storage class",
144152
Elem: &schema.Resource{
145153
Schema: map[string]*schema.Schema{
146154
"days": {
147155
Type: schema.TypeInt,
148156
Optional: true,
149157
ValidateFunc: validation.IntAtLeast(0),
158+
Description: "Specifies the number of days after object creation when the specific rule action takes effect",
150159
},
151160
"storage_class": {
152161
Type: schema.TypeString,
153162
Required: true,
154163
ValidateFunc: validation.StringInSlice(TransitionSCWStorageClassValues(), false),
164+
Description: "Specifies the Scaleway Object Storage class to which you want the object to transition",
155165
},
156166
},
157167
},
@@ -161,16 +171,18 @@ func resourceScalewayObjectBucket() *schema.Resource {
161171
},
162172
"region": regionSchema(),
163173
"versioning": {
164-
Type: schema.TypeList,
165-
Optional: true,
166-
Computed: true,
167-
MaxItems: 1,
174+
Type: schema.TypeList,
175+
Optional: true,
176+
Computed: true,
177+
MaxItems: 1,
178+
Description: "Allow multiple versions of an object in the same bucket",
168179
Elem: &schema.Resource{
169180
Schema: map[string]*schema.Schema{
170181
"enabled": {
171-
Type: schema.TypeBool,
172-
Optional: true,
173-
Default: false,
182+
Description: "Enable versioning. Once you version-enable a bucket, it can never return to an unversioned state",
183+
Type: schema.TypeBool,
184+
Optional: true,
185+
Default: false,
174186
},
175187
},
176188
},

scaleway/resource_object_bucket_test.go

+41
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,47 @@ func TestAccScalewayObjectBucket_Basic(t *testing.T) {
281281
}),
282282
),
283283
},
284+
{
285+
Config: fmt.Sprintf(`
286+
resource "scaleway_object_bucket" "par-bucket-lifecycle"{
287+
name = "%s"
288+
region = "fr-par"
289+
acl = "private"
290+
291+
lifecycle_rule {
292+
id = "id1"
293+
prefix = "path1/"
294+
enabled = true
295+
abort_incomplete_multipart_upload_days = 30
296+
}
297+
}
298+
`, bucketLifecycle),
299+
Check: resource.ComposeTestCheckFunc(
300+
resource.TestCheckResourceAttr("scaleway_object_bucket.par-bucket-lifecycle", "name", bucketLifecycle),
301+
resource.TestCheckResourceAttr(resourceNameLifecycle, "lifecycle_rule.0.id", "id1"),
302+
resource.TestCheckResourceAttr(resourceNameLifecycle, "lifecycle_rule.0.prefix", "path1/"),
303+
resource.TestCheckResourceAttr(resourceNameLifecycle, "lifecycle_rule.0.abort_incomplete_multipart_upload_days", "30"),
304+
),
305+
},
306+
{
307+
Config: fmt.Sprintf(`
308+
resource "scaleway_object_bucket" "par-bucket-lifecycle"{
309+
name = "%s"
310+
region = "fr-par"
311+
acl = "private"
312+
313+
lifecycle_rule {
314+
prefix = "path1/"
315+
enabled = true
316+
abort_incomplete_multipart_upload_days = 30
317+
}
318+
}
319+
`, bucketLifecycle),
320+
Check: resource.ComposeTestCheckFunc(
321+
resource.TestCheckResourceAttrSet(resourceNameLifecycle, "lifecycle_rule.0.id"),
322+
resource.TestCheckResourceAttr(resourceNameLifecycle, "lifecycle_rule.0.abort_incomplete_multipart_upload_days", "30"),
323+
),
324+
},
284325
},
285326
})
286327
}

0 commit comments

Comments
 (0)