Untitled

 avatar
master007
plain_text
a month ago
1.1 kB
3
Indexable
module "my_s3_bucket" {
  source = "./modules/s3"  # or wherever your module is located

  bucket_name                = "my-unique-bucket"
  bucket_versioning_enabled  = true
  enable_cors                = true
  cors_rule = {
    allowed_methods = ["GET", "PUT"]
    allowed_origins = ["*"]
    allowed_headers = ["*"]
    expose_headers  = []
    max_age_seconds = 3600
  }

  # Lifecycle rules: Expire noncurrent versions after 30 days,
  # current versions after 365 days
  noncurrent_version_expiration = 30
  current_version_expiration    = 365

  # Additional bucket policy statements in JSON form
  policy_doc_json = jsonencode({
    Statement = [
      {
        Sid       = "AllowListingPublicRead"
        Effect    = "Allow"
        Principal = "*"
        Action    = ["s3:GetObject"]
        Resource  = "arn:aws:s3:::my-unique-bucket/*"
      }
    ]
  })

  # Optionally set up logging
  logging_destination = "my-logging-bucket"

  extra_tags = {
    team    = "example-team"
    project = "example-project"
  }
}

# Then you can reference the outputs
output "my_s3_bucket_name" {
  value = module.my_s3_bucket.bucket_name
}
Leave a Comment