Sunday, December 16, 2018

How to create S3 bucket in AWS using Terraform - Create S3 bucket in AWS using Terraform

Terraform is an infrastructure orchestration tool for creating web services in AWS automatically. You can use Terraform for provisioning S3 bucket in AWS.

sudo vi create_s3.tf

resource "aws_s3_bucket" "mybucket" {
  bucket = "my-tf-test-bucket"
  acl    = "public-read"
  website {
    index_document = "hello.html"
   routing_rules = <<EOF
[{
    "Condition": {
        "KeyPrefixEquals": "docs/"
    },
    "Redirect": {
        "ReplaceKeyPrefixWith": "documents/"
    }
}]
EOF
  }

  tags= {
    Name        = "My bucket"
    Environment = "Dev"
  }
}

Once you create the above file, execute terraform plan and then terraform apply to create S3 bucket in AWS.

4 comments:

  1. Thanks a lot for this article..

    ReplyDelete
  2. I'm in no doubt coming back again to read these articles and blogs.
    user experience design company

    ReplyDelete
  3. Clear explanation, thanks for sharing. I used to create S3 buckets directly in the AWS console, but switching to Terraform gave me version control and repeatability. Do you also recommend managing bucket policies through Terraform files?

    ReplyDelete