Skip to content

Commit 3ccf059

Browse files
Adapt terraform-static-server Project into module (#1)
* chore: add gitignore * feat: upgraded terraform-static-server project to a module * fix: refactor modules to fix use cases * feat: add sample use cases
1 parent 775264a commit 3ccf059

25 files changed

+794
-1
lines changed

.gitignore

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
### Terraform ###
2+
# Local .terraform directories
3+
**/.terraform/*
4+
5+
# .tfstate files
6+
*.tfstate
7+
*.tfstate.*
8+
9+
# Crash log files
10+
crash.log
11+
crash.*.log
12+
13+
# Ignore override files as they are usually used to override resources locally and so
14+
# are not checked in
15+
override.tf
16+
override.tf.json
17+
*_override.tf
18+
*_override.tf.json
19+
20+
# Ignore CLI configuration files
21+
.terraformrc
22+
terraform.rc

.tflint.hcl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
config {
2+
format = "compact"
3+
module = true
4+
}
5+
6+
plugin "aws" {
7+
enabled = true
8+
version = "0.30.0"
9+
source = "github.com/terraform-linters/tflint-ruleset-aws"
10+
}
11+
12+
rule "terraform_comment_syntax" {
13+
enabled = true
14+
}
15+
16+
rule "terraform_naming_convention" {
17+
enabled = true
18+
}
19+
20+
rule "terraform_documented_variables" {
21+
enabled = true
22+
}

CONTRIBUTING.md

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
# Contributing to Forest Terraform
2+
3+
We'd love for you to contribute to our source code and to make the Forest even better than it is today! Here are the guidelines we'd like you to follow:
4+
5+
* [Issues and Bugs](#issue)
6+
* [Feature Requests](#feature)
7+
* [Submission Guidelines](#submit)
8+
* [Further Info](#info)
9+
10+
11+
## <a name="issue"></a> Found an Issue?
12+
13+
If you find a bug in the source code or a mistake in the documentation, you can help us by submitting an issue to our [Github Repository][github]. Even better you can submit a Pull Request with a fix.
14+
15+
**Please see the [Submission Guidelines](#submit) below.**
16+
17+
## <a name="feature"></a> Want a Feature?
18+
19+
You can request a new feature by submitting an issue to our [Github Repository][github]. If you would like to implement a new feature then consider what kind of change it is:
20+
21+
* **Major Changes**
22+
* **Small Changes** can be crafted and submitted to the [Github Repository][github] as a Pull Request.
23+
24+
## <a name="docs"></a> Want a Doc Fix?
25+
26+
If you want to help improve the docs, it's a good idea to let others know what you're working on to minimize duplication of effort. Create a new issue (or comment on a related existing one) to let others know what you're working on.
27+
28+
For large fixes, please build and test the documentation before submitting the MR to be sure you haven't accidentally introduced any layout or formatting issues. You should also make sure that your commit message starts with "docs" and follows the **[Commit Message Guidelines](#commit)** outlined below.
29+
30+
## <a name="submit"></a> Submission Guidelines
31+
32+
### Submitting an Issue
33+
34+
Before you submit your issue search the archive, maybe your question was already answered.
35+
36+
If your issue appears to be a bug, and hasn't been reported, open a new issue. Help us to maximize the effort we can spend fixing issues and adding new features, by not reporting duplicate issues. Providing the following information will increase the chances of your issue being dealt with quickly:
37+
38+
* **Overview of the Issue** - if an error is being thrown a non-minified stack trace helps
39+
* **Motivation for or Use Case** - explain why this is a bug for you
40+
* **Forest Version(s)** - is it a regression?
41+
* **Reproduce the Error** - try to describe how to reproduce the error
42+
* **Related Issues** - has a similar issue been reported before?
43+
* **Suggest a Fix** - if you can't fix the bug yourself, perhaps you can point to what might be
44+
causing the problem (line of code or commit)
45+
46+
**If you get help, help others. Good karma rulez!**
47+
48+
### Submitting a Pull Request
49+
50+
Before you submit your pull request consider the following guidelines:
51+
52+
* Make your changes in a new git branch:
53+
54+
```shell
55+
git checkout -b my-fix-branch main
56+
```
57+
58+
* Create your patch, **including appropriate test cases**.
59+
* Install [Terraform](https://www.terraform.io/). check `required_version` in `versions.tf` for the current development version of the module.
60+
* Installs
61+
* Install [tflint](https://github.com/terraform-linters/tflint). We use tflint to lint the terraform code.
62+
* Initialize the terraform modules:
63+
64+
```shell
65+
terraform init
66+
```
67+
68+
* For updating docs, you have to enable GitHub actions on your forked repository. Simply go to the tab Actions and enable actions.
69+
* Commit your changes using a descriptive commit message:
70+
71+
```shell
72+
git commit -a
73+
```
74+
75+
Note: the optional commit `-a` command line option will automatically "add" and "rm" edited files.
76+
77+
* Push your branch to Github:
78+
79+
```shell
80+
git push origin my-fix-branch
81+
```
82+
83+
In Github, send a pull request to original main branch: f.e. `terraform-aws-complete-static-site:main`.
84+
If we suggest changes, then:
85+
86+
* Make the required updates.
87+
* Re-run the test suite to ensure tests are still passing.
88+
* Commit your changes to your branch (e.g. `my-fix-branch`).
89+
* Push the changes to your Github repository (this will update your Pull Request).
90+
91+
If the PR gets too outdated we may ask you to rebase and force push to update the PR:
92+
93+
```shell
94+
git rebase main -i
95+
git push origin my-fix-branch -f
96+
```
97+
98+
_WARNING: Squashing or reverting commits and force-pushing thereafter may remove Github comments on code that were previously made by you or others in your commits. Avoid any form of rebasing unless necessary.
99+
100+
That's it! Thank you for your contribution!
101+
102+
#### After your merge request is merged
103+
104+
After your pull request is merged, you can safely delete your branch and pull the changes
105+
from the main (upstream) repository:
106+
107+
* Delete the remote branch on Github either through the Github web UI or your local shell as follows:
108+
109+
```shell
110+
git push origin --delete my-fix-branch
111+
```
112+
113+
* Check out the main branch:
114+
115+
```shell
116+
git checkout main -f
117+
```
118+
119+
* Delete the local branch:
120+
121+
```shell
122+
git branch -D my-fix-branch
123+
```
124+
125+
* Update your main with the latest upstream version:
126+
127+
```shell
128+
git pull --ff upstream main
129+
```
130+
131+
## <a name="info"></a> Info
132+
133+
[contribute]: CONTRIBUTING.md
134+
[github]: https://github.com/iKnowJavaScript/terraform-aws-complete-static-site/issues

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Victor Omolayo
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,30 @@
1-
# terraform-aws-complete-static-site
1+
# AWS Static Website Hosting Project
2+
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.
4+
5+
## Description
6+
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.
8+
9+
## How to Use
10+
11+
1. **Clone the Repository**: Clone this repository to your local machine.
12+
13+
2. **Install Terraform**: If you haven't already, [install Terraform](https://learn.hashicorp.com/tutorials/terraform/install-cli).
14+
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.
16+
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.
18+
19+
5. **Initialize Terraform**: Navigate to the project directory and run `terraform init` to initialize your Terraform workspace.
20+
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+
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.
24+
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.
26+
27+
28+
## License
29+
30+
This project is licensed under the MIT License. See the [LICENSE.md](LICENSE.md) file for details.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module "website" {
2+
source = "../../"
3+
4+
name = "example-website"
5+
environment = "prod"
6+
hosted_zone_domain = "example.com"
7+
custom_domain_name = "example-website.example.com"
8+
create_custom_domain = true
9+
aws_region = "us-east-2"
10+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
output "cloudflare_domain" {
2+
description = "Direct cloudflare domain"
3+
value = module.website.cloudflare_domain
4+
}
5+
6+
output "custom_domain" {
7+
description = "Custom domain name"
8+
value = module.website.custom_domain
9+
}
10+
11+
output "bucket_name" {
12+
description = "S3 bucket name"
13+
value = module.website.bucket_name
14+
}
15+
16+
output "access_key_id" {
17+
value = module.website.access_key_id
18+
description = "The access key ID for the S3 user"
19+
}
20+
21+
output "secret_access_key" {
22+
value = module.website.secret_access_key
23+
description = "The secret access key for the S3 user"
24+
sensitive = true
25+
}
26+
27+
# to view sensitive secret, try
28+
# terraform output secret_access_key
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
terraform {
2+
required_version = ">= 1.3"
3+
4+
required_providers {
5+
aws = {
6+
source = "hashicorp/aws"
7+
version = "~> 4.0"
8+
}
9+
}
10+
}
11+
12+
provider "aws" {
13+
region = "us-east-2"
14+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module "website" {
2+
source = "../../"
3+
4+
name = "example-website"
5+
environment = "prod"
6+
create_custom_domain = false
7+
aws_region = "us-east-2"
8+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
output "cloudflare_domain" {
2+
description = "Direct cloudflare domain"
3+
value = module.website.cloudflare_domain
4+
}
5+
6+
output "custom_domain" {
7+
description = "Custom domain name"
8+
value = module.website.custom_domain
9+
}
10+
11+
output "bucket_name" {
12+
description = "S3 bucket name"
13+
value = module.website.bucket_name
14+
}
15+
16+
output "access_key_id" {
17+
value = module.website.access_key_id
18+
description = "The access key ID for the S3 user"
19+
}
20+
21+
output "secret_access_key" {
22+
value = module.website.secret_access_key
23+
description = "The secret access key for the S3 user"
24+
sensitive = true
25+
}
26+
27+
# to view sensitive secret, try
28+
# terraform output secret_access_key

0 commit comments

Comments
 (0)