From 77ca8e0cbda7dbd4dbfece3e594a34cf410694cb Mon Sep 17 00:00:00 2001 From: "John \"Preston\" Mille" Date: Wed, 15 Nov 2023 16:30:59 +0000 Subject: [PATCH] Allows to set DomainName in DHCP Options --- ecs_composex/vpc/vpc_stack.py | 3 ++- ecs_composex/vpc/vpc_template.py | 6 +++++- ecs_composex/vpc/x-vpc.spec.json | 10 ++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/ecs_composex/vpc/vpc_stack.py b/ecs_composex/vpc/vpc_stack.py index 17e776dbf..efce93d44 100644 --- a/ecs_composex/vpc/vpc_stack.py +++ b/ecs_composex/vpc/vpc_stack.py @@ -112,6 +112,7 @@ def create_vpc(self, template: Template, settings: ComposeXSettings) -> None: self.vpc_cidr = set_else_none( VPC_CIDR.title, self.properties, self.default_ipv4_cidr ) + self.dhcp_options = set_else_none("DHCPOptions", self.properties, {}) region_account_zones = settings.session.client( "ec2" ).describe_availability_zones() @@ -130,7 +131,7 @@ def create_vpc(self, template: Template, settings: ComposeXSettings) -> None: self.azs[APP_SUBNETS] = current_region_azs self.layers = get_subnet_layers(self.vpc_cidr, len(curated_azs)) - vpc_core = add_vpc_core(template, self.vpc_cidr) + vpc_core = add_vpc_core(template, self.vpc_cidr, self.dhcp_options) self.vpc = vpc_core[0] self.storage_subnets = add_storage_subnets( template, self.vpc, azs_index, self.layers diff --git a/ecs_composex/vpc/vpc_template.py b/ecs_composex/vpc/vpc_template.py index a8532cfd5..f4f66f44f 100644 --- a/ecs_composex/vpc/vpc_template.py +++ b/ecs_composex/vpc/vpc_template.py @@ -14,6 +14,7 @@ AWS_REGION, GetAtt, If, + NoValue, Ref, Sub, Tags, @@ -39,7 +40,7 @@ AZ_INDEX_RE = re.compile(AZ_INDEX_PATTERN) -def add_vpc_core(template, vpc_cidr): +def add_vpc_core(template, vpc_cidr, dhcp_options: dict): """ Function to create the core resources of the VPC and add them to the core VPC template @@ -80,6 +81,9 @@ def add_vpc_core(template, vpc_cidr): dhcp_opts = DHCPOptions( "VpcDhcpOptions", template=template, + DomainName=dhcp_options["DomainName"] + if (dhcp_options and "DomainName" in dhcp_options) + else NoValue, DomainNameServers=["AmazonProvidedDNS"], Tags=Tags(Name=Sub(f"dhcp-${{{vpc.title}}}")), Metadata=metadata, diff --git a/ecs_composex/vpc/x-vpc.spec.json b/ecs_composex/vpc/x-vpc.spec.json index a6f691d6a..1c60d3c20 100644 --- a/ecs_composex/vpc/x-vpc.spec.json +++ b/ecs_composex/vpc/x-vpc.spec.json @@ -118,6 +118,16 @@ "description": "If true, won't create any NAT. Mutually exclusive with SingleNat", "default": false }, + "DHCPOptions": { + "type": "object", + "additionalProperties": false, + "properties": { + "DomainName": { + "type": "string", + "description": "https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-dhcpoptions.html#cfn-ec2-dhcpoptions-domainname" + } + } + }, "Endpoints": { "type": "object", "properties": {