-
Notifications
You must be signed in to change notification settings - Fork 9.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
r/s3_bucket_lifecycle_configuration: update value set in state for an empty filter
argument
#23232
r/s3_bucket_lifecycle_configuration: update value set in state for an empty filter
argument
#23232
Conversation
Import is not happy with this right now. My 3.74 Configresource "aws_s3_bucket" "example" {
bucket = "barrameda-994617143"
lifecycle_rule {
id = "log-expiration"
enabled = true
prefix = ""
transition {
days = 30
storage_class = "STANDARD_IA"
}
transition {
days = 180
storage_class = "GLACIER"
}
}
}
resource "aws_s3_bucket" "example2" {
bucket = "valladolid-817999296"
lifecycle_rule {
id = "Keep previous version 30 days, then in Glacier another 60"
enabled = true
noncurrent_version_transition {
days = 30
storage_class = "GLACIER"
}
noncurrent_version_expiration {
days = 90
}
}
lifecycle_rule {
id = "Delete old incomplete multi-part uploads"
enabled = true
abort_incomplete_multipart_upload_days = 7
}
}
resource "aws_s3_bucket" "example3" {
bucket = "granada-2433251135"
lifecycle_rule {
id = "log-expiration"
enabled = true
prefix = "log/"
transition {
days = 30
storage_class = "STANDARD_IA"
}
transition {
days = 180
storage_class = "GLACIER"
}
}
}
resource "aws_s3_bucket" "example4" {
bucket = "marbella-1354962447"
lifecycle_rule {
id = "log-expiration"
enabled = true
transition {
days = 30
storage_class = "STANDARD_IA"
}
transition {
days = 180
storage_class = "GLACIER"
}
}
} Import/v4 Configresource "aws_s3_bucket" "example" {
bucket = "barrameda-994617143"
}
resource "aws_s3_bucket_lifecycle_configuration" "example" {
bucket = aws_s3_bucket.example.id
rule {
id = "log-expiration"
status = "Enabled"
prefix = ""
transition {
days = 30
storage_class = "STANDARD_IA"
}
transition {
days = 180
storage_class = "GLACIER"
}
}
}
resource "aws_s3_bucket" "example2" {
bucket = "valladolid-817999296"
}
resource "aws_s3_bucket_lifecycle_configuration" "example2" {
bucket = aws_s3_bucket.example2.id
rule {
id = "Keep previous version 30 days, then in Glacier another 60"
status = "Enabled"
noncurrent_version_transition {
noncurrent_days = 30
storage_class = "GLACIER"
}
noncurrent_version_expiration {
noncurrent_days = 90
}
}
rule {
id = "Delete old incomplete multi-part uploads"
status = "Enabled"
abort_incomplete_multipart_upload {
days_after_initiation = 7
}
}
}
resource "aws_s3_bucket" "example3" {
bucket = "granada-2433251135"
}
resource "aws_s3_bucket_lifecycle_configuration" "example3" {
bucket = aws_s3_bucket.example3.id
rule {
id = "log-expiration"
status = "Enabled"
filter {
prefix = "log/"
}
transition {
days = 30
storage_class = "STANDARD_IA"
}
transition {
days = 180
storage_class = "GLACIER"
}
}
}
resource "aws_s3_bucket" "example4" {
bucket = "marbella-1354962447"
}
resource "aws_s3_bucket_lifecycle_configuration" "example4" {
bucket = aws_s3_bucket.example4.id
rule {
id = "log-expiration"
status = "Enabled"
transition {
days = 30
storage_class = "STANDARD_IA"
}
transition {
days = 180
storage_class = "GLACIER"
}
}
} Importing with this PR
Importing with v4.1.0
|
My current observations: If we apply
We can see resource "aws_s3_bucket_lifecycle_configuration" "example" {
bucket = aws_s3_bucket.example.id
rule {
id = "example"
filter {
prefix = ""
}
# ... etc. ...
} Similarly if we take example2 where prefix is never specified, the AWS CLI returns:
Here again we see prefix inside resource "aws_s3_bucket_lifecycle_configuration" "example2" {
bucket = aws_s3_bucket.example2.id
rule {
id = "Keep previous version 30 days, then in Glacier another 60"
status = "Enabled"
filter {
prefix = ""
}
noncurrent_version_transition {
noncurrent_days = 30
storage_class = "GLACIER"
}
noncurrent_version_expiration {
noncurrent_days = 90
}
}
rule {
id = "Delete old incomplete multi-part uploads"
status = "Enabled"
filter {
prefix = ""
}
abort_incomplete_multipart_upload {
days_after_initiation = 7
}
}
} This is all to say that I believe (a) v4.0 was doing the right thing with how Perhaps now the question is, if buckets are old, and the lifecycle configuration was configured in V1 format, does the s3api still return V2 format as seen above OR is V1 returned? something to ask the OP. |
Not a fan of having to set anything to empty or an empty string to make it work. Seems messy. I'd prefer a diff suppress. But, if needs must. |
@YakDriver one last experiment to show the change IMO represents reality. Let's say i create a bucket in the console, and the
and then the AWS Go SDK returns
so for terraform to be representative of what exists in S3, the resource would look like: resource "aws_s3_bucket_lifecycle_configuration" "example_bb" {
bucket = "its-me-bb-bucket"
rule {
id = "test"
status = "Enabled"
filter {}
noncurrent_version_transition {
noncurrent_days = 30
storage_class = "GLACIER_IR"
}
}
} and we should thus expect terraform to recognize the empty
|
Ah, I see the difference in opinion: viewing what AWS does as a source of correctness vs. not. I like a layer of correctness on top of the API to smooth out the various inconsistencies. But, there's something to be said for adhereing to "the way." |
Ahh yes that's a good way to put it 👍 I think in this case it's important contextual data to keep in terraform state but we can keep discussing 😃 . I'm gonna mark this as ready in the meantime. |
Documentation may need an edit but i'll double check with @justinretzolk if that's already in the works since we somewhat strayed from the original plan in Slack thread |
I've not started on documentation edits as of yet @anGie44 - happy to do so, but wanted to keep an eye on what the final outcome was first. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MPMB! 🎉 I especially like the branch "fitler!"
As long as I add in the fitler {}
, er, filter {}
my import tests pass.
Output from acceptance tests (us-west-2
):
% make testacc TESTS=TestAccS3BucketLifecycleConfig PKG=s3
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/s3/... -v -count 1 -parallel 20 -run='TestAccS3BucketLifecycleConfig' -timeout 180m
--- PASS: TestAccS3BucketLifecycleConfiguration_disappears (62.22s)
--- PASS: TestAccS3BucketLifecycleConfiguration_basic (201.36s)
--- PASS: TestAccS3BucketLifecycleConfiguration_prefix (206.86s)
--- PASS: TestAccS3BucketLifecycleConfiguration_nonCurrentVersionExpiration (206.87s)
--- PASS: TestAccS3BucketLifecycleConfiguration_TransitionDate_standardIa (206.87s)
--- PASS: TestAccS3BucketLifecycleConfiguration_RuleExpiration_emptyBlock (206.95s)
--- PASS: TestAccS3BucketLifecycleConfiguration_TransitionDate_intelligentTiering (207.01s)
--- PASS: TestAccS3BucketLifecycleConfiguration_TransitionStorageClassOnly_intelligentTiering (207.01s)
--- PASS: TestAccS3BucketLifecycleConfiguration_multipleRules (207.04s)
--- PASS: TestAccS3BucketLifecycleConfiguration_TransitionZeroDays_intelligentTiering (207.10s)
--- PASS: TestAccS3BucketLifecycleConfiguration_nonCurrentVersionTransition (207.11s)
--- PASS: TestAccS3BucketLifecycleConfiguration_EmptyFilter_NonCurrentVersions (208.66s)
--- PASS: TestAccS3BucketLifecycleConfiguration_RuleExpiration_expireMarkerOnly (281.83s)
--- PASS: TestAccS3BucketLifecycleConfiguration_filterWithPrefix (286.26s)
--- PASS: TestAccS3BucketLifecycleConfiguration_ruleAbortIncompleteMultipartUpload (286.55s)
--- PASS: TestAccS3BucketLifecycleConfiguration_disableRule (339.27s)
--- PASS: TestAccS3BucketLifecycleConfiguration_TransitionUpdateBetweenDaysAndDate_intelligentTiering (339.45s)
PASS
ok github.com/hashicorp/terraform-provider-aws/internal/service/s3 341.317s
…ilter in rule block; add more examples in upgrade guide
a68ea14
to
481687f
Compare
This functionality has been released in v4.2.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you! |
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
Community Note
Closes #23228
Description
Output from acceptance testing: