Hi, I'm pretty new with pulumi trying to figure ou...
# general
r
Hi, I'm pretty new with pulumi trying to figure out few things, especially with reading outputs of one resource and re-using them in another. I have deployed rancher2.Cluster resource and trying to read its outputs and passing it to rancher2.AppV2
Copy code
rancher_ci_cluster = rancher2.Cluster()

chart = rancher2.AppV2("cluster-autoscaler",
    cluster_id=rancher_ci_cluster.id,
    namespace="kube-system",
    repo_name=catalog.name.apply(lambda name: name),
    chart_name="cluster-autoscaler",
    chart_version="9.10.7",
    values=f"""
awsRegion: {config.require("rancherAwsCiRegion")}
autoDiscovery:
  clusterName: {rancher_ci_cluster.name.apply(lambda name: name)}
extraArgs:
  balance-similar-node-groups: true
priorityClassName: system-cluster-critical
""",
    opts=ResourceOptions(depends_on=catalog)
    )
so in the above snippet i could read the rancher_ci_cluster.id without any apply() or all() . but for looking up name even though i used
rancher_ci_cluster.name.apply(lambda name: name)
i still see it as an object instead of raw data
<pulumi.output.Output object at 0x103a73e20>
. so can anyone help me understand what is that im missing here and how the behavior works?
s
Not an answer to your question but just FYI
something.property.apply(lambda name: name)
is equivalent to
something.property
. The lambda function is just the identity function so no transformation is performed.
1
looks like you need
Copy code
clusterName: rancher_ci_cluster.name
you are wrapping it in a
{}
but it looks like that property probably just wants a
string
r
yeah just want a string but in an yaml format and i'm passing the value dynamically from previous resource
s
ohh right. does Pulumi Python have the
interpolate
function?
doing string interpolation with an
Output<string>
doesn't work
r
oh so need to use
all()
and
apply()
together?
s
yeah i think soemthing like this will work. might be an even better way to format it but i forget if python supports array param deconstruction
Copy code
values=Output.all(config.require("rancherAwsCiRegion"), rancher_ci_cluster.name).apply(lambda s: f"""
awsRegion: {s[0]}
autoDiscovery:
  clusterName: {s[1]}
extraArgs:
  balance-similar-node-groups: true
priorityClassName: system-cluster-critical
""",
🙌 1
r
let me try it out.
👍 1
s
might have to make that function a named function if python doesn't allow it for being multi-line
r
it might fail having
config
(as this is
pulumi.Config
) in
Output
as its not a resource
s
Output.all
just takes Outputs. it doesn't need to be from a cloud resource
r
perfect , thanks for help. appreciate it 👏
it worked like charm
p 1
on side note you mentioned this is
catalog.name.apply(lambda name: name)
same as
catalog.name
right, but
catalog.name
was returning object, after using
apply()
only it returned raw output, any thoughts on it? btw the catalog here is
rancher2.CatalogV2
resource
s
A Pulumi
Output<string>
is an object. It is not the same as a
string
. So you can't use it in normal string interpolation. The reason why you got an object reference earlier is because you used it python's string interpolation, and the string value of an object is that string you got with the memory address. What
apply
does is it allows you to access the value wrapped by
Output
. Within the callback function, you can treat an
Output<string>
as a normal string. This allows you to use
s[0]
and
s[1]
in the code block above as regular strings.
catalog.name.apply(lambda name: name)
is the same as
catalog.name
because the callback function you passed in is the identity function, not for any other reason.
r
understood, thanks for sharing out in detail. this helps.
👍 1