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

early-musician-41645

10/03/2019, 10:04 PM
I know this has come up a lot, but I'm just not seeing the problem:
Copy code
const zone = aws.route53.Zone.get("external-dns", ingress.externalDnsHostedZoneId);
      let domain: string = zone.name.apply(z => z.replace(/\.$/, ''));
      let zoneId: string = zone.zoneId.apply(z => z);
leads to:
error TS2322: Type 'Output<string>' is not assignable to type 'string'.
Any tips? How do I cast
Output<string>
to
string
?
I need to do some string operations like building a json IAM policy and set values for a helm chart
c

cool-egg-852

10/03/2019, 10:06 PM
Change
string
to
Output<string>
.
I think that’s the easiest way to solve it
Though I’m not sure, because whenever I run into this, it takes me a while to figure it out.
I think the other option is to
Copy code
pulumi.interpolate`${zone.name.replace(...)}`
w

white-balloon-205

10/03/2019, 10:08 PM
How do I cast
Output<string>
to
string
?
You unfortunately do not. An
Output<string>
is a value which may not have a string available yet (it may not until the resource gets created). So you need to use
.apply
on it - and within that callback you pass to apply you will get passed the actual string value (when it's available) and can transform it into some other value. But you then need to pass the resulting
Ouput<somethingelse>
to something else that accepts an
Output
. There is a fair bit of content on this topic at https://www.pulumi.com/docs/intro/concepts/programming-model/#outputs.
let zoneId: string = zone.zoneId.apply(z => z);
What does the code look like that is trying to use
zoneId
? The solution here is to change that code.
e

early-musician-41645

10/03/2019, 10:11 PM
here's an example:
Copy code
private getRolePolicy(zoneId: string) {
    return JSON.stringify({
      Version: "2012-10-17",
      Statement: [
        {
          Effect: "Allow",
          Action: [
            "route53:ChangeResourceRecordSets"
          ],
          Resource: [
            `arn:aws:route53:::hostedzone/${zoneId}`
          ]
        },
        {
          Effect: "Allow",
          Action: [
            "route53:ListHostedZones",
            "route53:ListResourceRecordSets"
          ],
          Resource: [
            "*"
          ]
        }
      ]
    });
  }
I need to get that policy JSON back as a string for create an IAM role policy
To work around this (or with it?) I just wrapped everything in a
pulumi.all([...]).apply({...});