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

sparse-state-34229

05/30/2020, 7:33 PM
it would be nice to see a “outputs best practices” document. with all the recent chatter about this i’m guessing this is (hopefully!) on their radar
b

bland-lamp-16797

05/30/2020, 7:33 PM
yeah, it would be good indeed....
I ended up with this code... It's not python anymore 😞
s

sparse-state-34229

05/30/2020, 7:34 PM
you might be able to use
Output.all()
there
would make it only one apply call
b

bland-lamp-16797

05/30/2020, 7:35 PM
it is only 1 apply just in that apply it has 2 internal function... but yes, I get your point
I might put this 2 functions somewhere else and assign global variable to it
s

stocky-spoon-28903

05/31/2020, 5:21 AM
You can also do this outside the resource definition which likely lead to cleaner code
☝️ 1
f

future-barista-68134

06/01/2020, 3:06 PM
We recently put together a short video on inputs and outputs:

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

b

bland-lamp-16797

06/03/2020, 4:54 PM
@stocky-spoon-28903 that did not work for me... the string was
<http://foo>.<Output
and it worked only when I put it in resource... I was getting errors from GCP for invalid strings 😞
s

stocky-spoon-28903

06/03/2020, 4:56 PM
@bland-lamp-16797 can you paste that line? This sounds like a slightly different variant of what I meant!
b

bland-lamp-16797

06/03/2020, 4:57 PM
hmmm, ex: this works
Copy code
gcp_bucket_admin = gcp_storage.Bucket(
    resource_name='admin-b81-react-web',
    name=top_domain.apply(lambda c: str(f"admin.{env_name}.{c}")),
this does not:
Copy code
somevar = top_domain.apply(lambda c: str(f"admin.{env_name}.{c}")), 
gcp_bucket_admin = gcp_storage.Bucket(
    resource_name='admin-b81-react-web',
    name= somevar,
right now, whole definition looks like this
Copy code
gcp_bucket_admin = gcp_storage.Bucket(
    resource_name='admin-b81-react-web',
    name=top_domain.apply(lambda c: str(f"admin.{env_name}.{c}")),
    location="EUROPE-WEST3",  # EU
    force_destroy=True,
    bucket_policy_only=True,
    website={
        "mainPageSuffix": 'index.html',
        "notFoundPage": "404.html"
    },
    cors=[{
        "origin": [top_domain.apply(
            lambda c: str(f"<http://admin>.{env_name}.{c}"))],
        "method": ["GET", "HEAD", "PUT", "POST", "DELETE"],
        "response_header": ["*"],
        "max_age_seconds": 3600,
    }],
    project=get_project_id_by_env(env_name)
   )
s

stocky-spoon-28903

06/03/2020, 6:17 PM
I’ll take a look when I can put it on a bigger screen, phones are not kind to python code!