This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def subnet_generator(subnets, vpc): | |
vpc_network = vpc.cidr_block.apply(ip_network) | |
nxt = str(vpc_network.network_address) | |
print(nxt) # prints `<pulumi.output.Output object at 0x108b93730>` | |
def valid_cidr(s1, s2): | |
if s1.network_address == s2.network_address: | |
return True | |
elif s1 > s2: | |
return True | |
else: | |
return False | |
for subnet in subnets: | |
count = subnet.get('az_count') | |
availability_zones = getn_availability_zones(count) | |
for i in range(count): | |
availability_zone = availability_zones[i] | |
mask = subnet.get('cidr_mask') | |
subnet_cidr = next(sn for sn in vpc_network.subnets(new_prefix=mask) if valid_cidr(sn, ip_network(nxt))) | |
nxt = str(subnet_cidr.broadcast_address + 1) # raises `TypeError: 'Output' object is not callable` | |
yield { | |
'name': vpc.name.apply(lambda x: f'{x}-{subnet.get("name")}_{availability_zone}'), | |
'cidr_block': str(subnet_cidr), | |
'has_natgw': subnet.get('has_natgw', False), | |
'availability_zone': availability_zone, | |
'kind': subnet.get('kind'), | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment