https://pulumi.com logo
#general
Title
# general
r

rhythmic-rain-31941

09/29/2021, 11:37 PM
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

steep-toddler-94095

09/29/2021, 11:45 PM
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

rhythmic-rain-31941

09/29/2021, 11:50 PM
yeah just want a string but in an yaml format and i'm passing the value dynamically from previous resource
s

steep-toddler-94095

09/29/2021, 11:50 PM
ohh right. does Pulumi Python have the
interpolate
function?
doing string interpolation with an
Output<string>
doesn't work
r

rhythmic-rain-31941

09/29/2021, 11:53 PM
oh so need to use
all()
and
apply()
together?
s

steep-toddler-94095

09/29/2021, 11:55 PM
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

rhythmic-rain-31941

09/29/2021, 11:56 PM
let me try it out.
👍 1
s

steep-toddler-94095

09/30/2021, 12:03 AM
might have to make that function a named function if python doesn't allow it for being multi-line
r

rhythmic-rain-31941

09/30/2021, 12:04 AM
it might fail having
config
(as this is
pulumi.Config
) in
Output
as its not a resource
s

steep-toddler-94095

09/30/2021, 12:10 AM
Output.all
just takes Outputs. it doesn't need to be from a cloud resource
r

rhythmic-rain-31941

09/30/2021, 12:17 AM
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

steep-toddler-94095

09/30/2021, 12:27 AM
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

rhythmic-rain-31941

09/30/2021, 2:32 AM
understood, thanks for sharing out in detail. this helps.
👍 1
4 Views