rhythmic-lamp-7943012/30/2021, 4:33 PM
to get the ipv6 subnet… however, if i run the whole stack in one go it fails… if i run it in stages i.e. create just the vpc and then create the subnet in second try it works fine. i have tried the depends_on mechanism but doesnt seem to be working… any idea what I might be doing wrong?
vpc_info = aws.ec2.get_vpc(id=resource_vpc.id, opts=ResourceOptions(depends_on=[resource_vpc]))
witty-candle-6600712/30/2021, 4:39 PM
rhythmic-lamp-7943012/30/2021, 4:43 PM
object to string…
witty-candle-6600712/30/2021, 4:49 PM
scenario. But in what context do you need to convert
to a string?
rhythmic-lamp-7943012/30/2021, 7:53 PM
Out of this i can then use the subnet method for a specific prefix length to generated the number of subnets per vpc. `ipv6_network.subnet(prefix``
ipv6_network = IPNetwork(cidr)
form of this call, which will take inputs and return outputs, ensuring that your call happens once the inputs are available (the VPC has been created).
vpc_info = aws.ec2.get_vpc_output(id=resource_vpc.id)
little-cartoon-1056912/30/2021, 8:19 PM
to turn that block into one of the blocks for a subnets. Something like this (excuse the poor pseudocode, it's heavily typescript-influenced...):
The value passed to
ipv6_network.subnet(resource_vpc.ipv6_cidr_block.apply(cidr => IPNetwork(cidr)));
is a string, and its return value is wrapped in a new Output before being passed to
. But since
is a Pulumi function, it handles Output parameters just fine.
rhythmic-lamp-7943012/30/2021, 8:40 PM
and is failing similar to .get_vpc
vpc_info = aws.ec2.get_vpc_output(id=resource_vpc.id, opts=pulumi.ResourceOptions(depends_on=[resource_vpc]))
TypeError: 'Output' object is not callable
little-cartoon-1056912/30/2021, 9:14 PM
on an object, do your work inside the apply() callback, then pass the result of
to a Pulumi function or property.
on line 40 is an output,
is a function that operates on a string (which is the value "inside"
on line 32 is a string, and the thing returned from
is another Output which is used as the value of
rhythmic-lamp-7943012/30/2021, 9:22 PM
ipv6_cidr_block = resource_vpc.ipv6_cidr_block ipv6_subnets_generator = ipv6_cidr_block.apply(get_ipv6_subnets_of)
def get_ipv6_subnets_of(cidr): ipv6_network = IPNetwork(cidr) return ipv6_network.subnet(64)
give a generator which I am using in the subnet creation to get the next available one
The error this time is different though
ipv6_cidr = str(next(ipv6_subnets_generator))
File "./__main__.py", line 46, in <module> ipv6_cidr = str(next(ipv6_subnets_generator)) TypeError: 'Output' object is not an iterator
little-cartoon-1056912/30/2021, 9:42 PM
is always an Output; you return a string or iterator or whatever, and Pulumi wraps it in an Output before your code gets it. So you need to call
on it too. Usually, the best thing is to make the function that you pass to
return the ultimate thing you need, not an interim thing:
ipv6_cidr = ipv6_cidr_block.apply(myfunc); def myfunc(cidr): ipv6 _network = IPNetwork(cidr) return str(next(ipv6_network.subnet(64)))
when you're operating on a value that's contained in an Output.
rhythmic-lamp-7943012/30/2021, 10:29 PM
too…but then the generator doesnt work 🙂
little-cartoon-1056912/30/2021, 10:56 PM
returns an Output? If it does, then you have to use
rhythmic-lamp-7943012/30/2021, 11:32 PM
little-cartoon-1056912/31/2021, 12:26 AM
, or you're not taking an Output parameter and you need to, or something like that.
rhythmic-lamp-7943012/31/2021, 12:58 AM