|
| 1 | +# Example Website Terraform Module with Custom Sub domain |
| 2 | + |
| 3 | +This Terraform module is utilized for deploying a static website on AWS with a custom subdomain, leveraging resources such as S3, CloudFront, Route 53, WAF, and IAM. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +Using this module, users can easily create a production-ready static website hosted on AWS infrastructure. With features like a secure S3 bucket for website content, CloudFront for optimized delivery, WAF WebACL for site protection, and a custom domain setup through Route 53, the module simplifies the way static websites are deployed and managed. |
| 8 | + |
| 9 | +The configuration also includes an IAM user for facilitating continuous deployment processes directly to the S3 bucket. |
| 10 | + |
| 11 | +### Architecture Diagram |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | +## How to Use This Module |
| 16 | + |
| 17 | +Below is an example of how you can use this module in your Terraform configuration to set up a static website with a custom subdomain. |
| 18 | + |
| 19 | +```hcl |
| 20 | +module "website" { |
| 21 | + source = "../../" |
| 22 | + |
| 23 | + name = "example-website" |
| 24 | + environment = "prod" |
| 25 | + hosted_zone_domain = "example.com" |
| 26 | + custom_domain_name = "example-website.example.com" |
| 27 | + create_custom_domain = true |
| 28 | + aws_region = "us-east-2" |
| 29 | +} |
| 30 | +``` |
| 31 | + |
| 32 | +Make sure to include the `aws` provider block in your configuration: |
| 33 | + |
| 34 | +```hcl |
| 35 | +provider "aws" { |
| 36 | + region = "us-east-2" |
| 37 | +} |
| 38 | +``` |
| 39 | + |
| 40 | +### Inputs for Custom Domain Setup |
| 41 | + |
| 42 | +| Name | Description | Type | Default | Required | |
| 43 | +|---------------------|---------------------------------------------------------------------|------------|---------|:--------:| |
| 44 | +| `name` | The project/site name | `string` | n/a | yes | |
| 45 | +| `environment` | The environment (e.g., staging, prod) | `string` | n/a | yes | |
| 46 | +| `hosted_zone_domain`| Your hosted zone domain in Route 53 | `string` | n/a | yes | |
| 47 | +| `custom_domain_name`| The full custom subdomain to set up | `string` | n/a | yes | |
| 48 | +| `create_custom_domain` | A flag indicating whether to create a custom domain | `bool` | `true` | no | |
| 49 | +| `aws_region` | AWS region where resources will be created | `string` | n/a | yes | |
| 50 | + |
| 51 | +### Outputs |
| 52 | + |
| 53 | +| Name | Description | Sensitive | |
| 54 | +|---------------------------|---------------------------------------------|:---------:| |
| 55 | +| `cloudflare_domain` | The direct CloudFront domain | No | |
| 56 | +| `custom_domain` | The custom domain name | No | |
| 57 | +| `bucket_name` | The name of the S3 bucket | No | |
| 58 | +| `access_key_id` | Access key ID for the S3 user | No | |
| 59 | +| `secret_access_key` | Secret access key for the S3 user | Yes | |
| 60 | +| `domain_certificate_arn` | The ARN of the domain certificate | No | |
| 61 | + |
| 62 | +Sensitive information like the `secret_access_key` can be accessed using the Terraform CLI command `terraform output secret_access_key`. |
| 63 | + |
| 64 | +## License |
| 65 | + |
| 66 | +This code is provided under the MIT License. See the included [LICENSE.md](LICENSE.md) file for more information. |
0 commit comments