|
1 |
| -# AWS Static Website Hosting Project |
2 | 1 |
|
3 |
| -This project provides a Terraform configuration for hosting a static website on AWS. It creates and configures the necessary AWS resources including S3, Route 53 (DNS), IAM, CloudFront, and WAF. |
| 2 | +# Terraform AWS Complete Static Site Module |
| 3 | + |
| 4 | +[](https://www.terraform.io) |
| 5 | +[](https://opensource.org/licenses/MIT) |
| 6 | + |
| 7 | +This Terraform module consist the configuration for hosting a static website on AWS. It creates and configures the necessary AWS resources including S3, Route 53 (DNS), IAM, CloudFront, and WAF. |
4 | 8 |
|
5 | 9 | ## Description
|
6 | 10 |
|
7 |
| -This project sets up an S3 bucket for storing your static website content, a CloudFront distribution for content delivery, a WAF WebACL for protecting your site, and a Route 53 record for DNS. It also creates an IAM user for managing continuous deployment to the s3 bucket. |
| 11 | +This Terraform module sets up an S3 bucket for storing your static website content, a CloudFront distribution for content delivery, OAI for access the bucket through CloudFront(Secure access), a WAF WebACL for protecting your site, and a Route 53 record for DNS. It also creates an IAM user for managing continuous deployment to the s3 bucket. |
| 12 | + |
| 13 | +This module provisions: |
| 14 | + |
| 15 | +- AWS Route53 records |
| 16 | +- AWS ACM certificates |
| 17 | +- AWS CloudFront distributions |
| 18 | +- IAM user |
| 19 | +- S3 bucket |
| 20 | + |
| 21 | + |
| 22 | + |
| 23 | +## Usage |
| 24 | + |
| 25 | +### Example with a custom domain (sub domain) |
| 26 | +```hcl |
| 27 | +module "frontend" { |
| 28 | + source = "github.com/iKnowJavaScript/terraform-aws-complete-static-site" |
| 29 | +
|
| 30 | + name = "example-website" |
| 31 | + environment = "prod" |
| 32 | + create_custom_domain = true |
| 33 | + hosted_zone_domain = "example.com" |
| 34 | + custom_domain_name = "example-website.example.com" |
| 35 | + aws_region = "us-east-1" |
| 36 | + tags = {} |
| 37 | +} |
8 | 38 |
|
9 |
| -## How to Use |
| 39 | +provider "aws" { |
| 40 | + region = "us-east-1" |
| 41 | +} |
| 42 | +``` |
10 | 43 |
|
11 |
| -1. **Clone the Repository**: Clone this repository to your local machine. |
| 44 | +### Example with default CloudFlare domain |
| 45 | +```hcl |
| 46 | +module "frontend" { |
| 47 | + source = "github.com/iKnowJavaScript/terraform-aws-complete-static-site" |
12 | 48 |
|
13 |
| -2. **Install Terraform**: If you haven't already, [install Terraform](https://learn.hashicorp.com/tutorials/terraform/install-cli). |
| 49 | + name = "example-website" |
| 50 | + environment = "prod" |
| 51 | + create_custom_domain = false |
| 52 | + aws_region = "us-east-1" |
| 53 | + tags = {} |
| 54 | +} |
14 | 55 |
|
15 |
| -3. **Configure AWS Credentials**: Ensure your AWS credentials are correctly configured. You can set them in your environment variables or in your AWS credentials file. |
| 56 | +provider "aws" { |
| 57 | + region = "us-east-1" |
| 58 | +} |
| 59 | +``` |
16 | 60 |
|
17 |
| -4. **Update Credential**: Navigate to the project directory, update the `input.auto.tfvars` file to suite your project need and update `terraform.tf` backend object as deem fit or remove if you don't intent to save your states remotely. |
| 61 | +## Inputs |
18 | 62 |
|
19 |
| -5. **Initialize Terraform**: Navigate to the project directory and run `terraform init` to initialize your Terraform workspace. |
| 63 | +| Name | Description | Type | Default | Required | |
| 64 | +|------|-------------|------|---------|:--------:| |
| 65 | +| aws_region | The AWS region to create resources in | `string` | n/a | no | |
| 66 | +| hosted_zone_domain | (OPTIONAL) Hosted zone to add doamin and cloufront Cname to | `string` | n/a | no | |
| 67 | +| custom_domain_name | (OPTIONAL) Custom domain name. should be a sub.domain to the main domain available on the hosted zone or ''(empty string) to use the domain on hosted zone. | `string` | n/a | no | |
| 68 | +| create_custom_domain | Whether to create a custom domain | `bool` | `false` | no | |
| 69 | +| name | The project name | `string` | n/a | yes | |
| 70 | +| environment | The environment the resources is meant for. | `string` | n/a | yes | |
| 71 | +| tags | Resources tags. | `map(string)` | n/a | no | |
20 | 72 |
|
21 |
| -6. **Apply the Configuration**: Run `terraform apply` to create the AWS resources. You'll be prompted to confirm that you want to create the resources. |
22 | 73 |
|
23 |
| -7. **Upload Your Website**: Once the resources are created, you can upload your static website content to the S3 bucket. The bucket name will be output by the `terraform apply` command. |
| 74 | +## Outputs |
24 | 75 |
|
25 |
| -8. **Access Your Website**: After your content is uploaded, you can access your website via the CloudFront distribution URL, which will also be output by the `terraform apply` command. |
| 76 | +| Name | Description | Sensitive | |
| 77 | +|------|-------------|:---------:| |
| 78 | +| cloudflare_domain | Direct cloudflare domain | No | |
| 79 | +| custom_domain | Custom domain name | No | |
| 80 | +| bucket_name | S3 bucket name | No | |
| 81 | +| access_key_id | The access key ID for the S3 user | No | |
| 82 | +| secret_access_key | The secret access key for the S3 user | Yes | |
| 83 | +| domain_certificate_arn | The ARN of the domain certificate | No | |
26 | 84 |
|
| 85 | +*To view sensitive secret, try `terraform output secret_access_key`* |
27 | 86 |
|
28 | 87 | ## License
|
29 | 88 |
|
30 |
| -This project is licensed under the MIT License. See the [LICENSE.md](LICENSE.md) file for details. |
| 89 | +This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details. |
0 commit comments