https://pulumi.com logo
#typescript
Title
# typescript
o

orange-kite-80991

11/21/2021, 7:35 AM
How do I convert an output to an input. I need to create an A-Record using the IP address of my postgresql LoadBalancer. I can acquire the LB-IP but Pulumi complains that 'Output<string>' is not assignable to type 'Input<Input<string>[]>'. The LB-IP values comes from postgresqlChart.getResource("v1/Service", "postgresql").status.loadBalancer.ingress[0].ip
s

sparse-student-54516

11/21/2021, 7:47 AM
`const apiUrl = floatingIp.ipAddress.apply((ip) => `<https://$%7Bip%7D/%60|https://${ip}/`>);`
I do it like this
floatingIp is output. I get its IP address and use
.apply ((<anyname>) => anyname;
o

orange-kite-80991

11/21/2021, 8:01 AM
I was hopeful but it didn't work. Maybe I've misplaced my modifiers? Here's what I tried.
Copy code
const frontendIp = frontend.status.loadBalancer.ingress[0].apply((ip) => `${ip}`)
That line is accepted but the result is still an Output<string>. When I go to use it I still get
Copy code
'Output<string>' is not assignable to type 'Input<Input<string>[]>'
m

miniature-king-36473

11/21/2021, 11:10 AM
Outputs are generally assignable to Inputs. The issue here is that you need an array of Input<string>. You should be able to do
[frontendIp]
when you use it
m

magnificent-lifeguard-15082

11/21/2021, 11:26 AM
It looks like you're just trying to pass in a string where it expects a list of strings? I've found output->input "just works" but here your types are not matching up. As Mark said, [frontendIp] should work.
w

wonderful-twilight-70958

11/21/2021, 12:07 PM
Where are you trying to use it?
o

orange-kite-80991

11/21/2021, 5:11 PM
Progress. Yes, changing to [frontendIp] changed the error from Output-Input to "The provided ip address 'undefined' is not valid." Unfortunately I can't see the value in console logs because Pulumi identifies the ip value as [secret].
l

little-cartoon-10569

11/21/2021, 8:11 PM
You cannot convert an Output to a string ever; code like
.apply ((<anyname>) => anyname;
and `frontend.status.loadBalancer.ingress[0].apply((ip) =>
${ip}
)` doesn't change anything. Can you paste your current code (maybe using the text snippet tool?
If your code is seeing undefined for a value that you know isn't undefined, it may be related to using an Output as a string, or something like that.
o

orange-kite-80991

11/21/2021, 8:31 PM
My overall goal is to use the IP address from my Helm deployed Postgresql service to create an A-Record in my *.myParent.com DNS record. Post deploy, I can see the IP in the Kubernetes Service as (yaml) status:   loadBalancer:       ingress:           - ip: 1.2.3.4 My source code (that isn't working) is below. The goal is setting up the last line:
Copy code
records: [frontendIp]
Copy code
const postgresqlChart = new k8s.helm.v3.Chart(
 'postgresql',
 {
  chart: 'postgresql',
  version: '10.5.0',
  namespace: namespace.metadata.name,
  fetchOpts: { repo: '<https://charts.bitnami.com/bitnami/>' },
  values: {
   postgresqlPostgresPassword: rootPassword,
   postgresqlDatabase: key,
   postgresqlUsername: key,
   postgresqlPassword: password,
   service: {
    type: 'LoadBalancer',
    annotations: {
     '<http://external-dns.alpha.kubernetes.io/hostname|external-dns.alpha.kubernetes.io/hostname>': desiredFQDN,
    },
   },
   metrics: {
    enabled: true,
   },
  },
 },
 { provider: infra.provider },
)

// Export the IP
const frontend = postgresqlChart.getResource("v1/Service", "postgresql");
const frontendIp = frontend.status.loadBalancer.ingress[0].ip

const aRecord = new azure.dns.ARecord( desiredHostname,
  name: desiredHostname,
  zoneName: dnsRootDomain,
  resourceGroupName: dnsRootResourceGroup,
  ttl: 30,
  records: [frontendIp],
})
I have verified that Pulumi can find the ip field. If I put a typo in the path, I get an error.
s

sparse-student-54516

11/22/2021, 3:38 AM
for me . apply worked when trying to use output IP of server and save it as API_URL in rancher.
46 Views