https://pulumi.com logo
Title
b

bland-tailor-50336

10/20/2022, 4:28 AM
I'm confused as to why the types in the Docs are different from my project... this is frustrating
This is what I see in vscode when I go to the definition (/home/charlie/workspace/mxd/infra/service/node_modules/@pulumi/awsx/ecs/fargateService.d.ts):
export interface FargateServiceArgs {
    // ...
    cluster?: ecs.Cluster;
    // ... 
  
}
But when I look at the source the docs link to I see: (https://github.com/pulumi/pulumi-awsx/blob/master/awsx/schema-types.ts)
export interface FargateServiceArgs {
    readonly cluster?: pulumi.Input<string>;
    // ...
}
Am I crazy?
b

brainy-church-78120

10/20/2022, 4:33 AM
what version of awsx are you using?
b

bland-tailor-50336

10/20/2022, 4:35 AM
I wrote above. the one I was originally using
0.40.1
But I just updated to the one linked by the docs page (
v1.0.0-beta.7
) and it's still the same issue
The type is defined here: /home/charlie/workspace/mxd/infra/service/node_modules/@pulumi/awsx/ecs/fargateService.d.ts
This contradicts the documentation
which says cluster is:
ARN of an ECS cluster.
This is causing me issues because It's not clear how to leverage the output of another stack in building a new FargateService object
If it were just the
ARN of an ECS cluster
then I could use the string output... unfortunately it is looking for an awsx.ecs.Cluster object as a property on the args parameter
Anyone have advice on how to resolve?
@millions-furniture-75402? This is me trying to fix the issue I had before
m

millions-furniture-75402

10/20/2022, 2:08 PM
Sorry, what issue?
b

bland-tailor-50336

10/20/2022, 2:09 PM
@millions-furniture-75402 so I'm trying to use stack reference and build each microservice in their own stack... instead of in one single stack (what we talked about originally)
m

millions-furniture-75402

10/20/2022, 2:10 PM
Ahh okay, yeah.
b

bland-tailor-50336

10/20/2022, 2:10 PM
Originally I was creating a bunch of microservices by looping through a list of services in a single stack index.ts... This presented its own issues like incremental build/deploy, I wanted a noop basically for micro-services that hadn't changed
so now I'm trying to build a Base infrastructure pulumi stack/script
which creates an ALB
and listener
and then have a seperate Pulumi stack for each microservice that attaches to the ALB
m

millions-furniture-75402

10/20/2022, 2:11 PM
right
b

bland-tailor-50336

10/20/2022, 2:11 PM
by creating an ecs FargateService attached to a TargetGroup and use a stack reference to attach that to the ALB in the base infr
... so the issue I'm having is that the FargateService requires a awsx.ecs.Cluster type object as part of it's FargateServiceArgs or whatever
and that is not a primitive value which can be provided by the output of the base stack
e.g. If it was just using an arn as input then that would be simple enough to grab from the output of the base stack
but since it's expecting an object of interface awsx.ecs.Cluster with all the fields/methods required I'm not sure what to do
m

millions-furniture-75402

10/20/2022, 2:14 PM
Do you have something like?
const cluster = new awsx.ecs.Cluster(`${appName}-cluster`, {
  securityGroups: [],
  vpc,
});
b

bland-tailor-50336

10/20/2022, 2:15 PM
yup in the base stack
m

millions-furniture-75402

10/20/2022, 2:15 PM
Your Stack Reference is an ARN or ID and now you have an issue because you need the awsx object again?
b

bland-tailor-50336

10/20/2022, 2:15 PM
yes exactly
m

millions-furniture-75402

10/20/2022, 2:15 PM
You need to use a
.get()
b

bland-tailor-50336

10/20/2022, 2:15 PM
I'm outputting a string
but the constructor requires an awsx.ecs.Cluster object
m

millions-furniture-75402

10/20/2022, 2:16 PM
Right, the getters help you recreate an object from an ID
b

bland-tailor-50336

10/20/2022, 2:16 PM
@millions-furniture-75402 is there any documentation on how to use
.get
?
m

millions-furniture-75402

10/20/2022, 2:16 PM
ugh... but maybe that's not exposed in awsx
b

bland-tailor-50336

10/20/2022, 2:17 PM
I was looking for ways to get the resource object solely using it's ARN
or id
but couldn't find a way
m

millions-furniture-75402

10/20/2022, 2:17 PM
Here is an example of doing a similar thing with a security group
const mySg = awsx.ec2.SecurityGroup.fromExistingId(
      "my-sg",
      mySgId,
      { vpc },
    );
the normal packages have getters, but I don't think awsx necessarily does, it might have helper methods like above instead
Unfortunately, my similar use was using EC2 Instances, instead of fargate. I believe all my clusters are running single services.
b

bland-tailor-50336

10/20/2022, 2:18 PM
hmmm the awsx.ecs.Cluster class doesn't even appear in the documentation for some reason
and the awsx.ecs.FargateService docs seem to not align with the actual definition
m

millions-furniture-75402

10/20/2022, 2:19 PM
Use your IDE to trace into the provider packages and read the docstrings there
b

bland-tailor-50336

10/20/2022, 2:19 PM
i.e. it specifies cluster is an arn... but the actual constructor definition expects a awsx.ecs.Cluster arg
I'd be happy to submit a PR to change the docs... If I knew how to correct it
m

millions-furniture-75402

10/20/2022, 2:20 PM
Personally, I have a bias against awsx (crosswalk). It's consistently been more of a pain in the ass than helpful to me.
Unfortunately, in certain cases, it's easier to use 😞 -- such as manipulating Security Groups
b

bland-tailor-50336

10/20/2022, 2:20 PM
interesting
m

millions-furniture-75402

10/20/2022, 2:21 PM
Another thing to know about awsx, is that many, if not all of the resources contain the AWS primitive resource as a property
e.g. the SecurityGroup will have a
.securityGroup
property that is the underlying aws security group created by the aws provider IIRC.
b

bland-tailor-50336

10/20/2022, 2:21 PM
I feel like every resource should implement a method like the one you've shown
.fromExistingId
or
.fromExistingARN
should be part of an interface that is implemented by all resources
just makes sense
@millions-furniture-75402 interesting
m

millions-furniture-75402

10/20/2022, 2:22 PM
FWIW, you CAN export your entire object
I'm not sure it's recommended... but it is possible.
The awsx package is not consistent. The API Gateway stuff is a hellscape.
b

bland-tailor-50336

10/20/2022, 2:24 PM
@millions-furniture-75402 but doesn't it just export as a plain data object ... and the constructor is expecting an instance of that class (awsx.ecs.Cluster)
m

millions-furniture-75402

10/20/2022, 2:27 PM
Hmmm, good point
b

bland-tailor-50336

10/20/2022, 2:28 PM
perhaps the constructor can take that plain data object as an argument?
m

millions-furniture-75402

10/20/2022, 2:28 PM
Perhaps, I don't remember, been a while.
This example uses the aws package, and the service args take it
b

bland-tailor-50336

10/20/2022, 3:09 PM
No I don't need to use awsx I just thought the whole point was it is supposed to save time lol
m

millions-furniture-75402

10/20/2022, 3:09 PM
Anecdotally, AWSX has given me PTSD
b

bland-tailor-50336

10/20/2022, 3:10 PM
@millions-furniture-75402 Also that link you sent me also leverages awsx
m

millions-furniture-75402

10/20/2022, 3:10 PM
Look closer
// Create an ECS Cluster
const cluster = new aws.ecs.Cluster("default-cluster");

const service = new awsx.ecs.FargateService("my-service", {
    cluster: cluster.arn,
   ...
});
b

bland-tailor-50336

10/20/2022, 3:10 PM
@millions-furniture-75402 good to know
oh interesting
thanks @millions-furniture-75402
m

millions-furniture-75402

10/20/2022, 3:11 PM
IIRC awsx can take ARNs or AWS resources instead of awsx resources in some cases.
b

bland-tailor-50336

10/20/2022, 3:11 PM
I wonder if it wouldn't make sense to update the docs when/if I get this working so another person doesn't have to go through the same headache figuring this out?
m

millions-furniture-75402

10/20/2022, 3:12 PM
It looks like there is an effort to replace the legacy version of awsx, which might be why the docs are out of sync.
b

bland-tailor-50336

10/20/2022, 3:12 PM
interesting
m

millions-furniture-75402

10/20/2022, 3:13 PM
The awsx resource having the aws resource as a property
You get this figured out?
b

bland-tailor-50336

10/20/2022, 7:00 PM
Been busy working on other stuff
but I think I've almost figured it out
will ping you
when I get a chance to get back at it
m

millions-furniture-75402

10/20/2022, 7:02 PM
Cool, sounds good.
b

bland-tailor-50336

10/20/2022, 7:04 PM
TY for all your help