Does anyone know the best way to run a split or so...
# typescript
g
Does anyone know the best way to run a split or some other function on an output<string>? The below code is not working for me - I am basically just trying to get the first two segments of the cidrblock property of a vpc.
Copy code
const cidrBlockFirstTwoSegments = vpc.cidrBlock.apply((s) =>
  s.split(".").slice(0, 2)
);
c
What exactly isn't working with that snippet?
g
Copy code
aws:ec2:Subnet (net-public-segments-az1-subnet):
    error: aws:ec2/subnet:Subnet resource 'net-public-segments-az1-subnet' has a problem: "Calling [toString] on an [Output<T>] is not supported.\n\nTo get the value of an Output<T> as an Output<string> consider either:\n1: o.apply(v => `prefix${v}suffix`)\n2: pulumi.interpolate `prefix${v}suffix`\n\nSee <https://www.pulumi.com/docs/concepts/inputs-outputs> for more details.\nThis function may throw in a future version of @pulumi/pulumi..Calling [toString] on an [Output<T>] is not supported.\n\nTo get the value of an Output<T> as an Output<string> consider either:\n1: o.apply(v => `prefix${v}suffix`)\n2: pulumi.interpolate `prefix${v}suffix`\n\nSee <https://www.pulumi.com/docs/concepts/inputs-outputs> for more details.\nThis function may throw in a future version of @pulumi/pulumi..11.0/24" is not a valid CIDR block: invalid CIDR address: 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://www.pulumi.com/docs/concepts/inputs-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://www.pulumi.com/docs/concepts/inputs-outputs> for more details.
    This function may throw in a future version of @pulumi/pulumi..11.0/24. Examine values at 'net-public-segments-az1-subnet.cidrBlock'.
I am trying to get the cidrBlock from the vpc and then use it when creating a subnet:
Copy code
cidrBlock: `${cidrBlockFirstTwoSegments[0]}.${cidrBlockFirstTwoSegments[1]}.11.0/24`
c
Change this:
Copy code
cidrBlock: `${cidrBlockFirstTwoSegments[0]}.${cidrBlockFirstTwoSegments[1]}.11.0/24`
...to this:
Copy code
// Make sure you've imported `@pulumi/pulumi` into the file so that you can use the interpolate function.
cidrBlock: pulumi.interpolate `${cidrBlockFirstTwoSegments[0]}.${cidrBlockFirstTwoSegments[1]}.11.0/24`