Skip to content

Commit

Permalink
Update incorrect version 4 upgrade guide
Browse files Browse the repository at this point in the history
  • Loading branch information
anGie44 committed Mar 18, 2022
1 parent 5e0c839 commit 9bd37cf
Showing 1 changed file with 86 additions and 12 deletions.
98 changes: 86 additions & 12 deletions website/docs/guides/version-4-upgrade.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ resource and remove `lifecycle_rule` and its nested arguments in the `aws_s3_buc

~> **Note:** When configuring the `rule.filter` configuration block in the new `aws_s3_bucket_lifecycle_configuration` resource, use the AWS CLI s3api [get-bucket-lifecycle-configuration](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/s3api/get-bucket-lifecycle-configuration.html)
to get the source bucket's lifecycle configuration and determine if the `Filter` is configured as `"Filter" : {}` or `"Filter" : { "Prefix": "" }`.
If AWS returns the former, configure `rule.filter` as `filter {}`. Otherwise, configure `rule.filter` as `filter { prefix = "" }` as shown here:
If AWS returns the former, configure `rule.filter` as `filter {}`. Otherwise, neither a `rule.filter` nor `rule.prefix` parameter should be configured as shown here:

```terraform
resource "aws_s3_bucket" "example" {
Expand All @@ -556,10 +556,6 @@ resource "aws_s3_bucket_lifecycle_configuration" "example" {
id = "Keep previous version 30 days, then in Glacier another 60"
status = "Enabled"
filter {
prefix = ""
}
noncurrent_version_transition {
noncurrent_days = 30
storage_class = "GLACIER"
Expand All @@ -574,10 +570,6 @@ resource "aws_s3_bucket_lifecycle_configuration" "example" {
id = "Delete old incomplete multi-part uploads"
status = "Enabled"
filter {
prefix = ""
}
abort_incomplete_multipart_upload {
days_after_initiation = 7
}
Expand Down Expand Up @@ -648,6 +640,89 @@ resource "aws_s3_bucket" "example" {
# ... other configuration ...
}
resource "aws_s3_bucket_lifecycle_configuration" "example" {
bucket = aws_s3_bucket.example.id
rule {
id = "log-expiration"
status = "Enabled"
transition {
days = 30
storage_class = "STANDARD_IA"
}
transition {
days = 180
storage_class = "GLACIER"
}
}
}
```

Run `terraform import` on each new resource, _e.g._,

```shell
$ terraform import aws_s3_bucket_lifecycle_configuration.example yournamehere
aws_s3_bucket_lifecycle_configuration.example: Importing from ID "yournamehere"...
aws_s3_bucket_lifecycle_configuration.example: Import prepared!
Prepared aws_s3_bucket_lifecycle_configuration for import
aws_s3_bucket_lifecycle_configuration.example: Refreshing state... [id=yournamehere]

Import successful!

The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.
```

#### For Lifecycle Rules with `prefix`

For example, given this configuration:

```terraform
resource "aws_s3_bucket" "example" {
bucket = "yournamehere"
lifecycle_rule {
id = "log-expiration"
enabled = true
prefix = "foobar"
transition {
days = 30
storage_class = "STANDARD_IA"
}
transition {
days = 180
storage_class = "GLACIER"
}
}
}
```

You will receive the following error after upgrading:

```
│ Error: Value for unconfigurable attribute
│ with aws_s3_bucket.example,
│ on main.tf line 1, in resource "aws_s3_bucket" "example":
│ 1: resource "aws_s3_bucket" "example" {
│ Can't configure a value for "lifecycle_rule": its value will be decided automatically based on the result of applying this configuration.
```

Since the `lifecycle_rule` argument changed to read-only, update the configuration to use the `aws_s3_bucket_lifecycle_configuration`
resource and remove `lifecycle_rule` and its nested arguments in the `aws_s3_bucket` resource:

```terraform
resource "aws_s3_bucket" "example" {
bucket = "yournamehere"
# ... other configuration ...
}
resource "aws_s3_bucket_lifecycle_configuration" "example" {
bucket = aws_s3_bucket.example.id
Expand All @@ -656,7 +731,7 @@ resource "aws_s3_bucket_lifecycle_configuration" "example" {
status = "Enabled"
filter {
prefix = ""
prefix = "foobar"
}
transition {
Expand Down Expand Up @@ -687,8 +762,7 @@ The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.
```

#### For Lifecycle Rules with a `prefix`

#### For Lifecycle Rules with `prefix` and `tags`

For example, given this previous configuration:

Expand Down

0 comments on commit 9bd37cf

Please sign in to comment.