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

gorgeous-pillow-13604

12/01/2023, 2:55 PM
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

clever-sunset-76585

12/01/2023, 3:42 PM
What exactly isn't working with that snippet?
g

gorgeous-pillow-13604

12/01/2023, 3:43 PM
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

clever-sunset-76585

12/01/2023, 8:44 PM
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`