Skip to content
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

provider/aws: Add support S3 Object Lifecycle Rule #6220

Merged
merged 6 commits into from
Apr 20, 2016

Conversation

kjmkznr
Copy link
Contributor

@kjmkznr kjmkznr commented Apr 18, 2016

This pull request adds S3 object lifecycle management configuration.

resource "aws_s3_bucket" "bucket" {
    bucket = "my-bucket"
    acl = "private"

    lifecycle_rule {
        id = "log"
        prefix = "log/"
        enabled = true

        transition {
            days = 30
            storage_class = "STANDARD_IA"
        }
        transition {
            days = 60
            storage_class = "GLACIER"
        }
        expiration {
            days = 90
        }
    }
    lifecycle_rule {
        id = "tmp"
        prefix = "tmp/"
        enabled = true

        expiration {
            date = "2016-01-12"
        }
    }
}

Acceptance test

$ make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSS3Bucket_Lifecycle' 
==> Checking that code complies with gofmt requirements...
/home/kjmkznr/go/bin/stringer
go generate $(go list ./... | grep -v /vendor/)
TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSS3Bucket_Lifecycle -timeout 120m
=== RUN   TestAccAWSS3Bucket_Lifecycle
--- PASS: TestAccAWSS3Bucket_Lifecycle (23.39s)
PASS
ok      github.com/hashicorp/terraform/builtin/providers/aws    23.407s
$ make test TEST=./builtin/providers/aws 
==> Checking that code complies with gofmt requirements...
/home/kjmkznr/go/bin/stringer
go generate $(go list ./... | grep -v /vendor/)
TF_ACC= go test ./builtin/providers/aws  -timeout=30s -parallel=4
ok      github.com/hashicorp/terraform/builtin/providers/aws    0.354s

@kjmkznr
Copy link
Contributor Author

kjmkznr commented Apr 18, 2016

Sorry, I forgot to check for the vet command.
I will fix soon.

@ajlanghorn
Copy link
Contributor

<3

if len(lifecycle.Rules) > 0 {
rules := make([]map[string]interface{}, 0, len(lifecycle.Rules))

for _, lifecycleRule := range lifecycle.Rules {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a chance any of these dereferenced properties may not exist? If so then, when dereferencing, we will get a panic

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should basically exists in response, but I added check code just in case.

@stack72
Copy link
Contributor

stack72 commented Apr 18, 2016

just a quick point here - when I was building the Azure provider - 3 levels of nesting sometimes gave some interesting results. So we need to keep an eye on this :)

@aviflax
Copy link

aviflax commented Apr 18, 2016

Semantics look fantastic! Thank you!

@kjmkznr
Copy link
Contributor Author

kjmkznr commented Apr 19, 2016

@stack72
Thanks reviews!
I fixed as was pointed out in comment.

just a quick point here - when I was building the Azure provider - 3 levels of nesting sometimes gave some interesting results. So we need to keep an eye on this :)

I'm sorry, I don't understand.
Do I need to fix something?
What is interest results?

@stack72
Copy link
Contributor

stack72 commented Apr 19, 2016

Hi @kjmkznr

Ignore my comments about the nesting - it's not an issue. BUT when i run all of the S3 bucket tests, I now see the following:

make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSS3Bucket_' 2>~/tf.log
==> Checking that code complies with gofmt requirements...
/Users/stacko/Code/go/bin/stringer
go generate $(go list ./... | grep -v /vendor/)
TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSS3Bucket_ -timeout 120m
=== RUN   TestAccAWSS3Bucket_Notification
--- FAIL: TestAccAWSS3Bucket_Notification (22.63s)
    testing.go:154: Step 0 error: Error applying: 1 error(s) occurred:

        * aws_s3_bucket.bucket: NoSuchLifecycleConfiguration: The lifecycle configuration does not exist
            status code: 404, request id: 796BA42E16CABD2F
    testing.go:175: Error destroying resource! WARNING: Dangling resources
        may exist. The full state and error is shown below.

        Error: Error refreshing: 1 error(s) occurred:

        * aws_s3_bucket.bucket: NoSuchLifecycleConfiguration: The lifecycle configuration does not exist
            status code: 404, request id: 6DC4F0C56A308207

        State: <nil>
