Skip to content

Commit 6a10828

Browse files
committed
initial import of working version
1 parent e2f312c commit 6a10828

File tree

8 files changed

+129
-66
lines changed

8 files changed

+129
-66
lines changed

README.md

+44-63
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,65 @@
1-
> START INSTRUCTION FOR TECHNATIVE ENGINEERS
1+
# terraform-aws-route53-s3-http-redirect ![](https://img.shields.io/github/workflow/status/TechNative-B-V/terraform-aws-route53-s3-http-redirect/Lint?style=plastic)
22

3-
# terraform-aws-module-template
3+
Implements creates a simple http url forwarding redirect using a route 53 alias
4+
records and a s3 bucket.
45

5-
Template for creating a new TerraForm AWS Module. For TechNative Engineers.
6+
This is the most simple method to create a HTTP redirect within AWS.
67

7-
## Instructions
8-
9-
### Your Module Name
10-
11-
Think hard and come up with the shortest descriptive name for your module.
12-
Look at competition in the [terraform
13-
registry](https://registry.terraform.io/).
14-
15-
Your module name should be max. three words seperated by dashes. E.g.
16-
17-
- html-form-action
18-
- new-account-notifier
19-
- budget-alarms
20-
- fix-missing-tags
21-
22-
### Setup Github Project
23-
24-
1. Click the template button on the top right...
25-
2. Name github project `terraform-aws-[your-module-name]`
26-
3. Make project private untill ready for publication
27-
2. Install `pre-commit`
28-
29-
### Develop your module
30-
31-
1. Develop your module
32-
2. Try to use the [best practices for TerraForm
33-
development](https://www.terraform-best-practices.com/) and [TerraForm AWS
34-
Development](https://github.com/ozbillwang/terraform-best-practices).
35-
36-
## Finish project documentation
8+
[![](we-are-technative.png)](https://www.technative.nl)
379

38-
1. Set well written title
39-
2. Add one or more shields
40-
3. Start readme with a short and complete as possible module description. This
41-
is the part where you sell your module.
42-
4. Complete README with well written documentation. Try to think as a someone
43-
with three months of Terraform experience.
44-
5. Check if pre-commit correctly generates the standard Terraform documentation.
10+
## How does it work
4511

46-
## Publish module
12+
This module creates a S3 bucket and a Route 53 A record.
4713

48-
If your module is in a state that it could be useful for others and ready for
49-
publication, you can publish a first version.
14+
The S3 bucket is empty and has a website configuration which redirects all
15+
traffic to the target url.
5016

51-
1. Create a [Github
52-
Release](https://docs.github.com/en/repositories/releasing-projects-on-github/about-releases)
53-
2. Publish in the TerraForm Registry under the Technative Namespace (the GitHub
54-
Repo must be in the TechNative Organization)
17+
The Route 53 A record will alias to the S3 endpoint.
5518

56-
---
19+
## Usage
5720

58-
> END INSTRUCTION FOR TECHNATIVE ENGINEERS
21+
```
22+
module "redirect_technative_nl_techdd" {
23+
source = "Technative-B-V/terraform-aws-route53-s3-http-redirect/aws"
24+
version = "0.1.0"
5925
26+
zone_name = "example.com" # THIS ZONE SHOULD EXIST IN ROUTE53
27+
domain_name = "sample-google-form.example.com"
28+
redirect_target_url = "https://docs.google.com/forms/d/e/1FAIpQLSeI8_vYyaJgM7SJM4Y9AWfLq-tglWZh6yt7bEXEOJr_L-hV1A/viewform?formkey=dGx0b1ZrTnoyZDgtYXItMWVBdVlQQWc6MQ"
29+
}
30+
```
6031

61-
# Terraform AWS [Module Name] ![](https://img.shields.io/github/workflow/status/TechNative-B-V/terraform-aws-module-name/Lint?style=plastic)
32+
<!-- BEGIN_TF_DOCS -->
33+
## Providers
6234

63-
<!-- SHIELDS -->
35+
| Name | Version |
36+
|------|---------|
37+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.0.0 |
6438

65-
This module implements ...
39+
## Modules
6640

67-
[![](we-are-technative.png)](https://www.technative.nl)
41+
| Name | Source | Version |
42+
|------|--------|---------|
43+
| <a name="module_route53_http_redirect_target_url"></a> [route53\_http\_redirect\_target\_url](#module\_route53\_http\_redirect\_target\_url) | TechNative-B-V/url-parser/null | 0.1.1 |
6844

69-
## How does it work
45+
## Resources
7046

71-
...
47+
| Name | Type |
48+
|------|------|
49+
| [aws_route53_record.domains](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_record) | resource |
50+
| [aws_s3_bucket.route53_http_redirect_bucket](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket) | resource |
51+
| [aws_s3_bucket_website_configuration.route53_http_redirect_webconf](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_website_configuration) | resource |
52+
| [aws_route53_zone.route53_http_redirect_zone](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/route53_zone) | data source |
7253

73-
## Usage
54+
## Inputs
7455

75-
To use this module ...
56+
| Name | Description | Type | Default | Required |
57+
|------|-------------|------|---------|:--------:|
58+
| <a name="input_domain_name"></a> [domain\_name](#input\_domain\_name) | Domain to provide the redirect including subdomain if applicable | `string` | n/a | yes |
59+
| <a name="input_redirect_target_url"></a> [redirect\_target\_url](#input\_redirect\_target\_url) | Redirect target - should be a full URL. If http:// or https:// is excluded, the scheme of the request will be used | `string` | n/a | yes |
60+
| <a name="input_zone_name"></a> [zone\_name](#input\_zone\_name) | Domain name of the Route53 hosted zone | `string` | n/a | yes |
7661

77-
```json
78-
{
79-
"some_conf": "might need explanation"
80-
}
81-
```
62+
## Outputs
8263

83-
<!-- BEGIN_TF_DOCS -->
64+
No outputs.
8465
<!-- END_TF_DOCS -->

examples/README.md

-1
This file was deleted.

examples/complete/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Example route53 s3 http redirect - Redirect to Google Forms
2+
3+
This example demonstrates how to create a redirect to a Google Form.

examples/complete/main.tf

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module "redirect_technative_nl_techdd" {
2+
source = "Technative-B-V/terraform-aws-route53-s3-http-redirect/aws"
3+
version = "0.1.0"
4+
5+
zone_name = "example.com" # THIS ZONE SHOULD EXIST IN ROUTE53
6+
domain_name = "sample-google-form.example.com"
7+
redirect_target_url = "https://docs.google.com/forms/d/e/1FAIpQLSeI8_vYyaJgM7SJM4Y9AWfLq-tglWZh6yt7bEXEOJr_L-hV1A/viewform?formkey=dGx0b1ZrTnoyZDgtYXItMWVBdVlQQWc6MQ"
8+
}
9+

main.tf

+47-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,47 @@
1-
# YOU MAIN CODE HERE
1+
data "aws_route53_zone" "route53_http_redirect_zone" {
2+
name = var.zone_name
3+
}
4+
5+
resource "aws_s3_bucket" "route53_http_redirect_bucket" {
6+
bucket = var.domain_name
7+
force_destroy = "true"
8+
}
9+
10+
module "route53_http_redirect_target_url" {
11+
source = "TechNative-B-V/url-parser/null"
12+
version = "0.1.1"
13+
14+
url = var.redirect_target_url
15+
}
16+
17+
resource "aws_s3_bucket_website_configuration" "route53_http_redirect_webconf" {
18+
bucket = aws_s3_bucket.route53_http_redirect_bucket.bucket
19+
20+
index_document {
21+
suffix = "index.html"
22+
}
23+
24+
routing_rules = <<EOF
25+
[{
26+
"Redirect": {
27+
"Hostname": "${module.route53_http_redirect_target_url.hostname}",
28+
"Protocol": "${module.route53_http_redirect_target_url.protocol}",
29+
"ReplaceKeyWith": "${module.route53_http_redirect_target_url.path_and_param}"
30+
}
31+
}]
32+
EOF
33+
}
34+
35+
resource "aws_route53_record" "domains" {
36+
zone_id = data.aws_route53_zone.route53_http_redirect_zone.zone_id
37+
name = var.domain_name
38+
type = "A"
39+
40+
alias {
41+
name = "s3-website.${aws_s3_bucket.route53_http_redirect_bucket.region}.amazonaws.com"
42+
zone_id = aws_s3_bucket.route53_http_redirect_bucket.hosted_zone_id
43+
evaluate_target_health = true
44+
}
45+
}
46+
47+

outputs.tf

Whitespace-only changes.

variables.tf

+15-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,15 @@
1-
# VARIABLES
1+
variable "zone_name" {
2+
description = "Domain name of the Route53 hosted zone"
3+
type = string
4+
}
5+
6+
variable "domain_name" {
7+
description = "Domain to provide the redirect including subdomain if applicable"
8+
type = string
9+
}
10+
11+
variable "redirect_target_url" {
12+
description = "Redirect target - should be a full URL. If http:// or https:// is excluded, the scheme of the request will be used"
13+
type = string
14+
}
15+

versions.tf

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
terraform {
3+
required_version = ">= 1.0.0"
4+
5+
required_providers {
6+
aws = {
7+
source = "hashicorp/aws"
8+
version = ">= 4.0.0"
9+
}
10+
}
11+
}

0 commit comments

Comments
 (0)