How do I convert an output to an input. I need to...
# typescript
o
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
`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
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
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
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
Where are you trying to use it?
o
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
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
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
for me . apply worked when trying to use output IP of server and save it as API_URL in rancher.
119 Views