I for the life of me can't figure out how Pulumi w...
# getting-started
g
I for the life of me can't figure out how Pulumi wants me to convert this output... Error:
Copy code
snaptshotRedirectCnames not empty!
    ######################
    Calling [toString] on an [Output<T>] is not supported.
    To get the value of an Output<T> as an Output<string> consider either:
    1: o.apply(v => `prefix${v}suffix`)
    2: pulumi.interpolate `prefix${v}suffix`
    See <https://pulumi.io/help/outputs> for more details.
    This function may throw in a future version of @pulumi/pulumi.
    ######################
    ######################
    Calling [toString] on an [Output<T>] is not supported.
    To get the value of an Output<T> as an Output<string> consider either:
    1: o.apply(v => `prefix${v}suffix`)
    2: pulumi.interpolate `prefix${v}suffix`
    See <https://pulumi.io/help/outputs> for more details.
    This function may throw in a future version of @pulumi/pulumi..Calling [toString] on an [Output<T>] is not supported.
    To get the value of an Output<T> as an Output<string> consider either:
    1: o.apply(v => `prefix${v}suffix`)
    2: pulumi.interpolate `prefix${v}suffix`
    See <https://pulumi.io/help/outputs> for more details.
    This function may throw in a future version of @pulumi/pulumi.
    ######################
Function
Copy code
export function snapshotRediretionCnames(subDomains: string[]) {
  const cnames: string[] = []
  subDomains.forEach(function (subDomain) {
    // Does subdomain have -v ?
    if (subDomain.indexOf('-v') > -1) {
      // Does it exist in cnames?
      if (cnames.length > 0) {
        let networkInCnames = false
        let cnameToReplace = ''
        cnames.forEach(function (cname) {
          const subDomainNetwork = subDomain.split('-v')[0]
          if (cname.indexOf(subDomainNetwork) > -1) {
            networkInCnames = true
            cnameToReplace = cname
          }
        })
        // If network is in cname
        if (networkInCnames) {
          // Does is the version higher than what exists?
          const subDomainVersion = subDomain.replace(/[^0-9]/g, '')
          const cnameVersion = cnameToReplace.replace(/[^0-9]/g, '')
          if (subDomainVersion < cnameVersion) {
            // If the subDomain is newer than the cname we're replacing it
            const index = cnames.indexOf(cnameToReplace)
            if (index !== -1) {
              cnames[index] = subDomain
            }
          }
        } else {
          cnames.push(subDomain)
        }

      } else {
        cnames.push(subDomain)
      }
    }
  })
  return pulumi.interpolate`${cnames}`
}
Caller:
Copy code
const allSubdomains = shotsDeployments.map((s) => s.subdomain!)
shotsDeployments.forEach(
  (shot) =>
    new TezosShotsDeployment(
      { ...shot, allSubdomains },
      { provider: cluster.provider }
    )
)

const snapshotRedirectionCnames = snapshotRediretionCnames(allSubdomains)
if(snapshotRedirectionCnames){
  snapshotRedirectionCnames.apply(cnames=>{
    cnames.split("\n").forEach(function(cname){
      const output = pulumi.interpolate`${cname}`
      console.log(`snaptshotRedirectCnames not empty!`)
      console.log(`######################`)
      console.log(`${snapshotRedirectionCnames}`)
      console.log(`######################`)
      const network = output.apply(cname => pulumi.interpolate`${cname.split('-v')[0]}`)
      console.log(`######################`)
      console.log(`${network}.${xtzshotsZone.name}`)
      console.log(`######################`)
    })
  })
}
I've tried every combination of
pulumi.interpolate
and
output.apply
that I can think of, but I can't seem to get this object parsed from an Output<T> to a string. If someone could take a look and let me know what I could be doing wrong, that would be most appreciated. 😄
e
Your trying to console.log the output values, you want to take the Output<T> call apply and do the console.log inside the apply so that it can see the actual string value. That should help your debugging
g
Thanks for the reply. I am pretty sure I have it inside the apply.
Copy code
snapshotRedirectionCnames.apply(cnames=>{
    cnames.split("\n").forEach(function(cname){
      const output = pulumi.interpolate`${cname}`
      console.log(`snaptshotRedirectCnames not empty!`)
      console.log(`######################`)
      console.log(`${snapshotRedirectionCnames}`)
      console.log(`######################`)
      const network = output.apply(cname => pulumi.interpolate`${cname.split('-v')[0]}`)
      console.log(`######################`)
      console.log(`${network}.${xtzshotsZone.name}`)
      console.log(`######################`)
    })
  })
Even if I change
Copy code
const network = output.apply(cname => pulumi.interpolate`${cname.split('-v')[0]}`)
to...
Copy code
const network = output.apply(cname => cname.split('-v')[0])
Same error 😢
e
I meant things like:
Copy code
const network = output.apply(cname => pulumi.interpolate`${cname.split('-v')[0]}`)
      console.log(`######################`)
      console.log(`${network}.${xtzshotsZone.name}`)
network there is an Output<T> so the console.log isn't going to be able to print it
g
Copy code
network.apply(v=>console.log(`${v}.${xtzshotsZone.name}`))
Gives me same error
Actually...
Copy code
const snapshotRedirectionCnames = snapshotRediretionCnames(allSubdomains)
if(snapshotRedirectionCnames){
  snapshotRedirectionCnames.apply(cnames=>{
    cnames.split("\n").forEach(function(cname){
      const output = pulumi.interpolate`${cname}`
      const network = output.apply(cname => pulumi.interpolate`${cname.split('-v')[0]}`)
      console.log(`######################`)
      network.apply(v=>console.log(`${v}.${xtzshotsZone.name}`))
      console.log(`######################`)
    })
  })
}
Is empty and it looks like the next iteration is erroring
Copy code
######################
    ######################
    mainnet.Calling [toString] on an [Output<T>] is not supported.
    To get the value of an Output<T> as an Output<string> consider either:
    1: o.apply(v => `prefix${v}suffix`)
    2: pulumi.interpolate `prefix${v}suffix`
    See <https://pulumi.io/help/outputs> for more details.
    This function may throw in a future version of @pulumi/pulumi.
ok i might have it