Posting here rather than <#CDE799L1M|python> becau...
# general
o
Posting here rather than #python because I don’t think it’s specific to Python. I have Pulumi installed manually in ~/.pulumi/bin. I have a virtualenv set up and pulumi Python package installed with pip. I start
python3
and try to do the following at the interactive prompt:
Copy code
>>> import pulumi
>>> config = pulumi.Config()
and I get “Program run without the Pulumi engine available; re-run using the
pulumi
CLI” The pulumi binary is in PATH, I checked with
print(os.environ["PATH"])
What else does it need?
b
Have you pip installed Python? It should be in your requirements file as well
o
I pip installed -r requirements.txt, if that’s what you mean. and I have the virtualenv active. the import line wouldn’t work otherwise
I’m looking at the source code, apparently it has something to do with not having a value for SETTINGS.project, but that’s marked as Optional? There is no “project” in any of the .yaml files, if that’s what it’s looking for.
I’ll pull on that thread later, can’t do it now. The full stack trace is:
Copy code
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/bgdnlp/khron/.env/lib/python3.7/site-packages/pulumi/config.py", line 46, in __init__
    name = get_project()
  File "/Users/bgdnlp/khron/.env/lib/python3.7/site-packages/pulumi/metadata.py", line 23, in get_project
    return runtime_gp()
  File "/Users/bgdnlp/khron/.env/lib/python3.7/site-packages/pulumi/runtime/settings.py", line 126, in get_project
    require_test_mode_enabled()
  File "/Users/bgdnlp/khron/.env/lib/python3.7/site-packages/pulumi/runtime/settings.py", line 114, in require_test_mode_enabled
    raise RunError('Program run without the Pulumi engine available; re-run using the `pulumi` CLI')
pulumi.errors.RunError: Program run without the Pulumi engine available; re-run using the `pulumi` CLI
This might be specific to Python after all
This looks like a bug to me. Either in the docs, or code. The docs give
config = pulumi.Config()
as a valid example in several places, but the code seems to require either a project name or “test mode” set. Maybe I’m missing something. Is it a bug, should I open an issue?
g
never tried pulumi python myself (I'm using the TypeScript flavor), however I think the issue is that you have to run pulumi programs via the
pulumi
CLI command and not via the
python3
command as entry-point.
o
I don’t think that’s intended. A Python dev would absolutely expect to be able to do what I just tried.
Plus, I just tried to set a config value with
pulumi config set testkey "testvalue"
and then retrieve it with Config.require(“testkey”) and it says it’s not set, although I can see it in yaml file. Either it’s quite bugged, or I don’t understand how it should work. Pretty sure it’s bugged. I’ll open an issue.
b
That’s 100% correct it’s not going to run in the python3 intepretor - it needs to run via the Pulumi cli
The code may well be Python syntax but it still needs Pulumi to run it for the engine
g
You're misunderstanding what pulumi is. Pulumi is a CLI Tool and not a standalone python library . Yes it comes together with bunch of python libraries, but these are intended to be run through the pulumi CLI (which underneath invokes python3 for you among other things) and not just a standalone python3 interpreter.
o
oh. OOH! I see. That explains some things that I thought were strange in the code. Too bad, but makes sense. I didn’t get that from the programming model, probably because I came in thinking about how it compares with the CDK. Thank you for clearing that up.
So, if I got it right this time, when an object is created based on Resource class, the init method of the base class calls back to the pulumi binary (RPC call I guess?) with the parameters passed to the Resource class and then the binary goes on to set up the resource in the cloud (or wtv). Unless it depends on some other resource that isn’t created yet. Meanwhile execution of Python continues and moves on to the next resource and so on.
Which means that everything about that resource should be set when the object is created, otherwise things can get weird. So we shouldn’t expect to be able to do things like
Copy code
bucket = s3.Bucket("bktname")
bucket.lifecycle_policy=[]
g
Which means that everything about that resource should be set when the object is created, otherwise things can get weird. So we shouldn’t expect to be able to do things like
That's correct - everything must be set when the object is created. You cannot modify resource arguments like
bucket.lifecycle_policy=[]
.
g
generally speaking your pulumi python code is really just to declare the desired state of resources. When you run the program through the CLI, each resource object instantiation will be translated into an rpc call to the engine (written in go) which creates a plan to get to the desired state and/or executes that plan. I.e. the hard work is being done by the engine, not by your python code. I also recommend you to throughly read through https://www.pulumi.com/docs/intro/concepts/how-pulumi-works/ which explains the high level architecture of pulumi. There also used to be a quite old YouTube video in which Joe (the pulumi ceo) explained the architecture on a whiteboard, but I can't quite find it anymore. Maybe some of the pulumi folks can chime in with a link?
o
Yeap, I read that page again, checked the source code too, I think understand now. I did read that page before, but it didn’t stand out to me that the Python program by itself can’t do anything. Probably because I’m coming from the CDK, which also executes a Python program to create the stack, but there it doesn’t call back as soon as an object is created, it just outputs CFN templates.
Thank you for the explanation, this is an essential piece to understand about Pulumi.
c
This may be the Joe Duffy whiteboard session (2018) mentioned by @glamorous-printer-66548

https://www.youtube.com/watch?v=YMAe59BYzm4

👍 1