├── .gitignore ├── LICENSE ├── README.md ├── main.tf ├── outputs.tf └── variables.tf /.gitignore: -------------------------------------------------------------------------------- 1 | # Local .terraform directories 2 | **/.terraform/* 3 | 4 | # .tfstate files 5 | *.tfstate 6 | *.tfstate.* 7 | 8 | # Crash log files 9 | crash.log 10 | 11 | # Ignore any .tfvars files that are generated automatically for each Terraform run. Most 12 | # .tfvars files are managed as part of configuration and so should be included in 13 | # version control. 14 | # 15 | # example.tfvars 16 | 17 | # Ignore override files as they are usually used to override resources locally and so 18 | # are not checked in 19 | override.tf 20 | override.tf.json 21 | *_override.tf 22 | *_override.tf.json 23 | 24 | # Include override files you do wish to add to version control using negated pattern 25 | # 26 | # !example_override.tf 27 | 28 | # Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan 29 | # example: *tfplan* 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Licensed under the Apache License, Version 2.0 (the "License"); 2 | you may not use this file except in compliance with the License. 3 | You may obtain a copy of the License at 4 | 5 | http://www.apache.org/licenses/LICENSE-2.0 6 | 7 | Unless required by applicable law or agreed to in writing, software 8 | distributed under the License is distributed on an "AS IS" BASIS, 9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | See the License for the specific language governing permissions and 11 | limitations under the License. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Terraform Module for Private Registry - AWS S3 Static website 2 | - This module provisions AWS S3 buckets configured for static website hosting. 3 | - This will be a demo S3 module 4 | 5 | -------------------------------------------------------------------------------- /main.tf: -------------------------------------------------------------------------------- 1 | # S3 static website bucket 2 | 3 | # Resource-1: aws_s3_bucket 4 | resource "aws_s3_bucket" "mywebsite" { 5 | bucket = var.bucket_name 6 | tags = var.tags 7 | force_destroy = true 8 | } 9 | 10 | # Resource-2: aws_s3_bucket_website_configuration 11 | resource "aws_s3_bucket_website_configuration" "mywebsite" { 12 | bucket = aws_s3_bucket.mywebsite.id 13 | index_document { 14 | suffix = "index.html" 15 | } 16 | error_document { 17 | key = "error.html" 18 | } 19 | } 20 | 21 | # Resource-3: aws_s3_bucket_versioning 22 | resource "aws_s3_bucket_versioning" "mywebsite" { 23 | bucket = aws_s3_bucket.mywebsite.id 24 | versioning_configuration { 25 | status = "Enabled" 26 | } 27 | } 28 | 29 | # Resource-4: aws_s3_bucket_ownership_controls 30 | resource "aws_s3_bucket_ownership_controls" "mywebsite" { 31 | bucket = aws_s3_bucket.mywebsite.id 32 | rule { 33 | object_ownership = "BucketOwnerPreferred" 34 | } 35 | } 36 | 37 | # Resource-5: aws_s3_bucket_public_access_block 38 | resource "aws_s3_bucket_public_access_block" "mywebsite" { 39 | bucket = aws_s3_bucket.mywebsite.id 40 | block_public_acls = false 41 | block_public_policy = false 42 | ignore_public_acls = false 43 | restrict_public_buckets = false 44 | } 45 | 46 | # Resource-6: aws_s3_bucket_acl 47 | resource "aws_s3_bucket_acl" "mywebsite" { 48 | depends_on = [ 49 | aws_s3_bucket_ownership_controls.mywebsite, 50 | aws_s3_bucket_public_access_block.mywebsite 51 | ] 52 | bucket = aws_s3_bucket.mywebsite.id 53 | acl = "public-read" 54 | } 55 | 56 | 57 | # Resource-7: aws_s3_bucket_policy 58 | resource "aws_s3_bucket_policy" "mywebsite" { 59 | bucket = aws_s3_bucket.mywebsite.id 60 | 61 | policy = <