-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
A bug when enabling aws_s3_bucket.replication_configuration.rules.destination.metrics without ReplicationTime #22774
Comments
Hi @husseinmimi , thank you again for creating this new issue. It looks like the Reference: terraform-provider-aws/internal/service/s3/bucket.go Lines 480 to 490 in 9f214e5
terraform-provider-aws/internal/service/s3/bucket.go Lines 2114 to 2121 in 9f214e5
|
@anGie44 thanks for your reply but i am not talking about the default value of time in metrics block, i am talking about this:
So the bug is that I hope that issue is more clear now. |
Hi again @husseinmimi ! Yes, unfortunately it's not super clear from the terrraform CLI side but the problem goes back to the data sent in the API request of So when the terraform config is the following: resource "aws_s3_bucket" "source" {
## settings
destination {
bucket = aws_s3_bucket.destination.arn
storage_class = "STANDARD"
metrics {
status = "Enabled"
}
}
} By the time that configuration gets communicated to the AWS provider, the bd := []interface{}{
"bucket": "...".
"storage_class" : "STANDARD",
"metrics": []interface{}{
"status": "Enabled",
"minutes": "15", // because the aws_s3_bucket resource schema has defined this value so it gets passed into here
}
} which then causes the API request of ...
ruleDestination := &s3.Destination{}
if metrics, ok := bd["metrics"].([]interface{}); ok && len(metrics) > 0 {
metricsConfig := &s3.Metrics{}
metricsValues := metrics[0].(map[string]interface{})
metricsConfig.EventThreshold = &s3.ReplicationTimeValue{}
metricsConfig.Status = aws.String(metricsValues["status"].(string))
metricsConfig.EventThreshold.Minutes = aws.Int64(int64(metricsValues["minutes"].(int))) <-- we are setting this even though practitioners don't intend to in their terraform configurations
ruleDestination.Metrics = metricsConfig
}
rule := &s3.ReplicationRule{
Destination: ruleDestination,
}
i := &s3.PutBucketReplicationInput{
Bucket: aws.String(bucket),
ReplicationConfiguration: &s3.ReplicationConfiguration{
Rules: []*s3.Rule{}{rule},
},
} One way to work around this would be to follow the logic expressed in the error message which wouldn't introduce a breaking change: ruleDestination := &s3.Destination{}
// replication time control (RTC) <-- move this logic up here
if rtc, ok := bd["replication_time"].([]interface{}); ok && len(rtc) > 0 {
rtcValues := rtc[0].(map[string]interface{})
rtcConfig := &s3.ReplicationTime{}
rtcConfig.Status = aws.String(rtcValues["status"].(string))
rtcConfig.Time = &s3.ReplicationTimeValue{}
rtcConfig.Time.Minutes = aws.Int64(int64(rtcValues["minutes"].(int)))
ruleDestination.ReplicationTime = rtcConfig
}
if metrics, ok := bd["metrics"].([]interface{}); ok && len(metrics) > 0 {
metricsConfig := &s3.Metrics{}
metricsValues := metrics[0].(map[string]interface{})
metricsConfig.Status = aws.String(metricsValues["status"].(string))
// only set Metrics EventThreshold when ReplicationTime is specified and not Disabled
if ruleDestination.ReplicationTime != nil && ruleDestination.ReplicationTime.Status != "Disabled" {
metricsConfig.EventThreshold = &s3.ReplicationTimeValue{
Minutes: aws.Int64(int64(metricsValues["minutes"].(int))),
}
}
ruleDestination.Metrics = metricsConfig
}
rule := &s3.ReplicationRule{
Destination: ruleDestination,
}
i := &s3.PutBucketReplicationInput{
Bucket: aws.String(bucket),
ReplicationConfiguration: &s3.ReplicationConfiguration{
Rules: []*s3.Rule{}{rule},
},
} But with the downside that you'll always see a perpetual diff due to the expected default (15) as follows: Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
~ update in-place
Terraform will perform the following actions:
# aws_s3_bucket.bucket will be updated in-place
~ resource "aws_s3_bucket" "bucket" {
id = "tf-test-bucket-6118547079748010386"
tags = {}
# (10 unchanged attributes hidden)
~ replication_configuration {
# (1 unchanged attribute hidden)
- rules {
- id = "foobar" -> null
- priority = 0 -> null
- status = "Enabled" -> null
- destination {
- bucket = "arn:aws:s3:::tf-test-bucket-destination-6118547079748010386" -> null
- storage_class = "STANDARD" -> null
- metrics {
- minutes = 0 -> null
- status = "Enabled" -> null
}
}
- filter {
- prefix = "foo" -> null
- tags = {} -> null
}
}
+ rules {
+ id = "foobar"
+ status = "Enabled"
+ destination {
+ bucket = "arn:aws:s3:::tf-test-bucket-destination-6118547079748010386"
+ storage_class = "STANDARD"
+ metrics {
+ minutes = 15
+ status = "Enabled"
}
}
+ filter {
+ prefix = "foo"
}
}
}
# (1 unchanged block hidden)
}
Plan: 0 to add, 1 to change, 0 to destroy. To address the above diff (just brainstorming here), we could make a code change to remove the plan-time validation on resource "aws_s3_bucket" "bucket" {
...
metrics {
minutes = 0
status = "Enabled"
}
} |
Hi @anGie44, any updates on this? Can you recommend some workaround instead of using the |
Hi @husseinmimi , any news on this issue? I am having the same problem when trying to update 3 buckets with terraform after having defined the replication metrics via the UI and cannot run my pipelines properly. I am using the deprecated Thank you very much for your time! |
Hello @gari1995, No, there is no new updates for this issue |
Has anyone come up with a reasonable work-around here? |
@mr-niche @husseinmimiHarri
|
Thanks @anGie44 for fixing similar issue #21895 with this fix #21901, but also i got similar problem when using
aws_s3_bucket
.replication_configuration.rules. destination.metrics
block it was depends onaws_s3_bucket
.replication_configuration.rules. destination.replication_time
block.Community Note
Terraform CLI and Terraform AWS Provider Version
Terraform v1.0.1
on darwin_amd64
Affected Resource(s)
Terraform Configuration Files
resource.tf
Expected Behavior
Edit existing bucket to enable replication metrics
Actual Behavior
raise this error
Steps to Reproduce
status = "Enabled"
}
References
similar issue #21895
fix for issue fix #21901
Note: Fix done on aws_s3_bucket_replication_configuration resource not on aws_s3_bucket_resource.
The text was updated successfully, but these errors were encountered: