Skip to content

Commit 601df49

Browse files
authored
feat: Added support for Staging Distribution (#130)
1 parent ed0f1f9 commit 601df49

File tree

5 files changed

+51
-27
lines changed

5 files changed

+51
-27
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ No modules.
134134
|------|-------------|------|---------|:--------:|
135135
| <a name="input_aliases"></a> [aliases](#input\_aliases) | Extra CNAMEs (alternate domain names), if any, for this distribution. | `list(string)` | `null` | no |
136136
| <a name="input_comment"></a> [comment](#input\_comment) | Any comments you want to include about the distribution. | `string` | `null` | no |
137+
| <a name="input_continuous_deployment_policy_id"></a> [continuous\_deployment\_policy\_id](#input\_continuous\_deployment\_policy\_id) | Identifier of a continuous deployment policy. This argument should only be set on a production distribution. | `string` | `null` | no |
137138
| <a name="input_create_distribution"></a> [create\_distribution](#input\_create\_distribution) | Controls if CloudFront distribution should be created | `bool` | `true` | no |
138139
| <a name="input_create_monitoring_subscription"></a> [create\_monitoring\_subscription](#input\_create\_monitoring\_subscription) | If enabled, the resource for monitoring subscription will created. | `bool` | `false` | no |
139140
| <a name="input_create_origin_access_control"></a> [create\_origin\_access\_control](#input\_create\_origin\_access\_control) | Controls if CloudFront origin access control should be created | `bool` | `false` | no |
@@ -154,6 +155,7 @@ No modules.
154155
| <a name="input_price_class"></a> [price\_class](#input\_price\_class) | The price class for this distribution. One of PriceClass\_All, PriceClass\_200, PriceClass\_100 | `string` | `null` | no |
155156
| <a name="input_realtime_metrics_subscription_status"></a> [realtime\_metrics\_subscription\_status](#input\_realtime\_metrics\_subscription\_status) | A flag that indicates whether additional CloudWatch metrics are enabled for a given CloudFront distribution. Valid values are `Enabled` and `Disabled`. | `string` | `"Enabled"` | no |
156157
| <a name="input_retain_on_delete"></a> [retain\_on\_delete](#input\_retain\_on\_delete) | Disables the distribution instead of deleting it when destroying the resource through Terraform. If this is set, the distribution needs to be deleted manually afterwards. | `bool` | `false` | no |
158+
| <a name="input_staging"></a> [staging](#input\_staging) | Whether the distribution is a staging distribution. | `bool` | `false` | no |
157159
| <a name="input_tags"></a> [tags](#input\_tags) | A map of tags to assign to the resource. | `map(string)` | `null` | no |
158160
| <a name="input_viewer_certificate"></a> [viewer\_certificate](#input\_viewer\_certificate) | The SSL configuration for this distribution | `any` | <pre>{<br> "cloudfront_default_certificate": true,<br> "minimum_protocol_version": "TLSv1"<br>}</pre> | no |
159161
| <a name="input_wait_for_deployment"></a> [wait\_for\_deployment](#input\_wait\_for\_deployment) | If enabled, the resource will wait for the distribution status to change from InProgress to Deployed. Setting this to false will skip the process. | `bool` | `true` | no |

examples/complete/main.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,18 @@ module "cloudfront" {
2222

2323
comment = "My awesome CloudFront"
2424
enabled = true
25+
staging = false # If you want to create a staging distribution, set this to true
2526
http_version = "http2and3"
2627
is_ipv6_enabled = true
2728
price_class = "PriceClass_All"
2829
retain_on_delete = false
2930
wait_for_deployment = false
3031

32+
# If you want to create a primary distribution with a continuous deployment policy, set this to the ID of the policy.
33+
# This argument should only be set on a production distribution.
34+
# ref. `aws_cloudfront_continuous_deployment_policy` resource: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudfront_continuous_deployment_policy
35+
continuous_deployment_policy_id = null
36+
3137
# When you enable additional metrics for a distribution, CloudFront sends up to 8 metrics to CloudWatch in the US East (N. Virginia) Region.
3238
# This rate is charged only once per month, per metric (up to 8 metrics per distribution).
3339
create_monitoring_subscription = true

main.tf

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,19 @@ resource "aws_cloudfront_origin_access_control" "this" {
2727
resource "aws_cloudfront_distribution" "this" {
2828
count = var.create_distribution ? 1 : 0
2929

30-
aliases = var.aliases
31-
comment = var.comment
32-
default_root_object = var.default_root_object
33-
enabled = var.enabled
34-
http_version = var.http_version
35-
is_ipv6_enabled = var.is_ipv6_enabled
36-
price_class = var.price_class
37-
retain_on_delete = var.retain_on_delete
38-
wait_for_deployment = var.wait_for_deployment
39-
web_acl_id = var.web_acl_id
40-
tags = var.tags
30+
aliases = var.aliases
31+
comment = var.comment
32+
continuous_deployment_policy_id = var.continuous_deployment_policy_id
33+
default_root_object = var.default_root_object
34+
enabled = var.enabled
35+
http_version = var.http_version
36+
is_ipv6_enabled = var.is_ipv6_enabled
37+
price_class = var.price_class
38+
retain_on_delete = var.retain_on_delete
39+
staging = var.staging
40+
wait_for_deployment = var.wait_for_deployment
41+
web_acl_id = var.web_acl_id
42+
tags = var.tags
4143

4244
dynamic "logging_config" {
4345
for_each = length(keys(var.logging_config)) == 0 ? [] : [var.logging_config]

variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ variable "comment" {
5353
default = null
5454
}
5555

56+
variable "continuous_deployment_policy_id" {
57+
description = "Identifier of a continuous deployment policy. This argument should only be set on a production distribution."
58+
type = string
59+
default = null
60+
}
61+
5662
variable "default_root_object" {
5763
description = "The object that you want CloudFront to return (for example, index.html) when an end user requests the root URL."
5864
type = string
@@ -101,6 +107,12 @@ variable "web_acl_id" {
101107
default = null
102108
}
103109

110+
variable "staging" {
111+
description = "Whether the distribution is a staging distribution."
112+
type = bool
113+
default = false
114+
}
115+
104116
variable "tags" {
105117
description = "A map of tags to assign to the resource."
106118
type = map(string)

wrappers/main.tf

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,23 @@ module "wrapper" {
33

44
for_each = var.items
55

6-
aliases = try(each.value.aliases, var.defaults.aliases, null)
7-
comment = try(each.value.comment, var.defaults.comment, null)
8-
create_distribution = try(each.value.create_distribution, var.defaults.create_distribution, true)
9-
create_monitoring_subscription = try(each.value.create_monitoring_subscription, var.defaults.create_monitoring_subscription, false)
10-
create_origin_access_control = try(each.value.create_origin_access_control, var.defaults.create_origin_access_control, false)
11-
create_origin_access_identity = try(each.value.create_origin_access_identity, var.defaults.create_origin_access_identity, false)
12-
custom_error_response = try(each.value.custom_error_response, var.defaults.custom_error_response, {})
13-
default_cache_behavior = try(each.value.default_cache_behavior, var.defaults.default_cache_behavior, null)
14-
default_root_object = try(each.value.default_root_object, var.defaults.default_root_object, null)
15-
enabled = try(each.value.enabled, var.defaults.enabled, true)
16-
geo_restriction = try(each.value.geo_restriction, var.defaults.geo_restriction, {})
17-
http_version = try(each.value.http_version, var.defaults.http_version, "http2")
18-
is_ipv6_enabled = try(each.value.is_ipv6_enabled, var.defaults.is_ipv6_enabled, null)
19-
logging_config = try(each.value.logging_config, var.defaults.logging_config, {})
20-
ordered_cache_behavior = try(each.value.ordered_cache_behavior, var.defaults.ordered_cache_behavior, [])
21-
origin = try(each.value.origin, var.defaults.origin, null)
6+
aliases = try(each.value.aliases, var.defaults.aliases, null)
7+
comment = try(each.value.comment, var.defaults.comment, null)
8+
continuous_deployment_policy_id = try(each.value.continuous_deployment_policy_id, var.defaults.continuous_deployment_policy_id, null)
9+
create_distribution = try(each.value.create_distribution, var.defaults.create_distribution, true)
10+
create_monitoring_subscription = try(each.value.create_monitoring_subscription, var.defaults.create_monitoring_subscription, false)
11+
create_origin_access_control = try(each.value.create_origin_access_control, var.defaults.create_origin_access_control, false)
12+
create_origin_access_identity = try(each.value.create_origin_access_identity, var.defaults.create_origin_access_identity, false)
13+
custom_error_response = try(each.value.custom_error_response, var.defaults.custom_error_response, {})
14+
default_cache_behavior = try(each.value.default_cache_behavior, var.defaults.default_cache_behavior, null)
15+
default_root_object = try(each.value.default_root_object, var.defaults.default_root_object, null)
16+
enabled = try(each.value.enabled, var.defaults.enabled, true)
17+
geo_restriction = try(each.value.geo_restriction, var.defaults.geo_restriction, {})
18+
http_version = try(each.value.http_version, var.defaults.http_version, "http2")
19+
is_ipv6_enabled = try(each.value.is_ipv6_enabled, var.defaults.is_ipv6_enabled, null)
20+
logging_config = try(each.value.logging_config, var.defaults.logging_config, {})
21+
ordered_cache_behavior = try(each.value.ordered_cache_behavior, var.defaults.ordered_cache_behavior, [])
22+
origin = try(each.value.origin, var.defaults.origin, null)
2223
origin_access_control = try(each.value.origin_access_control, var.defaults.origin_access_control, {
2324
s3 = {
2425
description = "",
@@ -32,6 +33,7 @@ module "wrapper" {
3233
price_class = try(each.value.price_class, var.defaults.price_class, null)
3334
realtime_metrics_subscription_status = try(each.value.realtime_metrics_subscription_status, var.defaults.realtime_metrics_subscription_status, "Enabled")
3435
retain_on_delete = try(each.value.retain_on_delete, var.defaults.retain_on_delete, false)
36+
staging = try(each.value.staging, var.defaults.staging, false)
3537
tags = try(each.value.tags, var.defaults.tags, null)
3638
viewer_certificate = try(each.value.viewer_certificate, var.defaults.viewer_certificate, {
3739
cloudfront_default_certificate = true

0 commit comments

Comments
 (0)