From 65125ade5567eee5ceef23430dc5569c3b728d41 Mon Sep 17 00:00:00 2001 From: arotchev Date: Tue, 20 Feb 2018 22:35:03 +0300 Subject: [PATCH] resource/aws_s3_bucket lifecycle_rule not reflected in state on disable --- aws/resource_aws_s3_bucket.go | 10 ++++------ aws/resource_aws_s3_bucket_test.go | 2 ++ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/aws/resource_aws_s3_bucket.go b/aws/resource_aws_s3_bucket.go index e8267aefa0a..d5cb754f8cf 100644 --- a/aws/resource_aws_s3_bucket.go +++ b/aws/resource_aws_s3_bucket.go @@ -850,9 +850,8 @@ func resourceAwsS3BucketRead(d *schema.ResourceData, meta interface{}) error { } } log.Printf("[DEBUG] S3 Bucket: %s, lifecycle: %v", d.Id(), lifecycle) + rules := make([]map[string]interface{}, 0, len(lifecycle.Rules)) if len(lifecycle.Rules) > 0 { - rules := make([]map[string]interface{}, 0, len(lifecycle.Rules)) - for _, lifecycleRule := range lifecycle.Rules { rule := make(map[string]interface{}) @@ -957,10 +956,9 @@ func resourceAwsS3BucketRead(d *schema.ResourceData, meta interface{}) error { rules = append(rules, rule) } - - if err := d.Set("lifecycle_rule", rules); err != nil { - return err - } + } + if err := d.Set("lifecycle_rule", rules); err != nil { + return err } // Read the bucket replication configuration diff --git a/aws/resource_aws_s3_bucket_test.go b/aws/resource_aws_s3_bucket_test.go index 16471265360..8b1384719ac 100644 --- a/aws/resource_aws_s3_bucket_test.go +++ b/aws/resource_aws_s3_bucket_test.go @@ -737,6 +737,8 @@ func TestAccAWSS3Bucket_Lifecycle(t *testing.T) { Config: testAccAWSS3BucketConfig(rInt), Check: resource.ComposeTestCheckFunc( testAccCheckAWSS3BucketExists("aws_s3_bucket.bucket"), + resource.TestCheckResourceAttr( + "aws_s3_bucket.bucket", "lifecycle_rule.#", "0"), ), }, },