=== RUN   TestAccAWSS3Bucket_NotificationWithoutFilter
--- FAIL: TestAccAWSS3Bucket_NotificationWithoutFilter (20.72s)
    testing.go:154: Step 0 error: Error applying: 1 error(s) occurred:

        * aws_s3_bucket.bucket: NoSuchLifecycleConfiguration: The lifecycle configuration does not exist
            status code: 404, request id: 8A803B0235F45AF4
    testing.go:175: Error destroying resource! WARNING: Dangling resources
        may exist. The full state and error is shown below.

        Error: Error refreshing: 1 error(s) occurred:

        * aws_s3_bucket.bucket: NoSuchLifecycleConfiguration: The lifecycle configuration does not exist
            status code: 404, request id: 54D63AD66FFB82D5

        State: <nil>
=== RUN   TestAccAWSS3Bucket_basic
--- FAIL: TestAccAWSS3Bucket_basic (21.54s)
    testing.go:154: Step 0 error: Error applying: 1 error(s) occurred:

        * aws_s3_bucket.bucket: NoSuchLifecycleConfiguration: The lifecycle configuration does not exist
            status code: 404, request id: 532767AA9682C193
    testing.go:175: Error destroying resource! WARNING: Dangling resources
        may exist. The full state and error is shown below.

        Error: Error refreshing: 1 error(s) occurred:

        * aws_s3_bucket.bucket: NoSuchLifecycleConfiguration: The lifecycle configuration does not exist
            status code: 404, request id: E6FB35C32C931C5E

        State: <nil>
=== RUN   TestAccAWSS3Bucket_Policy
--- FAIL: TestAccAWSS3Bucket_Policy (22.87s)
    testing.go:154: Step 0 error: Error applying: 1 error(s) occurred:

        * aws_s3_bucket.bucket: NoSuchLifecycleConfiguration: The lifecycle configuration does not exist
            status code: 404, request id: B61BEAA467EE28F4
    testing.go:175: Error destroying resource! WARNING: Dangling resources
        may exist. The full state and error is shown below.

        Error: Error refreshing: 1 error(s) occurred:

        * aws_s3_bucket.bucket: NoSuchLifecycleConfiguration: The lifecycle configuration does not exist
            status code: 404, request id: 403B3CDABE43A28F

        State: <nil>
=== RUN   TestAccAWSS3Bucket_UpdateAcl
--- FAIL: TestAccAWSS3Bucket_UpdateAcl (22.04s)
    testing.go:154: Step 0 error: Error applying: 1 error(s) occurred:

        * aws_s3_bucket.bucket: NoSuchLifecycleConfiguration: The lifecycle configuration does not exist
            status code: 404, request id: 1332CA491E3AE1B2
    testing.go:175: Error destroying resource! WARNING: Dangling resources
        may exist. The full state and error is shown below.

        Error: Error refreshing: 1 error(s) occurred:

        * aws_s3_bucket.bucket: NoSuchLifecycleConfiguration: The lifecycle configuration does not exist
            status code: 404, request id: FA02515E8AE637EE

        State: <nil>
=== RUN   TestAccAWSS3Bucket_Website_Simple
--- FAIL: TestAccAWSS3Bucket_Website_Simple (24.81s)
    testing.go:154: Step 0 error: Error applying: 1 error(s) occurred:

        * aws_s3_bucket.bucket: NoSuchLifecycleConfiguration: The lifecycle configuration does not exist
            status code: 404, request id: 7E25E5BDBD9F48ED
    testing.go:175: Error destroying resource! WARNING: Dangling resources
        may exist. The full state and error is shown below.

        Error: Error refreshing: 1 error(s) occurred:

        * aws_s3_bucket.bucket: NoSuchLifecycleConfiguration: The lifecycle configuration does not exist
            status code: 404, request id: 630E9F25BC785915

        State: <nil>
