This message was deleted.
# general
s
This message was deleted.
l
Set the "name" property of the resource. When Pulumi names something, it adds that random string to avoid collisions. If you can manage that yourself, then you can set the name property.
m
I set the name "foo" myself.
l
Do you mean in the 1st parameter of the constructor? That's not the property of the resource. The property is in the 2nd parameter.
So you need something like
Copy code
new Function("foo", { name: "foo"});
Or whatever syntax applies to your chosen language.
m
It does not compile,
TypeError: Function._internal_init() got multiple values for argument 'opts'.
l
I don't know what language you're working in. I provided pseudocode, you'll need to translate.
m
Code to re-create example:
Copy code
from pulumi_gcp.cloudfunctions import Function

Function(name, {"name": name},  
runtime=runtime,  
region=region,  
source_archive_bucket=source_bucket.name,  
source_archive_object=bucket_archive.name,  
entry_point="foo",  
trigger_http=True,  
opts=opts  )  
invoker = FunctionIamMember(f"{name}-invoker",  
project=function.project,  
region=function.region,  
cloud_function=function.name,  
role=role,  
member="allUsers")  
export(f'lambda-{name}-url', function.https_trigger_url)
l
Ok, you need to remove
{"name": name},
as the 2nd parameter, and add
name=name,
to the correct existing 2nd parametter.
Everything except the 1st parameter (logical name) and last parameter (opts) are the properties. You need to add the name property.
m
Indeed that works. Thanks for the quick help.
l
Don't do it unless you really need to. It always breaks something. The random naming is there for a very good reason; unless you have a better one (e.g. you need a well-known name for a Function so that other things can call it), then you shouldn't change the name of a resource.
m
On GCP, apigw needs a config file in swagger that points to the cloud function url. The swagger file is static so I need to the url to be deterministic. On AWS, this is much cleaner, I can simply pass
lambda.url
and not worry about any of this mess.
l
You can do that in Pulumi too. The ARN, URL, generated name, etc. are all available to other resources.
As you get more familiar with the ways to get the values where you need to, this will become easier
m
I generate the config file at
pulumi update
. The challenge is converting the Output<T> to str. I thought this is not possible because Output<T> means the value will be known in future?
l
Yes, but "future" is before the program finishes. So you can output it at program end time. And you can pass it to any other Pulumi resource: resources know how to handle Outputs. This is what I meant when I said "as you get more familiar with the ways to get the values". This is all doable.
m
The config file is static, I meant it needs to be known at plan stage while Output<T> is known at apply stage so it has to be hardcoded (i hate it but GCP designed it that way). On AWS this is not a problem because they don't require a static file (the lambda can be passed as a variable).
l
Ah. Well you can still do it: for example, you can use automation-api to wrap two Pulumi projects: one creates the Function, and one builds whatever resources need the Function name. You can get the Function name as a stack references into the 2nd project.
There are probably other ways to do it, too.
m
I see. I will take a look at automation api thanks.
l
That's a more advanced topic: get what you are currently working on working. Then improve it later.
❤️ 1