Skip to content

Commit 9be9388

Browse files
authored
[fix] aws-single-page-static site to work outside us-east-1 (#280)
Allow this module to work across regions by configuring providers specifically for us-east-1 where needed. Also fix the tests to work. ### Test Plan * tests work now
1 parent ecdcc6f commit 9be9388

File tree

7 files changed

+108
-46
lines changed

7 files changed

+108
-46
lines changed

.github/workflows/ci.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jobs:
66
- uses: actions/checkout@v2
77
- uses: actions/setup-go@v2
88
with:
9-
go-version: 1.14.3
9+
go-version: 1.15.5
1010
- run: make check-mod
1111
lint:
1212
name: lint
@@ -15,7 +15,7 @@ jobs:
1515
- uses: actions/checkout@v2
1616
- uses: hashicorp/setup-terraform@v1
1717
with:
18-
terraform_version: 0.12.24
18+
terraform_version: 0.12.30
1919
terraform_wrapper: "false"
2020
- name: setup
2121
run: make setup
@@ -37,7 +37,7 @@ jobs:
3737
- if: github.event == 'push' || steps.filter.outputs.module == 'true'
3838
uses: hashicorp/setup-terraform@v1
3939
with:
40-
terraform_version: 0.12.28
40+
terraform_version: 0.12.30
4141
terraform_wrapper: "false"
4242
- if: github.event == 'push' || steps.filter.outputs.module == 'true'
4343
uses: actions/setup-go@v2

Makefile

+6-3
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,12 @@ check-mod:
8585
.PHONY: check-mod
8686

8787
clean:
88-
rm **/*.tfstate*; true
89-
rm -rf **/.terraform; true
90-
rm -rf **/.test-data; true
88+
rm -rf */*.tfstate*; true
89+
rm -rf */.terraform; true
90+
rm -rf */.test-data; true
91+
rm -rf */*/*.tfstate*; true
92+
rm -rf */*/.terraform; true
93+
rm -rf */*/.test-data; true
9194
.PHONY: clean
9295

9396
test:

aws-s3-public-bucket/module_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ func TestPublicBucketDefaults(t *testing.T) {
124124
fmt.Println("Testing ", test.action, " with https enabled=", test.secureTransport)
125125
r.Equal(test.result, *resp.EvalDecision)
126126
}
127-
128127
},
129128
}
130129

aws-single-page-static-site/main.tf

+4
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ module "security_headers_lambda" {
9191
owner = var.owner
9292
env = var.env
9393
service = var.service
94+
95+
providers = {
96+
aws = aws.us-east-1
97+
}
9498
}
9599

96100
resource "aws_cloudfront_distribution" "s3_distribution" {
+19-39
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,33 @@
11
package test
22

33
import (
4-
"fmt"
54
"testing"
65

76
"github.com/chanzuckerberg/go-misc/tftest"
87
"github.com/gruntwork-io/terratest/modules/terraform"
98
)
109

11-
func TestAwsSinglePageStaticSiteInit(t *testing.T) {
12-
options := &terraform.Options{
13-
TerraformDir: ".",
14-
}
15-
terraform.Init(t, options)
16-
}
17-
18-
func TestAwsSinglePageStaticSiteInitAndApply(t *testing.T) {
19-
t.Skip("Skipping because destroy is painfully slow (>30m on average) - consider running destroy out of band")
20-
10+
func TestAwsSinglePageStaticSite(t *testing.T) {
2111
t.Parallel()
22-
project := tftest.UniqueID()
23-
env := tftest.UniqueID()
24-
service := tftest.UniqueID()
25-
owner := tftest.UniqueID()
2612

27-
subdomain := tftest.UniqueID()
28-
awsACMCert := tftest.EnvVar(tftest.EnvWildcardCloudfrontCertARN)
29-
route53ZoneID := tftest.EnvVar(tftest.EnvRoute53ZoneID)
30-
31-
aliases := []string{fmt.Sprintf(
32-
"%s.%s",
33-
tftest.UniqueID(),
34-
tftest.EnvVar(tftest.EnvRoute53ZoneName))}
35-
36-
options := tftest.Options(
37-
tftest.IAMRegion, // us-east-1
38-
map[string]interface{}{
39-
"project": project,
40-
"env": env,
41-
"service": service,
42-
"owner": owner,
43-
44-
"subdomain": subdomain,
45-
"aws_acm_cert_arn": awsACMCert,
46-
"aws_route53_zone_id": route53ZoneID,
47-
"aliases": aliases,
13+
test := tftest.Test{
14+
SkipDestroy: true,
15+
Setup: func(t *testing.T) *terraform.Options {
16+
subdomain := tftest.UniqueID()
17+
route53ZoneID := tftest.EnvVar(tftest.EnvRoute53ZoneID)
18+
19+
options := tftest.Options(
20+
tftest.DefaultRegion, // us-east-1
21+
map[string]interface{}{
22+
"subdomain": subdomain,
23+
"aws_route53_zone_id": route53ZoneID,
24+
},
25+
)
26+
options.TerraformDir = "./test"
27+
return options
4828
},
49-
)
29+
Validate: func(t *testing.T, options *terraform.Options) {},
30+
}
5031

51-
defer tftest.Destroy(t, options, 5)
52-
tftest.Run(t, options)
32+
test.Run(t)
5333
}
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
provider aws {}
2+
3+
provider aws {
4+
alias = "us-east-1"
5+
region = "us-east-1"
6+
}
+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
variable project {
2+
type = string
3+
}
4+
variable env {
5+
type = string
6+
}
7+
variable service {
8+
type = string
9+
}
10+
variable owner {
11+
type = string
12+
}
13+
variable subdomain {
14+
type = string
15+
}
16+
variable aws_route53_zone_id {
17+
type = string
18+
}
19+
20+
data aws_route53_zone zone {
21+
zone_id = var.aws_route53_zone_id
22+
}
23+
24+
locals {
25+
domain = replace(data.aws_route53_zone.zone.name, "/\\.$/", "")
26+
website_fqdn = "${var.subdomain}.${local.domain}"
27+
aliases = [
28+
"www.${local.website_fqdn}",
29+
]
30+
}
31+
32+
# these will be inherited in the modules
33+
provider aws {
34+
}
35+
36+
provider aws {
37+
alias = "us-east-1"
38+
region = "us-east-1"
39+
}
40+
41+
module cert {
42+
source = "../../aws-acm-cert"
43+
44+
cert_domain_name = local.website_fqdn
45+
aws_route53_zone_id = var.aws_route53_zone_id
46+
cert_subject_alternative_names = { for a in local.aliases : a => var.aws_route53_zone_id }
47+
cert_subject_alternative_names_count = length(local.aliases)
48+
49+
project = var.project
50+
env = var.env
51+
service = var.service
52+
owner = var.owner
53+
54+
providers = {
55+
aws = aws.us-east-1
56+
}
57+
}
58+
59+
module site {
60+
source = "../."
61+
62+
subdomain = var.subdomain
63+
aws_acm_cert_arn = module.cert.arn
64+
aws_route53_zone_id = var.aws_route53_zone_id
65+
66+
project = var.project
67+
env = var.env
68+
service = var.service
69+
owner = var.owner
70+
}

0 commit comments

Comments
 (0)