=== RUN   TestAccAWSS3Bucket_WebsiteRedirect
--- FAIL: TestAccAWSS3Bucket_WebsiteRedirect (28.52s)
    testing.go:154: Step 0 error: Error applying: 1 error(s) occurred:

        * aws_s3_bucket.bucket: NoSuchLifecycleConfiguration: The lifecycle configuration does not exist
            status code: 404, request id: 2F93706E561BAC07
    testing.go:175: Error destroying resource! WARNING: Dangling resources
        may exist. The full state and error is shown below.

        Error: Error refreshing: 1 error(s) occurred:

        * aws_s3_bucket.bucket: NoSuchLifecycleConfiguration: The lifecycle configuration does not exist
            status code: 404, request id: 26FE97469B0AC003

        State: <nil>
=== RUN   TestAccAWSS3Bucket_WebsiteRoutingRules
--- FAIL: TestAccAWSS3Bucket_WebsiteRoutingRules (23.24s)
    testing.go:154: Step 0 error: Error applying: 1 error(s) occurred:

        * aws_s3_bucket.bucket: NoSuchLifecycleConfiguration: The lifecycle configuration does not exist
            status code: 404, request id: 981441D2C0C9EA0F
    testing.go:175: Error destroying resource! WARNING: Dangling resources
        may exist. The full state and error is shown below.

        Error: Error refreshing: 1 error(s) occurred:

        * aws_s3_bucket.bucket: NoSuchLifecycleConfiguration: The lifecycle configuration does not exist
            status code: 404, request id: 6FB2653631814E1B

        State: <nil>
=== RUN   TestAccAWSS3Bucket_shouldFailNotFound
--- FAIL: TestAccAWSS3Bucket_shouldFailNotFound (24.82s)
    testing.go:154: Step 0 error: Error applying: 1 error(s) occurred:

        * aws_s3_bucket.bucket: NoSuchLifecycleConfiguration: The lifecycle configuration does not exist
            status code: 404, request id: 1C2DAC5C96A068BA
    testing.go:175: Error destroying resource! WARNING: Dangling resources
        may exist. The full state and error is shown below.

        Error: Error refreshing: 1 error(s) occurred:

        * aws_s3_bucket.bucket: NoSuchLifecycleConfiguration: The lifecycle configuration does not exist
            status code: 404, request id: F558276F6C15994E

        State: <nil>
=== RUN   TestAccAWSS3Bucket_Versioning
--- FAIL: TestAccAWSS3Bucket_Versioning (21.13s)
    testing.go:154: Step 0 error: Error applying: 1 error(s) occurred:

        * aws_s3_bucket.bucket: NoSuchLifecycleConfiguration: The lifecycle configuration does not exist
            status code: 404, request id: 8DFE8967311791B7
    testing.go:175: Error destroying resource! WARNING: Dangling resources
        may exist. The full state and error is shown below.

        Error: Error refreshing: 1 error(s) occurred:

        * aws_s3_bucket.bucket: NoSuchLifecycleConfiguration: The lifecycle configuration does not exist
            status code: 404, request id: F27FC80250CBA25F

        State: <nil>
=== RUN   TestAccAWSS3Bucket_Cors
--- FAIL: TestAccAWSS3Bucket_Cors (26.24s)
    testing.go:154: Step 0 error: Error applying: 1 error(s) occurred:

        * aws_s3_bucket.bucket: NoSuchLifecycleConfiguration: The lifecycle configuration does not exist
            status code: 404, request id: C6E17788D25E2A69
    testing.go:175: Error destroying resource! WARNING: Dangling resources
        may exist. The full state and error is shown below.

        Error: Error refreshing: 1 error(s) occurred:

        * aws_s3_bucket.bucket: NoSuchLifecycleConfiguration: The lifecycle configuration does not exist
            status code: 404, request id: 14CEA0E8FFAAD3F9

        State: <nil>
=== RUN   TestAccAWSS3Bucket_Logging
--- FAIL: TestAccAWSS3Bucket_Logging (23.07s)
    testing.go:154: Step 0 error: Error applying: 1 error(s) occurred:

        * aws_s3_bucket.log_bucket: NoSuchLifecycleConfiguration: The lifecycle configuration does not exist
            status code: 404, request id: 6BD0B8723977C63B
    testing.go:175: Error destroying resource! WARNING: Dangling resources
        may exist. The full state and error is shown below.

        Error: Error refreshing: 1 error(s) occurred:

        * aws_s3_bucket.log_bucket: NoSuchLifecycleConfiguration: The lifecycle configuration does not exist
            status code: 404, request id: ED125DEFA295B715

        State: <nil>
=== RUN   TestAccAWSS3Bucket_Lifecycle
--- PASS: TestAccAWSS3Bucket_Lifecycle (92.03s)
FAIL
exit status 1
FAIL    github.com/hashicorp/terraform/builtin/providers/aws    373.675s

@stack72 stack72 self-assigned this Apr 19, 2016
@stack72 stack72 added the waiting-response An issue/pull request is waiting for a response from the community label Apr 19, 2016
@kjmkznr
Copy link
Contributor Author

kjmkznr commented Apr 20, 2016

@stack72

I forgat check other acceptance tests.
I fixed it.

@stack72
Copy link
Contributor

stack72 commented Apr 20, 2016

Hi @kjmkznr

this looks great now - thanks so much for the fix on the 404!

The new test run confirmed it worked as expected:

make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSS3Bucket_' 2>~/tf.log
==> Checking that code complies with gofmt requirements...
/Users/stacko/Code/go/bin/stringer
go generate $(go list ./... | grep -v /vendor/)
TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSS3Bucket_ -timeout 120m
=== RUN   TestAccAWSS3Bucket_Notification
--- PASS: TestAccAWSS3Bucket_Notification (126.44s)
=== RUN   TestAccAWSS3Bucket_NotificationWithoutFilter
--- PASS: TestAccAWSS3Bucket_NotificationWithoutFilter (55.94s)
=== RUN   TestAccAWSS3Bucket_basic
--- PASS: TestAccAWSS3Bucket_basic (34.73s)
=== RUN   TestAccAWSS3Bucket_Policy
--- PASS: TestAccAWSS3Bucket_Policy (88.65s)
=== RUN   TestAccAWSS3Bucket_UpdateAcl
--- PASS: TestAccAWSS3Bucket_UpdateAcl (65.63s)
=== RUN   TestAccAWSS3Bucket_Website_Simple
--- PASS: TestAccAWSS3Bucket_Website_Simple (101.24s)
=== RUN   TestAccAWSS3Bucket_WebsiteRedirect
--- PASS: TestAccAWSS3Bucket_WebsiteRedirect (100.66s)
=== RUN   TestAccAWSS3Bucket_WebsiteRoutingRules
--- PASS: TestAccAWSS3Bucket_WebsiteRoutingRules (70.57s)
=== RUN   TestAccAWSS3Bucket_shouldFailNotFound
--- PASS: TestAccAWSS3Bucket_shouldFailNotFound (19.91s)
=== RUN   TestAccAWSS3Bucket_Versioning
--- PASS: TestAccAWSS3Bucket_Versioning (97.40s)
=== RUN   TestAccAWSS3Bucket_Cors
--- PASS: TestAccAWSS3Bucket_Cors (35.75s)
=== RUN   TestAccAWSS3Bucket_Logging
--- PASS: TestAccAWSS3Bucket_Logging (63.50s)
=== RUN   TestAccAWSS3Bucket_Lifecycle
--- PASS: TestAccAWSS3Bucket_Lifecycle (66.68s)
PASS
ok      github.com/hashicorp/terraform/builtin/providers/aws    918.631s

Thanks again :)

Paul

@stack72 stack72 merged commit 5e33517 into hashicorp:master Apr 20, 2016
@kjmkznr
Copy link
Contributor Author

kjmkznr commented Apr 20, 2016

Thanks!

@kjmkznr kjmkznr deleted the aws-s3-lifecycle branch June 7, 2016 12:27
@ghost
Copy link

ghost commented Apr 25, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement provider/aws waiting-response An issue/pull request is waiting for a response from the community
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants