Question , how do I convert an `Output<string&g...
# general
c
Question , how do I convert an
Output<string>
to
string
? One of the function returns an
Output<string>
and the other one expects a
string
.
@gentle-diamond-70147 @gorgeous-egg-16927 Would you guys be able to answer this?
g
Depending on where you're needing to do this
.apply(x=>x)
might be the best option or my favorite
pulumi.interpolate...
.
c
I want to convert an
Output<string>
to
Input<string>
I don’t see an example
Copy code
export async function createAliasRecord(
  targetDomain: string,
  loadBalancername: Output<string>
): Promise<aws.route53.Record> {
  const domainParts = getDomainAndSubdomain(targetDomain);
  const hostedZone = await aws.route53.getZone({
    name: domainParts.parentDomain
  });

  return new aws.route53.Record(targetDomain, {
    name: domainParts.subdomain,
    zoneId: hostedZone.zoneId,
    type: "A",
    aliases: [
      {
        name: loadBalancername,
        zoneId: getHostedZoneId().then(s => s.id),
        evaluateTargetHealth: true
      }
    ]
  });
}
In the above example I would like to pass
loadBalancername
to
aliases
name
the
name
requires
Input<string>
g
Does that not run? IIRC, you can pass
Output<string>
into places requiring an
Input<String>
c
I get an error
Copy code
Diagnostics:
  aws:route53:Record (<http://xyz.xyz.io|xyz.xyz.io>):
    error: aws:route53/record:Record resource '<http://xyz.xyz.io|xyz.xyz.io>' has a problem: "alias.0.name": required field is not set
If I hardcode the string it works.
But that’s not what I want.
g
how are you calling the function
createAliasRecord(...)
?
g
What if you do
loadBalancername.get()
?
o
Is pulumi.io running in Azure? 🙂
c
I am calling
createAliasRecord(<http://config.xyz|config.xyz>, xyz);
I cannot do a
get
because it errors
Copy code
error: Error: Cannot call '.get' during update or preview.
    To manipulate the value of this Output, use '.apply' instead.
g
what is
xyz
in
createAliasRecord(<http://config.xyz|config.xyz>, xyz);
?
g
Sorry, I'm still learning myself. I see this in the library code:
Copy code
/**
 * Input is a property input for a resource.  It may be a promptly available T, a promise
 * for one, or the output from a existing Resource.
 */
export declare type Input<T> = T | Promise<T> | Output<T>;
g
@orange-tailor-85423 I'm pretty sure it's on AWS?
o
ok - took a while to load and Azure is having issues. Just wondering 🙂
c
xyz
is
Output<String>
g
so something like
const xyz = loadbalancer.name;
is further up in your code?
c
My mistake i had the
ip
instead of
name
which was causing the issue.
The error message wasn’t clear. Thanks guys