agreeable-window-77899
07/14/2022, 9:34 AMStackReference
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
// Create new fargate cluster for running containers
export const fargateCluster = new awsx.ecs.Cluster(
`foo-bar`,
{
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
// Get resources from infra-base
const baseInfra = new pulumi.StackReference(
`blah/blah/blah`
);
// 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
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.ancient-car-89914
07/14/2022, 2:03 PMexport const cluster = fargateCluster.arn
should workagreeable-window-77899
07/14/2022, 2:50 PMcluster
argument which is part of the awsx.ecs.FargateService
is looking for a value of type awsx.ecs.Cluster
and thus the arn
value is not being accepted. I guess your suggestion will work with the classic aws api aws.ecs.Service
since it is only looking for string
for the cluster
argument.ancient-car-89914
07/14/2022, 2:55 PMagreeable-window-77899
07/14/2022, 3:35 PMawsx.ecs
to fetch the cluster which returns the type of awsx.ecs.Cluster
😢
Will probably have to create the service using aws.ecs.Service
i guessclever-sunset-76585
07/14/2022, 3:38 PMname
instead.
I am assuming you are using AWSX 0.x
? In that, the awsx.ecs.Cluster
accepts a cluster
arg which can either be an aws.ecs.Cluster
or an Input<string>
(the existing cluster's name): https://github.com/pulumi/pulumi-awsx/blob/066dcd47e78198a9a56ea36a38b4615ac50c747e/awsx-classic/ecs/cluster.ts#L176. So use the name
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 .get()
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.1.x-beta
which is based on the native AWS provider. There it seems the FargateService
itself has a cluster
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#L205agreeable-window-77899
07/14/2022, 4:20 PM1.x-beta
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 awsx.ecs.FargateService
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.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.