Skip to content

Commit

Permalink
enha: added support for subdomains
Browse files Browse the repository at this point in the history
  • Loading branch information
kfc-manager committed Mar 7, 2024
1 parent 8303b5b commit ec87de0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
13 changes: 9 additions & 4 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,21 @@ resource "aws_s3_bucket_public_access_block" "main" {
# Route53 #
################################

# get public zone already present in account
locals {
sub_strings = split(".", var.domain)
base_domain = "${local.sub_strings[length(local.sub_strings) - 2]}.${local.sub_strings[length(local.sub_strings) - 1]}"
}

# get public zone for base domain (must be already present in account)
data "aws_route53_zone" "main" {
count = var.domain != "test" ? 1 : 0
name = var.domain
count = !var.test ? 1 : 0
name = local.base_domain
private_zone = false
}

# conditionally set the zone_id to a dummy value for unit tests to run
locals {
zone_id = var.domain != "test" ? data.aws_route53_zone.main[0].id : "testzone123"
zone_id = !var.test ? data.aws_route53_zone.main[0].id : "testzone123"
}

# Cloudfront requires the certificate to be issued in the global region (us-east-1)
Expand Down
12 changes: 8 additions & 4 deletions tests/cloudfront.tftest.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ run "invalid_identifier" {
command = plan

variables {
test = true
identifier = "ab"
domain = "test"
domain = "test.com"
}

expect_failures = [var.identifier]
Expand All @@ -22,17 +23,19 @@ run "valid_identifier" {
command = plan

variables {
test = true
identifier = "abc"
domain = "test"
domain = "test.com"
}
}

run "invalid_price_class" {
command = plan

variables {
test = true
identifier = "abc"
domain = "test"
domain = "test.com"
price_class = "FOOBAR_200"
}

Expand All @@ -43,8 +46,9 @@ run "valid_price_class" {
command = plan

variables {
test = true
identifier = "abc"
domain = "test"
domain = "test.com"
price_class = "PriceClass_200"
}
}
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,9 @@ variable "tags" {
type = map(string)
default = {}
}

variable "test" {
description = "A flag for wether or not creating a test environment to conduct unit tests with."
type = bool
default = false
}

0 comments on commit ec87de0

Please sign in to comment.