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

salmon-raincoat-19475

11/02/2021, 1:40 PM
Hi all! Just joined this community, and learned about Pulumi a couple weeks ago. I'm looking to add some capabilities to our Python/K8s Pulumi build, and noticed that relative imports and custom, non-Pulumi packages are not supported. For this reason, I was looking to make a custom Pulumi package to support some generic creation handling for our team....I saw the https://github.com/pulumi/pulumi-component-provider-py-boilerplate Is there a (more) simple provider example - more simplistic than the eks one?
p

prehistoric-activity-61023

11/02/2021, 1:41 PM
can you explain more what you meant by “non-Pulumi packages are not supported”?
I can imagine that relative imports don’t not work due to the way python part is run by pulumi cli but did you have some problems with other python packages? Can you give some examples where it breaks?
s

salmon-raincoat-19475

11/02/2021, 1:46 PM
sure. So I think you're en pointe with relative imports not working with pulumi cli (that's in-line with what I saw online) I tried making my own local package and importing it as
pulumi_helper
- but that didn't seem to work.... So I thought I had to create a custom pulumi component to make that work...
so for now, I'm doing this...but I want
pulumi_helper
to be higher-level, so other pulumi deployments can use it
p

prehistoric-activity-61023

11/02/2021, 2:17 PM
by “other pulumi deployments” you mean other repositories?
if you publish this package, you should have no issues with reusing it in different pulumi projects
If you want to create a module for a single repository, you don’t need to create a fully-fledged python package. You can simply create a module (as you did) and import it but use absolute imports to do that.
s

salmon-raincoat-19475

11/02/2021, 2:40 PM
So we have a parent repo, which has is our cloud infrastructure repo for deploying to multiple environments/projects...then as a sub-directory, we have
pulumi_iac/[project_name]
However, it sounds like we could have separate repos, and
from pulumi_helper import [stuff]
I'll give that a try, might have to remove my
venv
and re-install
requirements.txt
with the local module, since Pulumi was having some issues when running
pulumi preview
, etc. identifying the module's existence...
b

billowy-army-68599

11/02/2021, 3:10 PM
@salmon-raincoat-19475 there's some examples here: https://github.com/pulumi/examples/search?l=Python&q=ComponentResource
s

salmon-raincoat-19475

11/02/2021, 3:12 PM
thank you both!