Hi folks, I am trying to get something done with P...
# getting-started
c
Hi folks, I am trying to get something done with Pulumi and I’m not even sure it’s possible after checking all examples. Basically, what I need to achieve is the following: 1. create some resources 2. (do some other testing with python) 3. modify those resources 4. (do some other testing) 5. and so forth 6. finally, destroy the thing. I figured the automation API is the way to go, but it insists on receiving a static program rather than (what I would have liked to) an ‘open-ended’ stack that will get updated as I modify objects.
e
Automation api would be the way to go. You should be able to feed config into the program to change what the program does each time.
c
I’m trying to do this as wieldy as possible and it’s not fun working like that. I could use control logic (e.g. if step == this_step:) or try to instantiate resources from a global variable (having some issues with that), but both have annoying limitations
e
I think automation api should be fine with global variables for inline programs. They do just run in the same process space.
c
I have failed to instantiate resources from a global array or dict. If you could help me with that, that would be wonderful
e
Can you run a simple version of the program just making one resource?
c
yeah, that works. also control logic works. it’s just so unwieldy to write programs like that. I wish I could just declare resources as I go and have pulumi do the right thing
instead of writing something like: res = resource stack.up res2 = resource2 stack.up I need to write something like: def program res = resource if flag = 2: res2 = resource2 stack.up flag = 2 stack.up
if I could write something like this (note, this doesn’t work), it would also be fine: def program: locals().update(resource_dictionary) resource_dictionary[“res”] = resource stack.up resource_dictionary[“res2"] = resource2 stack.up
e
you could kinda do that if it's the same resources each time, something like: resArgs = args1 stack.up resArgs = args2 stack.up and just have the program be something like: def program(): res = Resource("name", args=resArgs)
c
but I want to keep the previous resources
that’s why I wanted the dictionary
e
I mean in general you can do something like: d = {} d["name] = (Resource, ResourceArgs(...)) def program(): for key in d: ctor, args = d[key] ctor(key, args=args)
c
okay! that seems like the syntax I was missing. going to give that a shot
nope, not working. can you maybe give me a concretization with something simple like an aws s3 bucket? maybe i’m not picking up the invocation syntax
e
Copy code
from pulumi_aws import s3

d = {}
d["test"] = (s3.Bucket, s3.BucketArgs(tags={"myTag": "example"}))

for key in d:
    ctor, args = d[key]
    ctor(key, args)
c
okay! I was off on the argument types. gotcha 🙂
wonderful. thank you oh so much.