-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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
- Loading branch information
Showing
7 changed files
with
108 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |