diff --git a/stacks/custom_domain.go b/stacks/custom_domain.go index 3644e2d..cec119b 100644 --- a/stacks/custom_domain.go +++ b/stacks/custom_domain.go @@ -89,6 +89,7 @@ type CustomDomainStackParameters struct { HostedZone string ClusterStackName string PrimaryDomain string + CertificateName string AltDomain1 string AltDomain2 string AltDomain3 string @@ -141,6 +142,8 @@ func (p *CustomDomainStackParameters) SetInternalFields(sess *session.Session, n } p.HostedZone = strings.Split(*zone.Id, "/")[2] ui.Spinner.Stop() + // `*` is not allowed in certificate names + p.CertificateName = strings.Replace(*name, "*", "wildcard", -1) return nil } @@ -182,10 +185,9 @@ func (*CustomDomainStack) AskQuestions(_ *session.Session) error { } func (*CustomDomainStack) StackName(name *string) *string { - stackName := fmt.Sprintf( - customDomainStackNameTmpl, - strings.ReplaceAll(strings.TrimSuffix(*name, "."), ".", "-"), - ) + slug := strings.ReplaceAll(strings.TrimSuffix(*name, "."), ".", "-") + slug = strings.ReplaceAll(slug, "*", "wildcard") + stackName := fmt.Sprintf(customDomainStackNameTmpl, slug) return &stackName } @@ -193,9 +195,9 @@ func (*CustomDomainStack) StackType() string { return "custom domain" } -func (*CustomDomainStack) Tags(name *string) []*cloudformation.Tag { +func (a *CustomDomainStack) Tags(name *string) []*cloudformation.Tag { return []*cloudformation.Tag{ - {Key: aws.String("apppack:customDomain"), Value: name}, + {Key: aws.String("apppack:customDomain"), Value: &a.Parameters.CertificateName}, // TODO // {Key: aws.String("apppack:appName"), Value: appName}, {Key: aws.String("apppack"), Value: aws.String("true")}, diff --git a/stacks/custom_domain_test.go b/stacks/custom_domain_test.go new file mode 100644 index 0000000..dc5a790 --- /dev/null +++ b/stacks/custom_domain_test.go @@ -0,0 +1,22 @@ +package stacks + +import ( + "testing" + + "github.com/aws/aws-sdk-go/aws" +) + +func TestCustomDomainStackName(t *testing.T) { + stack := CustomDomainStack{} + actual := stack.StackName(aws.String("example.com")) + expected := "apppack-customdomain-example-com" + if *actual != expected { + t.Errorf("Expected %s, got %s", expected, *actual) + } + + actual = stack.StackName(aws.String("*.example.com")) + expected = "apppack-customdomain-wildcard-example-com" + if *actual != expected { + t.Errorf("Expected %s, got %s", expected, *actual) + } +}