iann0036 / former2

Generate CloudFormation / Terraform / Troposphere templates from your existing AWS resources.
https://former2.com
MIT License
2.21k stars 267 forks source link

S3 Lifecycle policy rules are not being generated correctly #240

Open jf13 opened 2 years ago

jf13 commented 2 years ago

I just discovered that Former2 does not generate S3 Lifecycle policy rules correctly.

Example RAW Output:

  [
      {
          "id": "000000000000-bucketname",
          "type": "s3.bucket",
          "data": {
              "Name": "000000000000-bucketname",
              "CreationDate": "2022-02-19T07:49:58.000Z",
              "Lifecycle": {
                  "Rules": [
                      {
                          "Expiration": {
                              "Days": 365
                          },
                          "ID": "OneYearLifecycleRule",
                          "Status": "Enabled",
                          "Transition": {
                              "Days": 30,
                              "StorageClass": "STANDARD_IA"
                          }
                      }
                  ]
              },
              "NotificationConfiguration": {
                  "TopicConfigurations": [],
                  "QueueConfigurations": [],
                  "LambdaFunctionConfigurations": []
              },
              "AnalyticsConfigurations": {
                  "IsTruncated": false,
                  "AnalyticsConfigurationList": []
              },
              "InventoryConfigurations": {
                  "InventoryConfigurationList": [],
                  "IsTruncated": false
              },
              "MetricsConfigurations": {
                  "IsTruncated": false,
                  "MetricsConfigurationList": []
              },
              "IntelligentTieringConfiguration": []
          },
          "region": "us-east-1"
      }
  ]

Here is the CloudFormation output with the missing transition to IA storage:

  AWSTemplateFormatVersion: "2010-09-09"
  Metadata:
      Generator: "former2"
  Description: ""
  Resources:
      S3Bucket:
          Type: "AWS::S3::Bucket"
          Properties:
              BucketName: !Sub "${AWS::AccountId}-bucketname"
              LifecycleConfiguration: 
                  Rules: 
                    - 
                      Id: "OneYearLifecycleRule"
                      Status: "Enabled"
                      ExpirationInDays: 365
iann0036 commented 2 years ago

Hey @jf13,

Thanks for raising!

I've made a change to hopefully allow the correct output for Transitions to happen. Let me know how it goes.

jf13 commented 2 years ago

Hey @iann0036
I can confirm that it works for Cloudformation.

I've just checked Terraform and it only generates s3 bucket resource without any Lifecycle rules:

resource "aws_s3_bucket" "S3Bucket" {
    bucket = "111111111111-bucketname"
}