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

broad-boots-45639

01/09/2020, 7:19 PM
I'm having a bad time with referencing output from another stack in a k8s configmap as part of a string. The result is that pulumi includes an error in my configmap. How can I pull this off?
the kube config bit:
Copy code
const floating_ips = new pulumi.StackReference(`<org>/floating-ips/stage`);
var ip1 = floating_ips.getOutput("floating_ip1")
var ip2 = floating_ips.getOutput("floating_ip2")

const proxychains = new kubernetes.core.v1.ConfigMap(`${app}-proxychains-config`,
pulumi.output({
  metadata: {
    name: "proxychains-config",
    namespace: "default"
  },
  data: {
    "proxychains.conf": `strict_chain\ntcp_read_time_out 15000\ntcp_connect_time_out 8000\nlocalnet 10.244.0.0/255.255.0.0\nlocalnet 127.0.0.1/255.0.0.0\n[ProxyList]\nsocks4 ${floating_ips.getOutput("floating_ip1")} 1080\nsocks4 ${floating_ips.getOutput("floating_ip2")} 1080\n`
  }
}), {  dependsOn: vars_configmap } );
The configmap sent to k8s is:
Copy code
kind: ConfigMap
metadata:
  annotations:
    <http://kubectl.kubernetes.io/last-applied-configuration|kubectl.kubernetes.io/last-applied-configuration>: |
      {"apiVersion":"v1","data":{"proxychains.conf":"strict_chain\ntcp_read_time_out 15000\ntcp_connect_time_out 8000\nlocalnet 10.244.0.0/255.255.0.0\nlocalnet 127.0.0.1/255.0.0.0\n[ProxyList]\nsocks4 Calling [toString] on an [Output\u003cT\u003e] is not supported.\n\nTo get the value of an Output\u003cT\u003e as an Output\u003cstring\u003e consider either:\n1: o.apply(v =\u003e `prefix${v}suffix`)\n2: pulumi.interpolate `prefix${v}suffix`\n\nSee <https://pulumi.io/help/outputs> for more details.\nThis function may throw in a future version of @pulumi/pulumi. 1080\nsocks4 Calling [toString] on an [Output\u003cT\u003e] is not supported.\n\nTo get the value of an Output\u003cT\u003e as an Output\u003cstring\u003e consider either:\n1: o.apply(v =\u003e `prefix${v}suffix`)\n2: pulumi.interpolate `prefix${v}suffix`\n\nSee <https://pulumi.io/help/outputs> for more details.\nThis function may throw in a future version of @pulumi/pulumi. 1080\n"},"kind":"ConfigMap","metadata":{"labels":{"<http://app.kubernetes.io/managed-by|app.kubernetes.io/managed-by>":"pulumi"},"name":"proxychains-config","namespace":"default"}}
a

astonishing-cartoon-37000

01/09/2020, 7:24 PM
this isn't super direct, but try
getOutputSync
because
getOutput
returns a
pulumi.Output
.It looks like it's pissed because it calls
toString()
behind the scenes, which isn't valid for a
pulumi.Output
. If you use Sync it will return a the underlying value
Might help 🤷
Oh actually I've seen this before you can't use interpolated string literals in with a pulumi output for exactly the reason I stated above. It doesn't have a pulumi
toString()
method. So the two options are either make sure it's a
string
or use the
.apply()
or
pulumi.interpolate
function Example With Snyc)
Copy code
const floating_ips = new pulumi.StackReference(`<org>/floating-ips/stage`);
var ip1 = floating_ips.getOutputSync("floating_ip1") // will return actual value
var ip2 = floating_ips.getOutputSync("floating_ip2") // will return actual value
const proxychains = new kubernetes.core.v1.ConfigMap(`${app}-proxychains-config`,
pulumi.output({
  metadata: {
    name: "proxychains-config",
    namespace: "default"
  },
  data: {
    "proxychains.conf": `strict_chain\ntcp_read_time_out 15000\ntcp_connect_time_out 8000\nlocalnet 10.244.0.0/255.255.0.0\nlocalnet 127.0.0.1/255.0.0.0\n[ProxyList]\nsocks4 ${ip1} 1080\nsocks4 ${ip2} 1080\n`
  }
}), {  dependsOn: vars_configmap } )
b

broad-boots-45639

