Hi guys, I’m trying to create `VPC` and `Subnet Ne...
# python
a
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
@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
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
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
@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
Is there an example of the
pulumi.output
and
pulumi.input
? I.e 2 resources with a dependency I didn't find
c
@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
Thanks @colossal-ram-89482 it makes more sense
c
Excellent!