rhythmic-lamp-79430
12/30/2021, 4:33 PMvpc_info = aws.ec2.get_vpc(id=resource_vpc.id, opts=ResourceOptions(depends_on=[resource_vpc]))
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?witty-candle-66007
12/30/2021, 4:39 PMrhythmic-lamp-79430
12/30/2021, 4:43 PMresource_vpc.ipv6_cidr_block
object to string…witty-candle-66007
12/30/2021, 4:49 PM.apply()
scenario.
But in what context do you need to convert resource_vpc.ipv6_cidr_block
to a string?rhythmic-lamp-79430
12/30/2021, 7:53 PMipv6_network = IPNetwork(cidr)
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``white-balloon-205
_output
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-10569
12/30/2021, 8:19 PMapply()
to turn that block into one of the blocks for a subnets. Something like this (excuse the poor pseudocode, it's heavily typescript-influenced...):
ipv6_network.subnet(resource_vpc.ipv6_cidr_block.apply(cidr => IPNetwork(cidr)));
The value passed to IPNework()
is a string, and its return value is wrapped in a new Output before being passed to subnet()
. But since subnet()
is a Pulumi function, it handles Output parameters just fine.rhythmic-lamp-79430
12/30/2021, 8:40 PMvpc_info = aws.ec2.get_vpc_output(id=resource_vpc.id, opts=pulumi.ResourceOptions(depends_on=[resource_vpc]))
and is failing similar to .get_vpcTypeError: 'Output' object is not callable
little-cartoon-10569
12/30/2021, 9:14 PMapply()
on an object, do your work inside the apply() callback, then pass the result of apply()
to a Pulumi function or property.bucket_name
on line 40 is an output, public_read_policy_for_bucket()
is a function that operates on a string (which is the value "inside" bucket_name
), the bucket_name
on line 32 is a string, and the thing returned from public_read_policy_for_bucket()
is another Output which is used as the value of policy
.rhythmic-lamp-79430
12/30/2021, 9:22 PMipv6_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)
ipv6_network.subnet(64)
give a generator
which I am using in the subnet creation to get the next available one
ipv6_cidr = str(next(ipv6_subnets_generator))
The error this time is different though
File "./__main__.py", line 46, in <module>
ipv6_cidr = str(next(ipv6_subnets_generator))
TypeError: 'Output' object is not an iterator
little-cartoon-10569
12/30/2021, 9:42 PMapply()
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 apply()
on it too. Usually, the best thing is to make the function that you pass to apply()
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)))
apply()
when you're operating on a value that's contained in an Output.rhythmic-lamp-79430
12/30/2021, 10:29 PMreturn str(next(ipv6_network.subnet(64)))
too…but then the generator doesnt work 🙂little-cartoon-10569
12/30/2021, 10:56 PMsubnet(64)
returns an Output? If it does, then you have to use apply()
again.rhythmic-lamp-79430
12/30/2021, 11:32 PMlittle-cartoon-10569
12/31/2021, 12:26 AMapply()
, or you're not taking an Output parameter and you need to, or something like that.rhythmic-lamp-79430
12/31/2021, 12:58 AM