Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allows to set DomainName in DHCP Options #713

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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