Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] aws-single-page-static site to work outside us-east-1 #280

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,12 @@ check-mod:
.PHONY: check-mod

clean:
rm **/*.tfstate*; true
rm -rf **/.terraform; true
rm -rf **/.test-data; true
rm -rf */*.tfstate*; true
rm -rf */.terraform; true
rm -rf */.test-data; true
rm -rf */*/*.tfstate*; true
rm -rf */*/.terraform; true
rm -rf */*/.test-data; true
.PHONY: clean

test:
Expand Down
1 change: 0 additions & 1 deletion aws-s3-public-bucket/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ func TestPublicBucketDefaults(t *testing.T) {
fmt.Println("Testing ", test.action, " with https enabled=", test.secureTransport)
r.Equal(test.result, *resp.EvalDecision)
}

},
}

Expand Down
4 changes: 4 additions & 0 deletions aws-single-page-static-site/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ module "security_headers_lambda" {
owner = var.owner
env = var.env
service = var.service

providers = {
aws = aws.us-east-1
}
}

resource "aws_cloudfront_distribution" "s3_distribution" {
Expand Down
58 changes: 19 additions & 39 deletions aws-single-page-static-site/module_test.go
Original file line number Diff line number Diff line change
@@ -1,53 +1,33 @@
package test

import (
"fmt"
"testing"

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

func TestAwsSinglePageStaticSiteInit(t *testing.T) {
options := &terraform.Options{
TerraformDir: ".",
}
terraform.Init(t, options)
}

func TestAwsSinglePageStaticSiteInitAndApply(t *testing.T) {
t.Skip("Skipping because destroy is painfully slow (>30m on average) - consider running destroy out of band")

func TestAwsSinglePageStaticSite(t *testing.T) {
t.Parallel()
project := tftest.UniqueID()
env := tftest.UniqueID()
service := tftest.UniqueID()
owner := tftest.UniqueID()

subdomain := tftest.UniqueID()
awsACMCert := tftest.EnvVar(tftest.EnvWildcardCloudfrontCertARN)
route53ZoneID := tftest.EnvVar(tftest.EnvRoute53ZoneID)

aliases := []string{fmt.Sprintf(
"%s.%s",
tftest.UniqueID(),
tftest.EnvVar(tftest.EnvRoute53ZoneName))}

options := tftest.Options(
tftest.IAMRegion, // us-east-1
map[string]interface{}{
"project": project,
"env": env,
"service": service,
"owner": owner,

"subdomain": subdomain,
"aws_acm_cert_arn": awsACMCert,
"aws_route53_zone_id": route53ZoneID,
"aliases": aliases,
test := tftest.Test{
SkipDestroy: true,
Setup: func(t *testing.T) *terraform.Options {
subdomain := tftest.UniqueID()
route53ZoneID := tftest.EnvVar(tftest.EnvRoute53ZoneID)

options := tftest.Options(
tftest.DefaultRegion, // us-east-1
map[string]interface{}{
"subdomain": subdomain,
"aws_route53_zone_id": route53ZoneID,
},
)
options.TerraformDir = "./test"
return options
},
)
Validate: func(t *testing.T, options *terraform.Options) {},
}

defer tftest.Destroy(t, options, 5)
tftest.Run(t, options)
test.Run(t)
}
6 changes: 6 additions & 0 deletions aws-single-page-static-site/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
provider aws {}

provider aws {
alias = "us-east-1"
region = "us-east-1"
}
70 changes: 70 additions & 0 deletions aws-single-page-static-site/test/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
variable project {
type = string
}
variable env {
type = string
}
variable service {
type = string
}
variable owner {
type = string
}
variable subdomain {
type = string
}
variable aws_route53_zone_id {
type = string
}

data aws_route53_zone zone {
zone_id = var.aws_route53_zone_id
}

locals {
domain = replace(data.aws_route53_zone.zone.name, "/\\.$/", "")
website_fqdn = "${var.subdomain}.${local.domain}"
aliases = [
"www.${local.website_fqdn}",
]
}

# these will be inherited in the modules
provider aws {
}

provider aws {
alias = "us-east-1"
region = "us-east-1"
}

module cert {
source = "../../aws-acm-cert"

cert_domain_name = local.website_fqdn
aws_route53_zone_id = var.aws_route53_zone_id
cert_subject_alternative_names = { for a in local.aliases : a => var.aws_route53_zone_id }
cert_subject_alternative_names_count = length(local.aliases)

project = var.project
env = var.env
service = var.service
owner = var.owner

providers = {
aws = aws.us-east-1
}
}

module site {
source = "../."

subdomain = var.subdomain
aws_acm_cert_arn = module.cert.arn
aws_route53_zone_id = var.aws_route53_zone_id

project = var.project
env = var.env
service = var.service
owner = var.owner
}