dtan4 / terraforming

Export existing AWS resources to Terraform style (tf, tfstate) / No longer actively maintained
http://terraforming.dtan4.net/
MIT License
4.29k stars 659 forks source link

improve-s3 #396

Open sergeylanzman opened 6 years ago

sergeylanzman commented 6 years ago

Add many features for s3.

Before

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

After

resource "aws_s3_bucket" "my_bucket" {
  bucket = "my-bucket"
  acl = "private"
 policy = <<POLICY
{
  "Version": "2012-10-17",
  "Id": "AWSConsole-AccessLogs-Policy-1414336270042",
  "Statement": [
    {
      "Sid": "AWSConsoleStmt-1414336270042",
      "Effect": "Allow",
      "Principal": {
        "AWS": "arn:aws:iam::44444:root"
      },
      "Action": "s3:PutObject",
      "Resource": "arn:aws:s3:::test/AWSLogs/34345/*"
    }
  ]
}
POLICY
  tags {
    "k8s" = "backup"
  }
  cors_rule {
    allowed_methods = [
      "GET"]
    allowed_origins = [
      "*"]
    allowed_headers = [
      "Authorization"]
    max_age_seconds = 3000
  }
  versioning {
    enabled = true
  }
  logging {
    target_bucket = "test"
    target_prefix = ""
  }
  lifecycle_rule {
    id = "Remove 7 days old backups"
    enabled = true
    prefix = ""
    transition {
      storage_class = "STANDARD_IA"
      days = 30
    }
    expiration {
      days = 31
    }
    noncurrent_version_transition {
      days = 30
      storage_class = "STANDARD_IA"
    }
    noncurrent_version_expiration {
      days = 31
    }
    abort_incomplete_multipart_upload_days = 7
  }
  website {
    index_document = "index.html"
    error_document = "ett.html"
    routing_rules = <<EOF
        [
  {
    "condition": {
      "http_error_code_returned_equals": "403"
    },
    "redirect": {
      "host_name": "mywebsite.com",
      "replace_key_prefix_with": "notfound/"
    }
  }
]
    EOF
  }
}

Know issue tfstate not update for new features, but you can run terraform refresh.

coveralls commented 6 years ago

Coverage Status

Coverage decreased (-0.4%) to 99.639% when pulling b9ebfdef04f4530c57925d8ba77a3a2a3bef9333 on sergeylanzman:improve-s3 into c1d467becef5645e14ff822860f3fc2a9868c066 on dtan4:master.

coveralls commented 6 years ago

Coverage Status

Coverage decreased (-0.4%) to 99.639% when pulling b9ebfdef04f4530c57925d8ba77a3a2a3bef9333 on sergeylanzman:improve-s3 into c1d467becef5645e14ff822860f3fc2a9868c066 on dtan4:master.

coveralls commented 6 years ago

Coverage Status

Coverage decreased (-0.4%) to 99.639% when pulling 5bd2c4d3b8217d72293d9f1bc952d4da0d0ed2d7 on sergeylanzman:improve-s3 into c1d467becef5645e14ff822860f3fc2a9868c066 on dtan4:master.

dtan4 commented 6 years ago

Sorry for the late review, but could you update unit tests at first?

Thank you for sending a patch to improve!

alexdotsh commented 6 years ago

@sergeylanzman @dtan4 Is this currently being worked on? If not then I can produce the tests and get it merged to master?

sergeylanzman commented 6 years ago

@alexmirkhaydarov I not working on this. I be happy if you can fix tests

GETandSELECT commented 5 years ago

@alexmirkhaydarov please fix the tests

alexdotsh commented 5 years ago

@GETandSELECT sure, I will try to add the tests in few weeks time.

sergeylanzman commented 5 years ago

@GETandSELECT @alexmirkhaydarov I wrote more generic solution for reverse terraform process include full support S3 https://github.com/GoogleCloudPlatform/terraformer

alexdotsh commented 5 years ago

I have fixed the tests under this PR It includes the original work from sergeylanzman and on top of it I added the tests. I'd be happy to push the changes to this branch @sergeylanzman - If you give me access to your repo?

sergeylanzman commented 5 years ago

@alexmirkhaydarov Done

alexdotsh commented 5 years ago

Pushed the changes to this branch now to fix the tests. Can you have a look @dtan4?

dimisjim commented 4 years ago

What's the status on this? Can it be merged?