diff --git a/README.md b/README.md index e3dde5c..5d650ce 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,8 @@ # Terraform AWS Complete Static Site Module -[![Terraform](https://img.shields.io/badge/Terraform-0.12.0-623CE4)](https://www.terraform.io) +[![Terraform registry](https://img.shields.io/badge/Terraform_Registry-0.0.2-blue)](https://registry.terraform.io/modules/iKnowJavaScript/complete-static-site/aws/latest) +[![Terraform](https://img.shields.io/badge/Terraform-0.0.2-623CE4)](https://www.terraform.io) [![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT) 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. @@ -18,6 +19,7 @@ This module provisions: - IAM user - S3 bucket +### Architecture Diagram ![image](assets/diagram.png) ## Usage @@ -25,7 +27,7 @@ This module provisions: ### Example with a custom domain (sub domain) ```hcl module "frontend" { - source = "github.com/iKnowJavaScript/terraform-aws-complete-static-site" + source = "iKnowJavaScript/complete-static-site/aws" name = "example-website" environment = "prod" @@ -44,7 +46,7 @@ provider "aws" { ### Example with default CloudFlare domain ```hcl module "frontend" { - source = "github.com/iKnowJavaScript/terraform-aws-complete-static-site" + source = "iKnowJavaScript/complete-static-site/aws" name = "example-website" environment = "prod" diff --git a/examples/with-custom-subdomain/README.md b/examples/with-custom-subdomain/README.md new file mode 100644 index 0000000..f635653 --- /dev/null +++ b/examples/with-custom-subdomain/README.md @@ -0,0 +1,66 @@ +# Example Website Terraform Module with Custom Sub domain + +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. + +## Overview + +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. + +The configuration also includes an IAM user for facilitating continuous deployment processes directly to the S3 bucket. + +### Architecture Diagram + +![](../../assets/diagram.png) + +## How to Use This Module + +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. + +```hcl +module "website" { + source = "../../" + + name = "example-website" + environment = "prod" + hosted_zone_domain = "example.com" + custom_domain_name = "example-website.example.com" + create_custom_domain = true + aws_region = "us-east-2" +} +``` + +Make sure to include the `aws` provider block in your configuration: + +```hcl +provider "aws" { + region = "us-east-2" +} +``` + +### Inputs for Custom Domain Setup + +| Name | Description | Type | Default | Required | +|---------------------|---------------------------------------------------------------------|------------|---------|:--------:| +| `name` | The project/site name | `string` | n/a | yes | +| `environment` | The environment (e.g., staging, prod) | `string` | n/a | yes | +| `hosted_zone_domain`| Your hosted zone domain in Route 53 | `string` | n/a | yes | +| `custom_domain_name`| The full custom subdomain to set up | `string` | n/a | yes | +| `create_custom_domain` | A flag indicating whether to create a custom domain | `bool` | `true` | no | +| `aws_region` | AWS region where resources will be created | `string` | n/a | yes | + +### Outputs + +| Name | Description | Sensitive | +|---------------------------|---------------------------------------------|:---------:| +| `cloudflare_domain` | The direct CloudFront domain | No | +| `custom_domain` | The custom domain name | No | +| `bucket_name` | The name of the S3 bucket | No | +| `access_key_id` | Access key ID for the S3 user | No | +| `secret_access_key` | Secret access key for the S3 user | Yes | +| `domain_certificate_arn` | The ARN of the domain certificate | No | + +Sensitive information like the `secret_access_key` can be accessed using the Terraform CLI command `terraform output secret_access_key`. + +## License + +This code is provided under the MIT License. See the included [LICENSE.md](LICENSE.md) file for more information. \ No newline at end of file diff --git a/examples/without-custom-domain/README.md b/examples/without-custom-domain/README.md new file mode 100644 index 0000000..69909fd --- /dev/null +++ b/examples/without-custom-domain/README.md @@ -0,0 +1,55 @@ +# Example Website Terraform Module without Custom Domain + +Deploy your static website on AWS without the need for a custom domain using this Terraform module. It provisions essential resources such as an S3 bucket, CloudFront distribution, and IAM user for secure and efficient hosting. + +## Overview + +This module sets up a static website hosting environment optimized for production use. By creating a secure S3 bucket to host your content, setting up a CloudFront distribution for fast global access, and establishing IAM security for continuous deployment processes, the module offers a straightforward approach to deploying static websites on AWS. + +### Architecture Diagram + +![](../../assets/diagram.png) + +## How to Use This Module + +To deploy your static website without a custom domain, you can use the module in your Terraform configuration like so: + +```hcl +module "website" { + source = "../../" + + name = "example-website" + environment = "prod" + create_custom_domain = false + aws_region = "us-east-2" +} + +provider "aws" { + region = "us-east-2" +} +``` + +### Inputs for Default Domain Setup + +| Name | Description | Type | Default | Required | +|-------------------------|--------------------------------------------------------|----------|---------|:--------:| +| `name` | The project/site name | `string` | n/a | yes | +| `environment` | The environment (e.g., staging, prod) | `string` | n/a | yes | +| `create_custom_domain` | A flag indicating whether to create a custom domain | `bool` | `false` | no | +| `aws_region` | AWS region where resources will be created | `string` | n/a | yes | + +### Outputs + +| Name | Description | Sensitive | +|---------------------------|------------------------------------------|:---------:| +| `cloudflare_domain` | The direct CloudFront domain | No | +| `bucket_name` | The name of the S3 bucket | No | +| `access_key_id` | Access key ID for the S3 user | No | +| `secret_access_key` | Secret access key for the S3 user | Yes | +| `domain_certificate_arn` | The ARN of the default domain certificate| No | + +To retrieve sensitive outputs like the `secret_access_key`, use the `terraform output` command with caution, for example: `terraform output secret_access_key`. + +## License + +This code is provided under the MIT License. Full licensing details are available in the included [LICENSE.md](LICENSE.md) file. \ No newline at end of file