Skip to content

Commit

Permalink
feat: amplify custom headers configuration (#46)
Browse files Browse the repository at this point in the history
* feat: amplify custom headers configuration

* additional readme exampel
  • Loading branch information
oycyc authored Jan 21, 2025
1 parent 4590c56 commit 2472cef
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 25 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
-->

Terraform module to provision AWS Amplify apps, backend environments, branches, domain associations, and webhooks.
Terraform module to provision AWS Amplify apps, backend environments, branches, domain associations, and webhooks.


> [!TIP]
Expand Down Expand Up @@ -121,6 +121,14 @@ module "amplify_app" {
}
]
custom_headers = <<-EOT
customHeaders:
- pattern: '**'
headers:
- key: 'Strict-Transport-Security'
value: 'max-age=31536000; includeSubDomains'
EOT
environment_variables = {
ENV = "test"
}
Expand Down Expand Up @@ -241,6 +249,7 @@ Available targets:
| <a name="input_basic_auth_credentials"></a> [basic\_auth\_credentials](#input\_basic\_auth\_credentials) | The credentials for basic authorization for the Amplify app | `string` | `null` | no |
| <a name="input_build_spec"></a> [build\_spec](#input\_build\_spec) | The [build specification](https://docs.aws.amazon.com/amplify/latest/userguide/build-settings.html) (build spec) for the Amplify app.<br/>If not provided then it will use the `amplify.yml` at the root of your project / branch. | `string` | `null` | no |
| <a name="input_context"></a> [context](#input\_context) | Single object for setting entire context at once.<br/>See description of individual variables for details.<br/>Leave string and numeric variables as `null` to use default value.<br/>Individual variable settings (non-null) override settings in context object,<br/>except for attributes, tags, and additional\_tag\_map, which are merged. | `any` | <pre>{<br/> "additional_tag_map": {},<br/> "attributes": [],<br/> "delimiter": null,<br/> "descriptor_formats": {},<br/> "enabled": true,<br/> "environment": null,<br/> "id_length_limit": null,<br/> "label_key_case": null,<br/> "label_order": [],<br/> "label_value_case": null,<br/> "labels_as_tags": [<br/> "unset"<br/> ],<br/> "name": null,<br/> "namespace": null,<br/> "regex_replace_chars": null,<br/> "stage": null,<br/> "tags": {},<br/> "tenant": null<br/>}</pre> | no |
| <a name="input_custom_headers"></a> [custom\_headers](#input\_custom\_headers) | The custom headers for the Amplify app, allows specifying headers for every HTTP response. Must adhere to AWS's format: https://docs.aws.amazon.com/amplify/latest/userguide/custom-headers.html | `string` | `""` | no |
| <a name="input_custom_rules"></a> [custom\_rules](#input\_custom\_rules) | The custom rules to apply to the Amplify App | <pre>list(object({<br/> condition = optional(string)<br/> source = string<br/> status = optional(string)<br/> target = string<br/> }))</pre> | `[]` | no |
| <a name="input_delimiter"></a> [delimiter](#input\_delimiter) | Delimiter to be used between ID elements.<br/>Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no |
| <a name="input_description"></a> [description](#input\_description) | The description for the Amplify app | `string` | `null` | no |
Expand Down
49 changes: 25 additions & 24 deletions docs/terraform.md

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions examples/complete/fixtures.us-east-2.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ custom_rules = [
}
]

# Custom header, HTST to always block HTTP and always redirect to HTTPS
custom_headers = <<-EOT
customHeaders:
- pattern: '**'
headers:
- key: 'Strict-Transport-Security'
value: 'max-age=31536000; includeSubDomains'
EOT

environment_variables = {
ENV = "test"
}
Expand Down
1 change: 1 addition & 0 deletions examples/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module "amplify_app" {
enable_branch_auto_deletion = var.enable_branch_auto_deletion
environment_variables = var.environment_variables
custom_rules = var.custom_rules
custom_headers = var.custom_headers
iam_service_role_enabled = var.iam_service_role_enabled
iam_service_role_arn = var.iam_service_role_arn
iam_service_role_actions = var.iam_service_role_actions
Expand Down
6 changes: 6 additions & 0 deletions examples/complete/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ variable "environment_variables" {
default = {}
}

variable "custom_headers" {
type = string
description = "The custom headers for the Amplify app, allows specifying headers for every HTTP response. Must adhere to AWS's format: https://docs.aws.amazon.com/amplify/latest/userguide/custom-headers.html"
default = ""
}

variable "iam_service_role_arn" {
type = list(string)
description = <<-EOT
Expand Down
1 change: 1 addition & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ resource "aws_amplify_app" "default" {
enable_basic_auth = var.enable_basic_auth
enable_branch_auto_build = var.enable_branch_auto_build
environment_variables = var.environment_variables
custom_headers = var.custom_headers

iam_service_role_arn = local.iam_service_role_arn

Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ variable "iam_service_role_actions" {
nullable = false
}

variable "custom_headers" {
type = string
description = "The custom headers for the Amplify app, allows specifying headers for every HTTP response. Must adhere to AWS's format: https://docs.aws.amazon.com/amplify/latest/userguide/custom-headers.html"
default = ""
}

variable "custom_rules" {
type = list(object({
condition = optional(string)
Expand Down

0 comments on commit 2472cef

Please sign in to comment.