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

abundant-window-12532

03/07/2022, 11:45 AM
I've just added ElastiCache to my stack, but I'm having problems getting the address from the output using Typescript, has anyone been able to implement this successfully. I'm trying with the same approach I've done for RDS, but keep getting
Copy code
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://pulumi.io/help/outputs> for more details. This function may throw in a future version of @pulumi/pulumi.
Rather than the expected value
e

echoing-dinner-19531

03/07/2022, 12:01 PM
Have you got some example code of what exactly your trying to do?
a

abundant-window-12532

03/07/2022, 12:09 PM
@echoing-dinner-19531
Copy code
export async function manageRedisCache(config) {
  try {
    const subnetGroup = new aws.elasticache.SubnetGroup(config.name, {
      name: config.name,
      subnetIds: config.subnetIds,
      description: `Subnet group for ${config.name} Cache Cluster`,
      tags: {
        Name: config.name,
      },
    });
    const redisInstance = await new aws.elasticache.Cluster(config.name, {
      engine: "redis",
      nodeType: config.size,
      numCacheNodes: 1,
      subnetGroupName: subnetGroup.name,
      securityGroupIds: config.securityGroupIds,
      securityGroupNames: config.securityGroupNames,
      tags: {
        Name: config.name,
      },
    });
    return {
      instance: redisInstance,
      data: {
        address: redisInstance.clusterAddress.apply((v) => v),
        port: redisInstance.port.apply((v) => v) as unknown as string,
      },
    };
  } catch (e) {
    throw e;
  }
}

I'm then passing the value from the function into a function to create my Fargate services
I've tried using the apply, both at source, when creating the resource, as well as on the function readying the values.
e

echoing-dinner-19531

03/07/2022, 12:15 PM
Ah right, yes once values are "Outputs" they need to stay Outputs. There is no way to go from
Output<string>
to just
string
except via resources (and they will just return more outputs)
a

abundant-window-12532

03/07/2022, 12:15 PM
The instance is being created fine, I'm having a problem reading the values for the output
e

echoing-dinner-19531

03/07/2022, 12:15 PM
Change your "data.address" and "data.port" to be
Output<string>
b

billowy-army-68599

03/07/2022, 4:51 PM
@abundant-window-12532 redis elasticache instances don't return a
clusterAddress
, only memcached based ones. You need
redisInstance.cacheNodes[0].address
which is an array You don't need to do an
apply
if you're just returning an
Output
example: https://github.com/jaxxstorm/brig.gs/blob/main/index.ts#L55
a

abundant-window-12532

03/08/2022, 2:37 PM
@billowy-army-68599 thanks for that, helped. I'm also seeing vpc under awsx, which has much more functionality that in aws
3 Views