Skip to content

Commit 1fc17c0

Browse files
committed
Attach tags through provider
1 parent 91dc93f commit 1fc17c0

File tree

6 files changed

+42
-3
lines changed

6 files changed

+42
-3
lines changed

README.md

+17-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,17 @@
1-
# tf-aws-static-site
1+
# tf-aws-static-site
2+
3+
Example use:
4+
```hcl
5+
module "hugo_blog" {
6+
source = "git::https://github.com/tabletcorry/tf-aws-static-site.git?ref=v1.1"
7+
8+
# Name for S3 bucket and possibly other resources in AWS
9+
name = "hugo-bucket-name"
10+
# Primary domain name for Cloudfront and certificate
11+
primary_domain_name = "example.com"
12+
# Secondary names for Cloudfront and certificate
13+
secondary_domain_names = ["www.example.com"]
14+
# JS Cloudfront function script for request path
15+
request_function_path = "${path.module}/request.js"
16+
}
17+
```

acm.tf

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ resource "aws_acm_certificate" "cloudfront" {
77
}
88

99
subject_alternative_names = var.secondary_domain_names
10-
1110
}
1211

1312
resource "aws_acm_certificate_validation" "cloudfront" {

cloudfront.tf

+5-1
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,13 @@ resource "aws_cloudfront_distribution" "self" {
7070

7171
resource "aws_cloudfront_function" "request" {
7272
code = file(var.request_function_path)
73-
name = "indexer"
73+
name = "${var.name}-request"
7474
runtime = "cloudfront-js-1.0"
7575
publish = true
76+
77+
lifecycle {
78+
create_before_destroy = true
79+
}
7680
}
7781

7882
resource "aws_cloudfront_response_headers_policy" "self" {

input.tf

+5
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,9 @@ variable "request_function_path" {
1818
variable "cloudfront_priceclass" {
1919
type = string
2020
default = "PriceClass_200"
21+
}
22+
23+
variable "tags" {
24+
type = map(string)
25+
default = {}
2126
}

locals.tf

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
locals {
22
s3_origin_id = "blogs3origin"
3+
module_tags = {
4+
module = "tf-aws-static-site"
5+
module_var_name = var.name
6+
}
7+
tags = merge(local.module_tags, var.tags)
38
}

provider.tf

+10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
provider "aws" {
22
alias = "us-east-1"
33
region = "us-east-1"
4+
5+
default_tags {
6+
tags = local.tags
7+
}
8+
}
9+
10+
provider "aws" {
11+
default_tags {
12+
tags = local.tags
13+
}
414
}

0 commit comments

Comments
 (0)