diff --git a/aladdin/lib/aws/dns_mapping.py b/aladdin/lib/aws/dns_mapping.py index 94e9bb6..cac775a 100644 --- a/aladdin/lib/aws/dns_mapping.py +++ b/aladdin/lib/aws/dns_mapping.py @@ -10,16 +10,13 @@ def fill_hostedzone( ): cluster_domain_name = cluster_domain_name or ClusterRules().cluster_domain_name namespace_domain_name = namespace_domain_name or ClusterRules().namespace_domain_name + namespace_hosted_zone = get_hostedzone( + boto_session, namespace_domain_name + ) or create_hostedzone(boto_session, namespace_domain_name) - # Get the namespace hosted zone, raise an error if not found - namespace_hosted_zone = get_hostedzone(boto_session, namespace_domain_name) - if namespace_hosted_zone is None: - raise KeyError("Hosted zone for [%s] not found" % namespace_domain_name) - - # Get the cluster hosted zone, raise an error if not found cluster_hosted_zone = get_hostedzone(boto_session, cluster_domain_name) if cluster_hosted_zone is None: - raise KeyError("Route 53 for [%s] not found" % cluster_domain_name) + raise KeyError("route 53 for [%s] not found" % cluster_domain_name) dns_nameservers = get_ns_from_hostedzone(boto_session, namespace_hosted_zone) @@ -51,6 +48,24 @@ def get_hostedzone(boto_session, dns_name) -> str: return hostedzone_id +def create_hostedzone(boto_session, dns_name) -> str: + log = logging.getLogger(__name__) + route53 = boto_session.client("route53") + + ref = "aladdin_generated_{:%Y%m%d_%H%M%S}".format(datetime.now()) + + log.info("Hosted zone %s created", dns_name) + + log.info("Creating hosted zone : %s", dns_name) + create_res = route53.create_hosted_zone( + Name=dns_name, + CallerReference=ref, + HostedZoneConfig=dict(Comment="Generated by aladdin", PrivateZone=False), + ) + + return create_res["HostedZone"]["Id"] + + def get_ns_from_hostedzone(boto_session, hostedzone_id): route53 = boto_session.client("route53") diff --git a/pyproject.toml b/pyproject.toml index 4207938..c90f1eb 100755 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "aladdin" -version = "1.25.15.3" +version = "1.25.15.2" description = "" authors = ["Fivestars "] include = [