Skip to content

Commit

Permalink
fix: tf lint formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
rankin-tr committed Sep 3, 2024
1 parent 331f4cb commit 7e0ff4d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
6 changes: 3 additions & 3 deletions examples/complete/s3-origins.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
locals {
additional_s3_origins_enabled = local.enabled && var.additional_s3_origins_enabled
default_s3_origin_configuration = {
domain_name = null
origin_id = null
origin_path = null
domain_name = null
origin_id = null
origin_path = null
origin_access_control_id = null
s3_origin_config = {
origin_access_identity = ""
Expand Down
24 changes: 12 additions & 12 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ locals {
origin_access_control_enabled = local.enabled && var.origin_access_type == "origin_access_control"

create_cloudfront_origin_access_identity = local.origin_access_identity_enabled && length(compact([var.cloudfront_origin_access_identity_iam_arn])) == 0 # "" or null
create_cloudfront_origin_access_control = local.origin_access_control_enabled && length(compact([var.cloudfront_origin_access_control_id])) == 0 # "" or null
create_cloudfront_origin_access_control = local.origin_access_control_enabled && length(compact([var.cloudfront_origin_access_control_id])) == 0 # "" or null

origin_id = module.this.id
origin_path = coalesce(var.origin_path, "/")
Expand All @@ -37,7 +37,7 @@ locals {

# Collect the information for cloudfront_origin_access_control and cloudfront_origin_access_identity and shorten the variable names
cf_origin_access_control_id_arn = "arn:${join("", data.aws_partition.current[*].partition)}:cloudfront::${data.aws_caller_identity.current.account_id}:distribution/${var.cloudfront_origin_access_control_id}"

cf_access_options = var.origin_access_type == "origin_access_identity" ? {
new = local.create_cloudfront_origin_access_identity ? {
arn = aws_cloudfront_origin_access_identity.default[0].iam_arn
Expand All @@ -46,8 +46,8 @@ locals {
existing = {
arn = var.cloudfront_origin_access_identity_iam_arn
path = var.cloudfront_origin_access_identity_path
}
} : var.origin_access_type == "origin_access_control" ? {
}
} : var.origin_access_type == "origin_access_control" ? {
new = local.create_cloudfront_origin_access_control ? {
arn = "arn:${join("", data.aws_partition.current[*].partition)}:cloudfront::${data.aws_caller_identity.current.account_id}:distribution/${aws_cloudfront_origin_access_control.default[0].id}"
} : null
Expand Down Expand Up @@ -108,7 +108,7 @@ locals {
"$${origin_path}", local.origin_path),
"$${bucket_name}", local.bucket),
"$${cloudfront_origin_access_identity_iam_arn}", try(local.cf_access.arn, "")),
"$${cloudfront_origin_access_control_arn}", try(local.cf_access.arn, ""))
"$${cloudfront_origin_access_control_arn}", try(local.cf_access.arn, ""))
}

data "aws_partition" "current" {
Expand All @@ -135,7 +135,7 @@ resource "aws_cloudfront_origin_access_identity" "default" {
}

resource "aws_cloudfront_origin_access_control" "default" {
count = local.create_cloudfront_origin_access_control ? 1 : 0
count = local.create_cloudfront_origin_access_control ? 1 : 0
name = local.origin_id
description = local.origin_id
origin_access_control_origin_type = "s3"
Expand Down Expand Up @@ -197,9 +197,9 @@ data "aws_iam_policy_document" "s3_origin_access_control" {
}

condition {
test = "StringEquals"
test = "StringEquals"
variable = "AWS:SourceArn"
values = [aws_cloudfront_distribution.default[0].arn]
values = [aws_cloudfront_distribution.default[0].arn]
}
}
}
Expand Down Expand Up @@ -508,9 +508,9 @@ resource "aws_cloudfront_distribution" "default" {
}

origin {
domain_name = local.bucket_domain_name
origin_id = local.origin_id
origin_path = var.origin_path
domain_name = local.bucket_domain_name
origin_id = local.origin_id
origin_path = var.origin_path
# the following enables specifying the origin_access_identity used by the origin created by this module, prior to the module's creation:
origin_access_control_id = local.create_cloudfront_origin_access_control ? aws_cloudfront_origin_access_control.default[0].id : local.origin_access_control_enabled && length(compact([var.cloudfront_origin_access_control_id])) > 0 ? var.cloudfront_origin_access_control_id : null

Expand Down Expand Up @@ -580,7 +580,7 @@ resource "aws_cloudfront_distribution" "default" {
origin_path = lookup(origin.value, "origin_path", "")
# the following enables specifying the origin_access_control used by the origin created by this module, prior to the module's creation:
origin_access_control_id = local.origin_access_control_enabled && try(length(origin.value.s3_origin_config.origin_access_control_id), 0) > 0 ? origin.value.s3_origin_config.origin_access_control_id : local.origin_access_control_enabled ? aws_cloudfront_origin_access_control.default[0].id : null

dynamic "s3_origin_config" {
for_each = local.origin_access_identity_enabled ? var.s3_origins : []
content {
Expand Down
20 changes: 10 additions & 10 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ variable "cloudfront_origin_access_control_id" {

variable "origin_access_control_signing_behavior" {
# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudfront_origin_access_control#signing_behavior
type = string
default = "always"
type = string
default = "always"
description = "Specifies which requests CloudFront signs. Specify always for the most common use case. Allowed values: always, never, and no-override."

validation {
condition = var.origin_access_control_signing_behavior == "always" || var.origin_access_control_signing_behavior == "no-override" || var.origin_access_control_signing_behavior == "never"
condition = var.origin_access_control_signing_behavior == "always" || var.origin_access_control_signing_behavior == "no-override" || var.origin_access_control_signing_behavior == "never"
error_message = "The origin_access_control_signing_behavior must be one of: `always`, `no-override`, or `never`."
}
}
Expand Down Expand Up @@ -470,9 +470,9 @@ variable "custom_origins" {

variable "s3_origins" {
type = list(object({
domain_name = string
origin_id = string
origin_path = string
domain_name = string
origin_id = string
origin_path = string
origin_access_control_id = string
s3_origin_config = object({
origin_access_identity = string
Expand Down Expand Up @@ -517,11 +517,11 @@ variable "deployment_actions" {
}

variable "origin_access_type" {
type = string
default = "origin_access_identity"
type = string
default = "origin_access_identity"
description = "Choose to use `origin_access_control` or `orgin_access_identity`"
validation {
condition = var.origin_access_type == "origin_access_control" || var.origin_access_type == "origin_access_identity"
condition = var.origin_access_type == "origin_access_control" || var.origin_access_type == "origin_access_identity"
error_message = "The origin_access_type must be `origin_access_control` or `origin_access_identity`."
}
}
Expand Down

0 comments on commit 7e0ff4d

Please sign in to comment.