https://pulumi.com logo
Title
t

thousands-art-36850

06/14/2021, 2:30 PM
Hi everyone! I’m facing an issue when trying to reference an AWS ECS Cluster from another stack. I have a stack that exports the id of that cluster and another one that should use that cluster when creating an ECS FargateService. I tried to use get method to get that cluster by id, but the type of the cluster that’s being returned
aws.ecs.Cluster
is not compatible with what’s required when creating an ECS FargateService
awsx.ecs.Cluster
. Any suggestions / guidance would be appreciated, thanks in advance! (more details in 🧵 )
This is how I’m exporting the id from the first stack:
const cluster = new awsx.ecs.Cluster(...);

export const clusterId = cluster.id;
b

brave-planet-10645

06/14/2021, 2:35 PM
Take a look at Stack references: https://www.pulumi.com/docs/intro/concepts/stack/#stackreferences This means you can access the outputs from one stack in another
Also worth noting is that AWSX masks a lot of the underlying AWS provider to make it easier to set up. However, it can get a little trickier (but not impossible) to have the two work together
t

thousands-art-36850

06/14/2021, 2:39 PM
I’m already using
StackReference
. This is how I’m importing the id and trying to create an ECS FargateService:
const services = new pulumi.StackReference("stack");
const clusterId = services.getOutput("clusterId");
const cluster = aws.ecs.Cluster.get("name", clusterId);

const server = new awsx.ecs.FargateService("resourceName", {
  cluster, // This doesn't work
});
I’m getting a typescript error that says
aws.ecs.Cluster
is not compatible with
awsx.ecs.Cluster
b

brave-planet-10645

06/14/2021, 2:40 PM
That's what I mean. They're not interchangeable.
AWSX is there to get you started. Once you're starting to look at more complicated setups you're going to have to look at the base AWS provider
t

thousands-art-36850

06/14/2021, 2:49 PM
Got it, thanks! do I need to switch to using the AWS core package in this case? Is there an easier way to accomplish the same result? I tried to search for a cluster method in AWSX similar to the one for
awsx.ec2.Vpc
fromExistingIds that returns
Vpc
of type AWSX, but couldn’t find something similar for the cluster
b

brave-planet-10645

06/14/2021, 3:42 PM
do I need to switch to using the AWS core package in this case?
Sorry to say this, but "it depends". There are some cases where it's going to be fine to use AWSX - like if you're using it all within the same stack, if you're not building anything particularly complicated etc and if you can stay within the resources that the package provides.
Otherwise it's best to start looking at the main AWS package
t

thousands-art-36850

06/14/2021, 4:14 PM
I guess in our case we need to use AWS core package for some resources (resources that need the above cluster). Thanks again!
a

agreeable-restaurant-12233

06/14/2021, 5:51 PM
Have you tried cluster.arn instead of cluster.id?
t

thousands-art-36850

06/15/2021, 6:41 AM
No, what will be the advantage in this case? creating a fargate service in AWSX requires passing the entire cluster not only the id/arn
b

brave-planet-10645

06/15/2021, 7:13 AM
Was thinking about this last night. Since this is just a typescript object, you could create the object yourself and pass it in
So get the information using the get method you specified before and creating the object with that information
t

thousands-art-36850

06/15/2021, 10:54 AM
hmm, that’s a good idea, but I don’t think this would work because cluster properties are read-only so I can’t do something like this:
const cluster = aws.ecs.Cluster.get(`${stackName}-cluster`, config.appClusterId);

const appCluster: awsx.ecs.Cluster;
appCluster.id = cluster.id;
b

brave-planet-10645

06/15/2021, 11:40 AM
But you could do something like:
const cluster = aws.ecs.Cluster.get(`${stackName}-cluster`, config.appClusterId);

let appCluster = {
    id: cluster.id
    ...
}
It's the shape that's important (or at least that's my understanding)
t

thousands-art-36850

06/15/2021, 1:10 PM
Thanks again! I think this should work but it requires filling out other properties like security groups that need to be exported from the first stack. Back to your first point, luckily, I found out that I only need to replace two resources to use the AWS core package instead of AWSX and i’m not seeing any issue with this approach so far. So, I think I will go with it
b

brave-planet-10645

06/15/2021, 1:13 PM
I would advise going with the base provider rather than AWSX in this case, but you know how to move on if you wanted to use AWSX
👍 1