01/09/2020, 7:31 PM
Thank you Parker! I'm testing that out, I appreciate the explanation.
👍 1
a

astonishing-cartoon-37000

01/09/2020, 7:32 PM
hope it helps! you could maybe get it not using sync too, but I find the sync version meets my needs 99% of the time.
b

broad-boots-45639

01/09/2020, 7:35 PM
Hooray! Thank you so much. I've been beating my head on the keyboard over that for a while.
It worked
b

brave-angle-33257

01/09/2020, 7:41 PM
fyi, getOutputSync is marked as deprecated in 1.6.0 - would be nice to get clarity on the proper way to do this from the devs
1
https://github.com/pulumi/pulumi/blob/master/CHANGELOG.md#160-2019-11-20
Copy code
Compatibility
StackReference.getOutputSync and requireOutputSync are deprecated as they may cause hangs on some combinations of Node and certain OS platforms. StackReference.getOutput and requireOutput should be used instead.
a

astonishing-cartoon-37000

01/09/2020, 7:52 PM
oh nice catch! @brave-angle-33257 that would be nice, because I use Sync a decent bit. Promises can be frustrating at times XD
@broad-boots-45639 ^ gave you deprecated advice 😅. but glad it worked
b

brave-angle-33257

01/09/2020, 7:53 PM
yea, definitely a difficult part of the pulumi world.. i was trying to help Aubrey out and wasn't able to... so it's great there is a workaround but hopefully it wont stop functioning soon!!
😓 1
a

astonishing-cartoon-37000

01/09/2020, 8:00 PM
actually looking at the type I think this might just work
Copy code
/**
     * Data contains the configuration data. Each key must consist of alphanumeric characters,
     * '-', '_' or '.'. Values with non-UTF-8 byte sequences must use the BinaryData field. The
     * keys stored in Data must not overlap with the keys in the BinaryData field, this is
     * enforced during validation process.
     */
    readonly data: pulumi.Output<{
        [key: string]: pulumi.Output<string>;
    }>;
b

brave-angle-33257

01/09/2020, 8:00 PM
interesting! yea seems like there could be a better way to do this somehow.. maybe like a
pulumi.outputStringTemplate()
or something where you pass in the template, and a bunch of keys and values, like a python
format()
or jinja style
a

astonishing-cartoon-37000

01/09/2020, 8:03 PM
also why do you wrap the args as a
pulumi.output
shouldn't need to do that my final take would be this. Without using deprecated
Sync
. Sorry for blowing up Thread.
Copy code
const floating_ips = new pulumi.StackReference(`<org>/floating-ips/stage`)
    const ip1 = floating_ips.getOutput('floating_ip1')
    const ip2 = floating_ips.getOutput('floating_ip1') 

    const proxychains = new kubernetes.core.v1.ConfigMap(
      `${app}-proxychains-config`,
      {
        metadata: {
          name: 'proxychains-config',
          namespace: 'default'
        },
        data: {
          'proxychains.conf': pulumi.interpolate `strict_chain\ntcp_read_time_out 15000\ntcp_connect_time_out 8000\nlocalnet 10.244.0.0/255.255.0.0\nlocalnet 127.0.0.1/255.0.0.0\n[ProxyList]\nsocks4 ${ip1} 1080\nsocks4 ${ip2} 1080\n`
        } //use the newly transformed pulumi.Output
      },
      { dependsOn: vars_configmap }
    )
anyhow, hope that helps!
a

acoustic-florist-12628

01/09/2020, 8:23 PM
if the end goal is to get a string that contains the values of
ip1
and
ip2
(which are pulumi.Output type), isn't it much easier to just use
pulumi.interpolate
...${ip1}......${ip2}...`` ? Is there a reason this isn't an option? Also in the k8s configmap arguments i'm not sure there's a reason to wrap the properties in a pulumi.output() call; it appears there are only strings and pulumi.Outputs involved already, which will work... If I'm reading it all correctly, wouldn't Aubrey's original code snippet work just fine with `"proxychains.conf": pulumi.interpolate `<original content>``?
💯 1
a

astonishing-cartoon-37000

01/09/2020, 8:24 PM
that's even better, and my thing above didn't use both ip1 and ip2 XD, so it wouldn't work. thx brandon
👍 1
updated example above.
5 Views