Skip to content

Commit

Permalink
pass AWS::NoValue to SubjectAlternativeNames if no alternate domains …
Browse files Browse the repository at this point in the history
…were provided to the stack
  • Loading branch information
tobiasmcnulty committed Sep 27, 2017
1 parent 9a96873 commit 73f2a0d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
13 changes: 3 additions & 10 deletions stack/assets.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os

from troposphere import Equals, GetAtt, If, Join, Output, Ref, Split, iam
from troposphere import GetAtt, If, Join, Output, Ref, Split, iam
from troposphere.cloudfront import (
DefaultCacheBehavior,
Distribution,
Expand All @@ -19,16 +19,9 @@
)

from .common import arn_prefix
from .domain import domain_name, domain_name_alternates
from .domain import domain_name, domain_name_alternates, no_alt_domains
from .template import template

no_alt_domains_condition = "NoAlternateDomains"
template.add_condition(
no_alt_domains_condition,
# Equals() only supports strings, so convert domain_name_alternates to one first
Equals(Join("", domain_name_alternates), ""),
)

common_bucket_conf = dict(
VersioningConfiguration=VersioningConfiguration(
Status="Enabled"
Expand All @@ -39,7 +32,7 @@
AllowedOrigins=Split(";", Join("", [
"https://", domain_name,
If(
no_alt_domains_condition,
no_alt_domains,
# if we don't have any alternate domains, return an empty string
"",
# otherwise, return the ';https://' that will be needed by the first domain
Expand Down
6 changes: 3 additions & 3 deletions stack/certificates.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from troposphere import Ref
from troposphere import If, Ref
from troposphere.certificatemanager import Certificate, DomainValidationOption

from .domain import domain_name, domain_name_alternates
from .domain import domain_name, domain_name_alternates, no_alt_domains
from .template import template

application = Ref(template.add_resource(
Certificate(
'Certificate',
DomainName=domain_name,
SubjectAlternativeNames=domain_name_alternates,
SubjectAlternativeNames=If(no_alt_domains, Ref("AWS::NoValue"), domain_name_alternates),
DomainValidationOptions=[
DomainValidationOption(
DomainName=domain_name,
Expand Down
9 changes: 8 additions & 1 deletion stack/domain.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from troposphere import Parameter, Ref
from troposphere import Equals, Join, Parameter, Ref

from .template import template

Expand All @@ -14,3 +14,10 @@
"the Subject Alternative Name extension of the SSL certificate.",
Type="CommaDelimitedList",
)))

no_alt_domains = "NoAlternateDomains"
template.add_condition(
no_alt_domains,
# Equals() only supports strings, so convert domain_name_alternates to one first
Equals(Join("", domain_name_alternates), ""),
)

0 comments on commit 73f2a0d

Please sign in to comment.