https://pulumi.com logo
#python
Title
# python
a

agreeable-angle-1483

01/19/2020, 4:52 PM
Hi guys, I’m trying to create
VPC
and
Subnet Network
with Pulumi in python and during the process to understand the relationships management in Pulumi, I’ve created the following 3 files (attaching in the comments):
network.py
- which contains the python functions I want to use in multiple projects
Pulumi.stg.yaml
- contains the configurations
__main__.py
- main code with calls to the functions When I ran this code I saw there is no relationship management, I have tried to use
ResourceOptions(parent\child)
I’ve also tried to use the
dependsOn:
but I didn’t success to use it, I think in both options the resource should be exists before, and I want to know how to do it right. I’d be glad to get some examples because I didn’t find on the internet. Thanks a lot
c

colossal-ram-89482

01/20/2020, 3:22 AM
@agreeable-angle-1483 I would start by wiring up dependencies using the Python objects, not strings / names. Concretely in this case: looks like you are declaring the
compute.Subnetwork(...)
with
network
set to the string value of the
vpc_name
variable, which is
"lala"
. Instead you would set
network
equal to the object that is returned from
compute.Network(...)
. This should establish the desired relationship.
Related:
create_vpc()
would return that
Network
object, not the result of
pulumi.export(...)
. I expect that
pulumi.export()
returns
None
.
a

agreeable-angle-1483

01/20/2020, 2:49 PM
Thanks @colossal-ram-89482 I’ve got to this example which seems helpful https://github.com/pulumi/pulumi-awsx/blob/master/python/pulumi_aws_infra/network.py I’m looking for an example for how to use Outputs as dependency between resources in python
there is a huge lack of python examples
c

colossal-ram-89482

01/20/2020, 6:13 PM
Note that there are two notions of “output”. 1) Resource outputs of type
pulumi.output.Output
which can be used as inputs to other resources. And then 2) stack outputs which are created by
pulumi.export()
.
Agreed that there are far more examples for JS/TS. If you haven’t seen it, this repo has some Python examples for various cloud providers. https://github.com/pulumi/examples
w

white-balloon-205

01/20/2020, 7:28 PM
@agreeable-angle-1483 note that the awsx library is not yet available in Python (there is a partial port of part of the library in the repo there, but it is not complete and not yet documented). That is the reason there are almost no examples in that particular repo. “Examples” in most repros are also actually tests (we should rename to avoid confusion). There are 24 Python examples across a variety of clouds in the main Pulumi examples repo: https://github.com/pulumi/examples.
a

agreeable-angle-1483

01/21/2020, 6:43 AM
Is there an example of the
pulumi.output
and
pulumi.input
? I.e 2 resources with a dependency I didn't find
c

colossal-ram-89482

01/21/2020, 12:57 PM
@agreeable-angle-1483 Sure. Looking at https://github.com/pulumi/examples/blob/master/aws-py-s3-folder/__main__.py
web_bucket
is of type
pulumi_aws.s3.Bucket
web_bucket.id
is of type
pulumi.output.Output[str]
then in the
for
loop:
obj
is of type
pulumi_aws.s3.BucketObject
obj.bucket
is of type
Input[str]
obj.bucket
is set to
web_bucket.id
// assigning
Input
to
Output
Thus all of the `obj`s (bucket objects) are dependent on the creation of
web_bucket
(the bucket itself)
🙏 1
a

agreeable-angle-1483

01/22/2020, 8:52 AM
Thanks @colossal-ram-89482 it makes more sense
c

colossal-ram-89482

01/22/2020, 12:25 PM
Excellent!