rhythmic-branch-12845
11/24/2022, 7:57 AMvpc
project, to another project that needs the list of subnet ids.
Based on https://www.pulumi.com/docs/reference/pkg/python/pulumi/#stack-exports-1 and seeing pulumi.export(_name: str_, _value: Any_)
, I was thinking that I could export a list… but nope:
pulumi:pulumi:Stack (acm-us):
error: Program failed with an unhandled exception:
Traceback (most recent call last):
File "/Users/jf/.../pulumi/acm/./__main__.py", line 40, in <module>
pulumi.export(cert_arns, cert_arns)
File "/Users/jf/.../pulumi/venv/lib/python3.10/site-packages/pulumi/resource.py", line 1282, in export
res.output(name, value)
File "/Users/jf/.../pulumi/venv/lib/python3.10/site-packages/pulumi/runtime/stack.py", line 158, in output
self.outputs[name] = value
TypeError: unhashable type: 'list'
UPDATE: this has been resolved. A big thank you to @billowy-army-68599 for the help! Looking back at the code above again, I also see where I went wrong: pulumi.export(cert_arns, cert_arns)
should have been pulumi.export("cert_arns", cert_arns)
! argh…..apply
on each one. But nope!:
pulumi:pulumi:Stack (vpc-us):
error: Program failed with an unhandled exception:
Traceback (most recent call last):
File "/Users/jf/…/pulumi/vpc/./__main__.py", line 106, in <module>
pulumi.export('public_subnet_ids', yaml.dump( [ sid.apply(lambda v: f'{ v }') for sid in public_subnet_ids ] ))
File "/Users/jf/…/pulumi/venv/lib/python3.10/site-packages/yaml/__init__.py", line 253, in dump
return dump_all([data], stream, Dumper=Dumper, **kwds)
File "/Users/jf/…/pulumi/venv/lib/python3.10/site-packages/yaml/__init__.py", line 241, in dump_all
dumper.represent(data)
File "/Users/jf/…/pulumi/venv/lib/python3.10/site-packages/yaml/representer.py", line 27, in represent
node = self.represent_data(data)
File "/Users/jf/…/pulumi/venv/lib/python3.10/site-packages/yaml/representer.py", line 48, in represent_data
node = self.yaml_representers[data_types[0]](self, data)
File "/Users/jf/…/pulumi/venv/lib/python3.10/site-packages/yaml/representer.py", line 199, in represent_list
return self.represent_sequence('tag:<http://yaml.org|yaml.org>,2002:seq', data)
File "/Users/jf/…/pulumi/venv/lib/python3.10/site-packages/yaml/representer.py", line 92, in represent_sequence
node_item = self.represent_data(item)
File "/Users/jf/…/pulumi/venv/lib/python3.10/site-packages/yaml/representer.py", line 52, in represent_data
node = self.yaml_multi_representers[data_type](self, data)
File "/Users/jf/…/pulumi/venv/lib/python3.10/site-packages/yaml/representer.py", line 317, in represent_object
reduce = data.__reduce_ex__(2)
TypeError: 'Output' object is not callable
What I am doing wrong?
Instead of doing the export, I’ve also tried to print
with print( public_subnet_ids[0].apply(lambda v: f"{ v }") )
. While this does not give me any explicit errors, it seems that Pulumi still has issues because I get this output under `Diagnostics:`:
Diagnostics:
pulumi:pulumi:Stack (vpc-us):
Calling __str__ on an Output[T] is not supported.
To get the value of an Output[T] as an Output[str] consider:
1. o.apply(lambda v: f"prefix{v}suffix")
See <https://pulumi.io/help/outputs> for more details.
This function may throw in a future version of Pulumi.
It seems that it does NOT recognize that I have done precisely what it’s telling me to do?
This is the output for print(public_subnet_ids)
, btw:
[<pulumi.output.Output object at 0x1048b5f30>, <pulumi.output.Output object at 0x1048da950>, <pulumi.output.Output object at 0x104903430>]
billowy-army-68599
11/24/2022, 3:18 PMprint( public_subnet_ids[0].apply(lambda v: f"{ v }") )
it needs to be
public_subnet_ids.apply(lambda v: print v)
rhythmic-branch-12845
11/24/2022, 3:33 PMpublic_subnet_ids
is a list
• if I were to do a “public_subnet_ids.apply” call, I get AttributeError: ‘list’ object has no attribute ‘apply’
• unless you’re using python 2 (I’m not sure Pulumi supports that now), you will get a complaint: SyntaxError: Missing parentheses in call to ‘print’. Did you mean print(...)?
billowy-army-68599
11/24/2022, 3:34 PMoutput<T>
so you’d need to do
public_subnet_ids[0].apply(lambda v: print v)
print(v)
rhythmic-branch-12845
11/24/2022, 3:39 PMvpc
project, to another project that needs the list of subnet ids.
In this case then, I want to export a list. print(v)
just simply prints the text to Diagnostics:
(which I dont need) but does not export the list for use from another projectbillowy-army-68599
11/24/2022, 3:41 PMapply
- you have to resolve it.rhythmic-branch-12845
11/24/2022, 3:43 PMapply
and then export the list. I could do a pulumi.export("public_subnet_ids", public_subnet_ids)
… but Pulumi just gives me this under the output after running:
Outputs:
+ public_subnet_ids : [
+ [0]: <null>
+ [1]: <null>
+ [2]: <null>
]
I doubt this means I can access it from another projectpublic_subnet_ids
is just a list of `null`s):billowy-army-68599
11/24/2022, 3:45 PMrhythmic-branch-12845
11/24/2022, 3:46 PMbillowy-army-68599
11/24/2022, 3:47 PMrhythmic-branch-12845
11/24/2022, 3:51 PMaws.route53.CertificateValidation
. This is wrong. There is no aws.route53.CertificateValidation
. It should be aws.acm.CertificateValidation
• https://www.pulumi.com/registry/packages/aws/api-docs/lb/listener/#inputs: the description for protocol
says: Protocol. Valid values are HTTP, HTTPS, or #{protocol}. Defaults to #{protocol}.
It actually defaults to HTTP
.billowy-army-68599
11/24/2022, 3:52 PMrhythmic-branch-12845
11/24/2022, 3:53 PMpublic_subnet_ids = []
for i in range(0, vars.az_count):
public_subnet = aws.ec2.Subnet(...)
public_subnet_ids.append( public_subnet.id )
# hoping to export a proper list
pulumi.export('public_subnet_ids', public_subnet_ids)
billowy-army-68599
11/24/2022, 3:58 PMimport pulumi_aws
import pulumi
# Create a VPC
vpc = pulumi_aws.ec2.Vpc('my-vpc', cidr_block="172.16.0.0/16")
# Get all the availability zones
zones = pulumi_aws.get_availability_zones()
subnet_ids = []
# Loop through all the zones and create a subnet in each
for zone in zones.names:
vpc_subnet = pulumi_aws.ec2.Subnet(
f'vpc-subnet-{zone}',
vpc_id=vpc.id,
cidr_block=f'172.16.{len(subnet_ids)}.0/24',
availability_zone=zone
)
subnet_ids.append(vpc_subnet.id)
pulumi.export('subnet_ids', subnet_ids)
Updating (dev)
View Live: <https://app.pulumi.com/jaxxstorm/vpc_with_subnets_python/dev/updates/2>
Type Name Status Info
pulumi:pulumi:Stack vpc_with_subnets_python-dev
+- ├─ aws:ec2:Vpc my-vpc replaced (0.72s) [diff: ~cidrBlock]
+ ├─ aws:ec2:Subnet vpc-subnet-us-west-2a created (0.83s)
+ ├─ aws:ec2:Subnet vpc-subnet-us-west-2b created (0.84s)
+ ├─ aws:ec2:Subnet vpc-subnet-us-west-2c created (0.91s)
+ └─ aws:ec2:Subnet vpc-subnet-us-west-2d created (0.91s)
Outputs:
+ subnet_ids: [
+ [0]: "subnet-0e0b8c4ef854516e2"
+ [1]: "subnet-02351fc61ddbce3af"
+ [2]: "subnet-00efaf2162127a2f2"
+ [3]: "subnet-09d3ec89cf51b6388"
]
rhythmic-branch-12845
11/24/2022, 4:07 PMbillowy-army-68599
11/24/2022, 4:07 PMrhythmic-branch-12845
11/24/2022, 4:10 PMbillowy-army-68599
11/24/2022, 4:11 PMrhythmic-branch-12845
11/24/2022, 4:41 PMimport pulumi_aws
import pulumi
# Create a VPC
vpc = pulumi_aws.ec2.Vpc('my-vpc', cidr_block="172.16.0.0/16", tags = { 'Name': 'test' })
# Get all the availability zones
zones = pulumi_aws.get_availability_zones(all_availability_zones = True)
subnet_ids = []
# Loop through all the zones and create a subnet in each
for i in range(0, 3):
subnet_name = f'vpc-subnet-{i}'
vpc_subnet = pulumi_aws.ec2.Subnet(subnet_name,
vpc_id = vpc.id,
availability_zone = zones.names[i],
cidr_block=f'172.17.{len(subnet_ids)}.0/24',
tags = { 'Name': f'test-subnet-{i}' }
)
pulumi.export(subnet_name, vpc_subnet.id) # export vpc_subnet.id once
subnet_ids.append(vpc_subnet.id)
pulumi.export('subnet_ids', subnet_ids)
billowy-army-68599
11/24/2022, 4:42 PMrhythmic-branch-12845
11/24/2022, 4:45 PM.require_output
. I’ve not seen this in the docs that I’ve come across, only get_output
. Is this a synonym? I’m not able to find any info on .require_output
.get_output
billowy-army-68599
11/24/2022, 5:12 PMrequire_output
throws an error if the upstream stack reference doesn’t exist
get_output
will return null if the upstream stack reference doesn’t existrhythmic-branch-12845
11/24/2022, 5:14 PMbillowy-army-68599
11/24/2022, 5:19 PMrhythmic-branch-12845
11/24/2022, 5:28 PM