I'm struggling with handing outputs, I have `const...
# general
t
I'm struggling with handing outputs, I have
const proj = new gitlab.Project(...)
and I want to get
proj.id
to use in a string literal (typescript). The documentation seems to be indicating that I can do this: `console.log(proj.id.apply(v =>
${v}
));` however it doesn't like it
b
Outputs work like promises. So the following code:
Output<string>.apply(v => "${v}");
would return
Output<string>
The same way that:
Promise<string>.then(v => $"{v}");
returns
Promise<string>
If you need to interpolate it into a string literal, then your literal needs to be part of the promise:
var result = proj.id.apply(id => "My project ID is ${id}");
now
result
is
Output<string>
and your
proj.id
has been interpolated and can be passed to an
Input<string>
t
Ah, I want to be able to use the string as part of the name of a future task
Copy code
new gitlab.BranchProtection(`BranchProtection(${proj.id}:${project.defaultBranch})`, {...})
and the names don't take
Input<string>
b
you cannot do that
nor should you
t
How should I name these then? I have ~ 50 git repos being configured with pulumi, for each of those there may be ~2/3 branches that need configuring, the project ID and branch name was a way to give these a unique identifier
b
well you know what the branch is and you have a name that you already provided to
gitlab.Project
, so why not
{projectName}-branchprotection-{branchName}
t
Project names aren't guaranteed to be unique, a project ID is
Actually, I do have a unique name for it since i use a name for
new gitlab.Project()
b
a pulumi name must be unique for a given stack, so how could the name you provided to
new gitlab.Project(name, ...)
not be unique?
t
Hmm, okay i'll do that, thanks
b
yea, that's what I was getting at
t
Is there a way to make it only run the
delete
or to at least run them first?
Currently its failing a lot of the create steps
b
so by default for a
replace
action pulumi does
create new, delete old
but for some types of resources that have unique constraints that default behavior doesn't work so you set
deleteBeforeReplace: true
in the resource options which makes a
replace
action do
delete current, create new
There are scenarios where it may be dangerous to set that so the default is what it is for a reason. But for instance like a pulumi controlled DNS record or something needs to be deleted first before the new one can be created since there can only be 1 with a certain value
You might need to do a
destroy
first though since you are actually changing the pulumi names of theses resources so pulumi no longer sees them as the same entity and thus is doing the create and destroy separately
Or if you can't do a full destroy because you don't want to destroy other resources, you would comment out the resources whose names you are changing and then run a
pulumi up
so that it deletes them first since they are no longer declared - then uncomment them with the new names
Or alternatively, you could use pulumi aliases and make the old name an alias and it wouldn't need to recreate them at all
t
I ended up going with commenting out. But aliases are a good one to know, do they accept Input<String> as a value, otherwise i'd have the same problem correct?
b
I believe they do but I don't think that would do anything for you
it's just a pulumi name, so the only reason you would use them is if the old pulumi name needed to be changed - so it doesn't really make sense to make aliases pre-emptively IMO they would have no function