Hello folks, I need some advice on the right way t...
# typescript
Hello folks, I need some advice on the right way to use Pulumi
My scenario is as follows: 1. I have a base infrastructure project where I have created some common AWS resources like VPC, RDS, Fargate cluster etc. Resource creation is working fine in this base project. The fargate cluster is created like this
Copy code
// Create new fargate cluster for running containers
export const fargateCluster = new awsx.ecs.Cluster(
    vpc: vpc,
    securityGroups: [fargateSecurityGroup],
2. Now i want to import this Fargate cluster in another Pulumi project so that I can create new Fargate services and task definitions on top this common cluster. I'm doing this to accomplish that
Copy code
// Get resources from infra-base
const baseInfra = new pulumi.StackReference(

// Get fargate cluster from base infra
const fargateCluster = baseInfra.getOutput("fargateCluster");

// Define the fargate service and task definitions
const service = new awsx.ecs.FargateService(`blah blah`, {
  cluster: (fargateCluster as unknown as awsx.ecs.Cluster) || undefined,
  name: `blah blah`,
  desiredCount: 1,
  taskDefinitionArgs: { ... },
When i try to do
pulumi up
I get this error
Copy code
TypeError: this.cluster.autoScalingGroups.map is not a function
        at new Service (/Users/amal/rasa/tooling/infra-app/node_modules/@pulumi/ecs/service.ts:60:55)
        at new FargateService (/Users/amal/rasa/tooling/infra-app/node_modules/@pulumi/ecs/fargateService.ts:216:9)
        at Object.<anonymous> (/Users/amal/rasa/tooling/infra-app/index.ts:103:17)
        at Module._compile (node:internal/modules/cjs/loader:1103:14)
        at Module.m._compile (/Users/amal/rasa/tooling/infra-app/node_modules/ts-node/src/index.ts:439:23)
        at Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
        at Object.require.extensions.<computed> [as .ts] (/Users/amal/rasa/tooling/infra-app/node_modules/ts-node/src/index.ts:442:12)
        at Module.load (node:internal/modules/cjs/loader:981:32)
        at Function.Module._load (node:internal/modules/cjs/loader:822:12)
        at Module.require (node:internal/modules/cjs/loader:1005:19)
What is the right way to do this? Any help is much appreciated.
you're exporting the whole cluster object, which won't work because stack outputs are only primitives like strings - but luckily the FargateService constructor's cluster argument is only supported to be the arn, which is a string
export const cluster = fargateCluster.arn
should work
Hi @ancient-car-89914 Thanks for your response. The
argument which is part of the
is looking for a value of type
and thus the
value is not being accepted. I guess your suggestion will work with the classic aws api
since it is only looking for
for the
ah, my mistake - I haven't yet worked with the native providers, I guess you would need to get the cluster by its arn somehow
Unfortunately i could not find any method in
to fetch the cluster which returns the type of
😢 Will probably have to create the service using
i guess
Just as @ancient-car-89914 said above, you cannot export the whole cluster object.You could export its
instead. I am assuming you are using AWSX
? In that, the
accepts a
arg which can either be an
or an
(the existing cluster's name): https://github.com/pulumi/pulumi-awsx/blob/066dcd47e78198a9a56ea36a38b4615ac50c747e/awsx-classic/ecs/cluster.ts#L176. So use the
from your other stack to "re-create" the Cluster resource. Note that when you do this, you are essentially bringing the cluster resource into this stack's state. This is because AWSX does a
when you pass the name thereby bringing the cluster into the state. So it's sort of undoing the separation that you are likely looking to have.
Also, if you are using AWSX
which is based on the native AWS provider. There it seems the
itself has a
arg that simply seems to accept a string value which I am assuming is either the name or the ARN of the cluster. https://github.com/pulumi/pulumi-awsx/blob/master/awsx/schema-types.ts#L205
Thanks for the input @clever-sunset-76585 It will give these a shot and see if it solves my issue
👌 1
I tried with the
package but found out that the API have changed significantly there and it was breaking a lot of other stuff. So I did not go with that option. Thus I finally created a
default VPC
and let the
create a
default cluster
on the default VPC so that the cluster is auto created and i don't have to manage that separately and pass around the value for deployments.
Update: Pulumi was creating new fargate
default cluster
per stack. Thus I finally ended up with create a new Fargate cluster per stack and decided not to share a single cluster across stacks.