Skip to content

Commit

Permalink
Allows to set DomainName in DHCP Options
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnPreston committed Nov 15, 2023
1 parent fa98419 commit 77ca8e0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
3 changes: 2 additions & 1 deletion ecs_composex/vpc/vpc_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down
6 changes: 5 additions & 1 deletion ecs_composex/vpc/vpc_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
AWS_REGION,
GetAtt,
If,
NoValue,
Ref,
Sub,
Tags,
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions ecs_composex/vpc/x-vpc.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit 77ca8e0

Please sign in to comment.