Skip to content

Commit

Permalink
Add option to redirect all requests (#24)
Browse files Browse the repository at this point in the history
* add redirect_all_requests_to

* dynamic website config

* terraform fmt

* regen readme

* remove unncessary quotes and interpolations

* properly regen README using yaml
  • Loading branch information
sarkis authored and osterman committed Jan 15, 2019
1 parent 769ba9c commit 3bcc297
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ Available targets:
lint Lint terraform code
```

## Inputs

| Name | Description | Type | Default | Required |
Expand Down Expand Up @@ -119,6 +118,7 @@ Available targets:
| parent_zone_id | ID of the hosted zone to contain the record | string | `` | no |
| parent_zone_name | Name of the hosted zone to contain the record | string | `` | no |
| prefix | Prefix identifying one or more objects to which the rule applies | string | `` | no |
| redirect_all_requests_to | A hostname to redirect all website requests for this bucket to. If this is set `index_document` will be ignored. | string | `` | no |
| region | AWS region this bucket should reside in | string | `` | no |
| replication_source_principal_arns | (Optional) List of principal ARNs to grant replication access from different AWS accounts | list | `<list>` | no |
| routing_rules | A json array containing routing rules describing redirect behavior and when redirects are applied | string | `` | no |
Expand Down Expand Up @@ -230,7 +230,7 @@ In general, PRs are welcome. We follow the typical "fork-and-pull" Git workflow.

## Copyright

Copyright © 2017-2018 [Cloud Posse, LLC](https://cpco.io/copyright)
Copyright © 2017-2019 [Cloud Posse, LLC](https://cpco.io/copyright)



Expand Down
2 changes: 1 addition & 1 deletion docs/terraform.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

## Inputs

| Name | Description | Type | Default | Required |
Expand Down Expand Up @@ -27,6 +26,7 @@
| parent_zone_id | ID of the hosted zone to contain the record | string | `` | no |
| parent_zone_name | Name of the hosted zone to contain the record | string | `` | no |
| prefix | Prefix identifying one or more objects to which the rule applies | string | `` | no |
| redirect_all_requests_to | A hostname to redirect all website requests for this bucket to. If this is set `index_document` will be ignored. | string | `` | no |
| region | AWS region this bucket should reside in | string | `` | no |
| replication_source_principal_arns | (Optional) List of principal ARNs to grant replication access from different AWS accounts | list | `<list>` | no |
| routing_rules | A json array containing routing rules describing redirect behavior and when redirects are applied | string | `` | no |
Expand Down
20 changes: 15 additions & 5 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
locals {
website_config = {
redirect_all = [{
redirect_all_requests_to = "${var.redirect_all_requests_to}"
}]

default = [{
index_document = "${var.index_document}"
error_document = "${var.error_document}"
routing_rules = "${var.routing_rules}"
}]
}
}

module "logs" {
source = "git::https://github.com/cloudposse/terraform-aws-s3-log-storage.git?ref=tags/0.2.0"
name = "${var.name}"
Expand Down Expand Up @@ -31,11 +45,7 @@ resource "aws_s3_bucket" "default" {
target_prefix = "${module.logs.prefix}"
}

website {
index_document = "${var.index_document}"
error_document = "${var.error_document}"
routing_rules = "${var.routing_rules}"
}
website = "${local.website_config[var.redirect_all_requests_to == "" ? "default" : "redirect_all"]}"

cors_rule {
allowed_headers = "${var.cors_allowed_headers}"
Expand Down
5 changes: 5 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ variable "index_document" {
description = "Amazon S3 returns this index document when requests are made to the root domain or any of the subfolders"
}

variable "redirect_all_requests_to" {
default = ""
description = "A hostname to redirect all website requests for this bucket to. If this is set `index_document` will be ignored."
}

variable "error_document" {
default = "404.html"
description = "An absolute path to the document to return in case of a 4XX error"
Expand Down

0 comments on commit 3bcc297

Please sign in to comment.