diff --git a/.github/workflows/semantic-check.yml b/.github/workflows/semantic-check.yml new file mode 100644 index 0000000..07002a4 --- /dev/null +++ b/.github/workflows/semantic-check.yml @@ -0,0 +1,24 @@ +name: "Semantic Check" +on: + pull_request_target: + types: + - opened + - edited + - synchronize +permissions: + contents: read + pull-requests: read +jobs: + main: + name: Semantic Commit Message Check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # ratchet:actions/checkout@v4 + - uses: amannn/action-semantic-pull-request@cfb60706e18bc85e8aec535e3c577abe8f70378e # ratchet:amannn/action-semantic-pull-request@v5 + name: Check PR for Semantic Commit Message + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + requireScope: false + validateSingleCommit: true + ignoreLabels: release merge \ No newline at end of file diff --git a/README.md b/README.md index 96bf3a6..e3dde5c 100644 --- a/README.md +++ b/README.md @@ -1,30 +1,89 @@ -# AWS Static Website Hosting Project -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. +# Terraform AWS Complete Static Site Module + +[](https://www.terraform.io) +[](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. ## Description -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. +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. + +This module provisions: + +- AWS Route53 records +- AWS ACM certificates +- AWS CloudFront distributions +- IAM user +- S3 bucket + + + +## Usage + +### Example with a custom domain (sub domain) +```hcl +module "frontend" { + source = "github.com/iKnowJavaScript/terraform-aws-complete-static-site" + + name = "example-website" + environment = "prod" + create_custom_domain = true + hosted_zone_domain = "example.com" + custom_domain_name = "example-website.example.com" + aws_region = "us-east-1" + tags = {} +} -## How to Use +provider "aws" { + region = "us-east-1" +} +``` -1. **Clone the Repository**: Clone this repository to your local machine. +### Example with default CloudFlare domain +```hcl +module "frontend" { + source = "github.com/iKnowJavaScript/terraform-aws-complete-static-site" -2. **Install Terraform**: If you haven't already, [install Terraform](https://learn.hashicorp.com/tutorials/terraform/install-cli). + name = "example-website" + environment = "prod" + create_custom_domain = false + aws_region = "us-east-1" + tags = {} +} -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. +provider "aws" { + region = "us-east-1" +} +``` -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. +## Inputs -5. **Initialize Terraform**: Navigate to the project directory and run `terraform init` to initialize your Terraform workspace. +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| aws_region | The AWS region to create resources in | `string` | n/a | no | +| hosted_zone_domain | (OPTIONAL) Hosted zone to add doamin and cloufront Cname to | `string` | n/a | no | +| 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 | +| create_custom_domain | Whether to create a custom domain | `bool` | `false` | no | +| name | The project name | `string` | n/a | yes | +| environment | The environment the resources is meant for. | `string` | n/a | yes | +| tags | Resources tags. | `map(string)` | n/a | no | -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. -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. +## Outputs -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. +| Name | Description | Sensitive | +|------|-------------|:---------:| +| cloudflare_domain | Direct cloudflare domain | No | +| custom_domain | Custom domain name | No | +| bucket_name | S3 bucket name | No | +| access_key_id | The access key ID for the S3 user | No | +| secret_access_key | The secret access key for the S3 user | Yes | +| domain_certificate_arn | The ARN of the domain certificate | No | +*To view sensitive secret, try `terraform output secret_access_key`* ## License -This project is licensed under the MIT License. See the [LICENSE.md](LICENSE.md) file for details. \ No newline at end of file +This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details. diff --git a/assets/diagram.png b/assets/diagram.png new file mode 100644 index 0000000..79b3e88 Binary files /dev/null and b/assets/diagram.png differ diff --git a/output.tf b/output.tf index 73babfd..7190e4c 100644 --- a/output.tf +++ b/output.tf @@ -24,5 +24,10 @@ output "secret_access_key" { sensitive = true } +output "domain_certificate_arn" { + value = var.create_custom_domain ? module.dns[0].certificate_arn : null + description = "The ARN of the domain certificate" +} + # to view sensitive secret, try # terraform output secret_access_key diff --git a/variables.tf b/variables.tf index 1ec9cca..3b03d99 100644 --- a/variables.tf +++ b/variables.tf @@ -18,7 +18,7 @@ variable "aws_region" { variable "create_custom_domain" { type = bool - description = "(OPTIONAL) Whether to use a custom domain or not" + description = "(OPTIONAL) Whether to use a custom domain or not." default = false }
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: