Skip to content

Commit

Permalink
Add support for resource-specific tags
Browse files Browse the repository at this point in the history
  • Loading branch information
jansiwy committed Sep 21, 2024
1 parent 41a38eb commit dd3b3ec
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 21 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,5 @@ module "cloudfront-bucket-example" {
version = "~> 1.0"
bucket_name = "foo"
tags = {
environment = "production"
}
}
```
4 changes: 2 additions & 2 deletions bucket.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
resource "aws_s3_bucket" "this" {
bucket = var.bucket_name
bucket = var.s3_bucket_name

tags = var.tags
tags = merge(var.default_tags, var.s3_bucket_tags)
}

data "aws_iam_policy_document" "bucket_policy" {
Expand Down
2 changes: 1 addition & 1 deletion cloudfront.tf
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ resource "aws_cloudfront_distribution" "this" {
}
}

tags = var.tags
tags = marge(var.default_tags, var.cloudfront_distribution_tags)
}

locals {
Expand Down
56 changes: 42 additions & 14 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,13 @@ with matchgin domains via `acm_certificate_arn`.
EOS
}

variable "bucket_name" {
type = string
variable "cloudfront_distribution_tags" {
type = map(string)
default = {}

description = "Name of the S3 bucket to create"
description = <<EOS
Map of tags assigned to the CloudFront distribution.
EOS
}

variable "custom_error_response" {
Expand All @@ -53,44 +56,68 @@ variable "custom_error_response" {
response_page_path = string
})
)

default = []

description = "One or more custom error response elements to be used for the CloudFront distribution"
description = <<EOS
One or more custom error response elements to be used for the CloudFront distribution.
EOS
}

variable "default_root_object" {
type = string
default = null

description = "The default root object CloudFront is to request from the S3 bucket as root URL"
description = <<EOS
The default root object CloudFront is to request from the S3 bucket as root URL.
EOS
}

variable "default_tags" {
type = map(string)
default = {}

description = <<EOS
Map of tags assigned to all AWS resources created by this module.
EOS
}

variable "http_version" {
type = string
default = "http2"

description = "Supported HTTP versions set on the CloudFront distribution"
description = <<EOS
Supported HTTP versions set on the CloudFront distribution".
EOS
}

variable "tags" {
variable "s3_bucket_name" {
type = string

description = <<EOS
Name of the S3 bucket to create.
EOS
}

variable "s3_bucket_tags" {
type = map(string)
default = {}

description = "Tags to be assigned to the S3 bucket and the CloudFront distribution"
description = <<EOS
Map of tags assigned to the S3 bucket.
EOS
}


variable "trusted_key_groups" {
type = list(
object({
id = string
})
)

default = null

description = "List of AWS Key Groups to trust for CloudFront distribution's default cache behavior"
description = <<EOS
List of AWS Key Groups to trust for CloudFront distribution's default cache behavior.
EOS
}

variable "ttl" {
Expand All @@ -99,12 +126,13 @@ variable "ttl" {
default = number
max = number
})

default = {
min = 0
default = 86400
max = 31536000
}

description = "The min, default and max TTLs set on the CloudFront distribution"
description = <<EOS
The min, default and max TTLs set on the CloudFront distribution.
EOS
}

0 comments on commit dd3b3ec

Please sign in to comment.