A random string is added at the end of my google c...
# general
A random string is added at the end of my google cloud function name eg: "foo-38d9875". Do you know how to avoid that i.e. the cloud function should be called exactly as the name it is given "foo"? When making a cloud function on the console, this does not happen. Happens through Pulumi. Thanks.
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.
I set the name "foo" myself.
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.
It does not compile,
TypeError: Function._internal_init() got multiple values for argument 'opts'.
I don't know what language you're working in. I provided pseudocode, you'll need to translate.
Code to re-create example:
Copy code
from pulumi_gcp.cloudfunctions import Function

Function(name, {"name": name},  
opts=opts  )  
invoker = FunctionIamMember(f"{name}-invoker",  
export(f'lambda-{name}-url', function.https_trigger_url)
Ok, you need to remove
{"name": name},
as the 2nd parameter, and add
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.
Indeed that works. Thanks for the quick help.
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.
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
and not worry about any of this mess.
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
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?
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.
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).
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.
I see. I will take a look at automation api thanks.
That's a more advanced topic: get what you are currently working on working. Then improve it later.