-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added(iac): added terraform directory for creating web app infrastruc…
…ture (#15)
- Loading branch information
Showing
7 changed files
with
137 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
name: Pull Request Terraform Checks | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- 'main' | ||
paths: | ||
- 'terraform/**' | ||
|
||
jobs: | ||
validate: | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
working-directory: ./terraform | ||
steps: | ||
- name: Checkout the source code | ||
uses: actions/checkout@v2 | ||
- name: Setup terraform | ||
uses: hashicorp/setup-terraform@v1 | ||
with: | ||
terraform_version: 1.0.8 | ||
- name: Initialize Terraform modules | ||
run: terraform init | ||
- name: Validate Terraform | ||
run: terraform validate | ||
|
||
format: | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
working-directory: ./terraform | ||
steps: | ||
- name: Checkout the source code | ||
uses: actions/checkout@v2 | ||
- name: Setup terraform | ||
uses: hashicorp/setup-terraform@v1 | ||
with: | ||
terraform_version: 1.0.8 | ||
- name: Initialize Terraform modules | ||
run: terraform init | ||
- name: Check the Terraform format | ||
run: terraform fmt -recursive -check |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
terraform { | ||
# backend "s3" { | ||
# bucket = "" # Replace with the name of the S3 bucket to place remote state | ||
# key = "" # Name of the .tfstate file in the S3 bucket | ||
# region = "us-east-1" | ||
# } | ||
|
||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = "~> 3.0" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
locals { | ||
region = "us-east-1" | ||
env = "test" | ||
app_name = "mywebsite-app" | ||
domain_name = "www.mywebsite.com" | ||
acm_domain = "*.mywebsite.com" # replace with the domain name attached to your ACM certificate | ||
hosted_zone_id = "ABC123" # Replace with Hosted ZOne ID of your domain name | ||
|
||
# Custom error responses for AWS CloudFront | ||
responses = [ | ||
{ | ||
error_code = 404, | ||
response_code = 404, | ||
response_page_path = "/404" | ||
}, | ||
{ | ||
error_code = 403, | ||
response_code = 404, | ||
response_page_path = "/404" | ||
} | ||
] | ||
|
||
s3_apps = { | ||
"mywebsite-app" = { | ||
domain_name = "www.mywebsite.bucket" | ||
s3_config = { | ||
error_document = "index.html" | ||
index_document = "index.html" | ||
force_destroy = true | ||
acl = "private" | ||
} | ||
app_config = null | ||
origin_path = "" | ||
cache_behavior = { | ||
path_pattern = "*" | ||
allowed_methods = ["GET", "HEAD"] | ||
cached_methods = ["GET", "HEAD"] | ||
forwarded_values = { | ||
query_string = false | ||
cookies = "none" | ||
} | ||
lambdas = [] | ||
default_ttl = 3600 | ||
min_ttl = 0 | ||
max_ttl = 86400 | ||
viewer_protocol_policy = "redirect-to-https" | ||
} | ||
} | ||
} | ||
} | ||
|
||
module "aws_cloudfront_app" { | ||
source = "git::https://github.com/SSouik/aws-cloudfront-app.git?ref=v2.1.0" | ||
region = local.region | ||
env = local.env | ||
app_name = local.app_name | ||
domain_name = local.domain_name | ||
cloudfront_responses = local.responses | ||
use_acm_certificate = true | ||
route53_zone_id = local.hosted_zone_id | ||
acm_certificate_domain = local.acm_domain | ||
default_app_name = "mywebsite-app" # Must match the name of your S3 App | ||
s3_app_configs = local.s3_apps | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
provider "aws" { | ||
region = "us-east-1" # replace with your region | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1.0.8 |