anyone available for some more awsx typing help? `...
# general
p
anyone available for some more awsx typing help?
Copy code
TSError: ⨯ Unable to compile TypeScript:
    index.ts(17,5): error TS2345: Argument of type '{ vpc: Output<any>; }' is not assignable to parameter of type 'ClusterArgs'.
      Types of property 'vpc' are incompatible.
        Type 'Output<any>' is not assignable to type 'Vpc | undefined'.
(code and error output in thread)
Copy code
import * as pulumi from "@pulumi/pulumi";
// import * as aws from "@pulumi/aws";
import * as awsx from "@pulumi/awsx";



// make this a config.
const vpcStack = new pulumi.StackReference(`test-vpc1`);

export const vpc = vpcStack.getOutput("vpc");
export const vpcId = vpcStack.getOutput("vpcId");
export const subnets = vpcStack.getOutput("vpcPublicSubnetIds");


// Create an ECS Fargate cluster.
const cluster = new awsx.ecs.Cluster("cluster",
    {
      // must be an awsx.ec2.Vpc only.
      vpc: vpc
    }
 );
Copy code
Diagnostics:
  pulumi:pulumi:Stack (test_service-test-service1):
    error: Running program '/Users/draistrick/git/tg/devops-infra/test_service' failed with an unhandled exception:
    TSError: ⨯ Unable to compile TypeScript:
    index.ts(17,5): error TS2345: Argument of type '{ vpc: Output<any>; }' is not assignable to parameter of type 'ClusterArgs'.
      Types of property 'vpc' are incompatible.
        Type 'Output<any>' is not assignable to type 'Vpc | undefined'.
          Type 'OutputInstance<any>' is missing the following properties from type 'Vpc': publicSubnetIds, privateSubnetIds, isolatedSubnetIds, vpc, and 12 more.
the other stack
Copy code
// <https://pulumi.io/reference/crosswalk/aws/vpc/>
import * as awsx from "@pulumi/awsx";


// Name tags are not created on IGW, DHCP option sets, route tables, ACL
// <https://github.com/pulumi/pulumi-awsx/issues/322>
// trying to
export const vpc = new awsx.ec2.Vpc("custom", {
    cidrBlock: "10.118.0.0/16",
    numberOfAvailabilityZones: 2,
    // no ipv6 default routes created OR netblocks added to subnets.  sigh.
    // <https://github.com/pulumi/pulumi-awsx/issues/323>
    // so you can't do dualstack anything right now with this.
    assignGeneratedIpv6CidrBlock: true,
    // defaults:
    // DNS resolution Enabled
    // DNS hostnames Enabled
    // you can't safely change, or at least a change that adds, this. you'll get subnet conflicts
    // subnets: [{ type: "public" }],
    // <https://github.com/pulumi/pulumi-awsx/issues/321>
    subnets: [{ type: "public" }, { type: "private" }],
    tags: { Name: "custom_name"},
});


// Export a few resulting fields to make them easy to use:
export const vpcId = vpc.id;
export const vpcPrivateSubnetIds = vpc.privateSubnetIds;
export const vpcPublicSubnetIds = vpc.publicSubnetIds;
@lemon-spoon-91807 any chance you have a few minutes to look at this? I'm sure I'm missing something obvious.
l
looking 🙂
er, yeah. i wouldn't expect that to work.
but i understand why you'd want it to 🙂
basically today, stack exports really are intended to just be POJOs
so, your vpcId and subnetIds should be ok.
and we'll allow you to export th Vpc. but not really in a way that's importable
p
if I try to consume the subnetIDs, they're always blank
l
so, on the other end, what should work instead is
(ok. so that's bad too. not sure why that woul dbe)
Copy code
export const vpcId = vpcStack.getOutput("vpcId");
const vpc = Vpc.fromExistingIds(...)
when teh other stack runs, did it have exports that matched your expectations?
p
Copy code
// vpcObject = awsx.ec2.Vpc.fromExistingIds("vpcObject", {
  //         vpcId: vpcId,
  //         // this doesnt get populated automatically, and -fargateservice- only reads this from cluster.vpc.[pubic|private]....
  //         publicSubnetIds: subnets.apply(out => out)
  //         // privateSubnetIds: ...
  // });
that? 🙂
l
right.
let's try to figure out hte publicSubnetIds issue.
p
yeah, the exports are fine from the vpc stack, and if I just export and do nothing else in the 2nd stack, they look fine
l
i have not actually used stack references. time to go find out how htey work
just to check, but at least vpcId works right?
p
vpcid works fine. my ACM ARN (not in this sample) also works fine
subnets have been the kicker
(running a simplied test variant now)
Copy code
import * as pulumi from "@pulumi/pulumi";
// import * as aws from "@pulumi/aws";
import * as awsx from "@pulumi/awsx";



// make this a config.
const vpcStack = new pulumi.StackReference(`test-vpc1`);

// export const vpc = vpcStack.getOutput("vpc");
export const vpcId = vpcStack.getOutput("vpcId");
export const subnets = vpcStack.getOutput("vpcPublicSubnetIds");

  vpcObject = awsx.ec2.Vpc.fromExistingIds("vpcObject", {
          vpcId: vpcId,
          publicSubnetIds: subnets
  });

const cluster = new awsx.ecs.Cluster(namePrefix+"cluster",
    {
      // must be an awsx.ec2.Vpc only.
      vpc: vpcObject
    }
 );
oops, old var in there still for namePrefix. 🙂
but doesnt error there:
Copy code
TSError: ⨯ Unable to compile TypeScript:
    index.ts(17,5): error TS2345: Argument of type '{ vpc: Output<any>; }' is not assignable to parameter of type 'ClusterArgs'.
      Types of property 'vpc' are incompatible.
        Type 'Output<any>' is not assignable to type 'Vpc | undefined'.
          Type 'OutputInstance<any>' is missing the following properties from type 'Vpc': publicSubnetIds, privateSubnetIds, isolatedSubnetIds, vpc, and 12 more.
l
where is vpcObject defined.
p
Copy code
vpcObject = awsx.ec2.Vpc.fromExistingIds("vpcObject", {
        vpcId: vpcId,
        publicSubnetIds: subnets
});
oh missing the let (it was in an if)
l
something seems odd about that error.
p
Copy code
error: Running program '/Users/draistrick/git/tg/devops-infra/test_service' failed with an unhandled exception:
    TSError: ⨯ Unable to compile TypeScript:
    index.ts(15,9): error TS2322: Type 'Output<any>' is not assignable to type 'Input<string>[] | undefined'.
      Type 'OutputInstance<any>' is missing the following properties from type 'Input<string>[]': length, pop, push, concat, and 26 more.
and this is 15
Copy code
publicSubnetIds: subnets
l
ahhh
yes.
thinking
p
if I convert this to javascript, it ignores the type complaint (as you'd mentioned), and gets to trying to create the cluster with an empty subnet
l
i understand the problem there.
p
cool 🙂
l
first off, i want to figure something out
can you comment everything
and just do this:
Copy code
const vpcStack = new pulumi.StackReference(`test-vpc1`);
vpcStack.outputs.apply(o => console.log(JSON.stringify(o)));
p
and here I wish I could attach a snippit to a thread... 🙂
I'll pm it for sanity (1 giant json line of many things)
l
ok. so:
Copy code
"vpcPublicSubnetIds":["subnet-0ce946c7c70d9b413","subnet-082c54f7d53c685f8"]
so the data is there, as i would expect
p
yep
l
so we're running into a different problem
and i know what the problem is
i just don't have a solution at this moment
to make the problem clear:
p
if I were to guess, there's a async related problem somewhere
l
not exactly
the issue is that Vpc wants the 'existing Ids' information in 'realized' form
i.e. it wants a true array of subnetIds.
so that it can literally go iterate it and know how many actual subnets to create
the problem here is that we have an
Output<string[]>
not a
string[]
(so yeah, you could say this is an async problem).
p
yeah, this is effectively the same problem I had trying to pass in getSubnetIds output
l
(thinking hard)
(thinking intensifies)
p

https://www.sweetwater.com/sweetcare/media/2005/10/Screen-Shot-2016-09-28-at-2.33.39-PM.png

l
this has spawned an interesting internal discussion
we have a hacky way we think we could unblock you
but we're investiating a non-hacky way forward
question:
about:
Copy code
const vpcStack = new pulumi.StackReference(`test-vpc1`);
do you always know the name of the stack you'll be referencing?
i.e. there's no chance that that name would be an Output?
ok. we have a potential solution (it would require a new pulumi/pulumi version). but i'm trying it out now
p
thanks, sorry storm rolled in and knocked cable out. still down.
l
suckkkkkkks 🙂
p
yep. hard to do aws stuff without network!
finally added this slack ti my phone to check in :)
l
we're debating hte pros/cons of my approach
and if we want to go with this simple approach, or rethink a much deeper area here
(though the latter would takea lot longer, and we're very aware of the pain here)
p
for my current case, the stack name would likely always be a config.
l
great
p
reading the pr - fun. i can only guess at the comlexities behind this
l
yeah, we've been screwed because we have a hard grpc dependency
and grpc is only async on nodejs
p
ahhhh
btw if there is a super hacky for now workaround, i'd appreciate it. it would let me get unblocked tomorrow.
l
super hacky is:
1. you'll need to be an in an async function
i.e. something like:
(async () => { ... })();
and inside that async funciton, you do
await (<any>vpcPublicSubnetIds).promise();
😢
p
the vpc...get inside the async or the whole thing? got a pointed to a similar sample structure?
and yeah 😿
l
no samples, because this is def not recommended
so, this 'await' will pull out hte actual string[] with the subnetIds
so after that line, you'll have to do the Vpc.fromExistingIds.
p
is there a better approach to consuming an out if stack vpc? something closer to the original plan?
(pulumis plan)
or am i just in the weeds in an unexplored direction?
l
that's what we're discussing now
i mean, if you don't use StackReferences, it's easy
just use the actual vpcId and publicSubnetIds 🙂
but consuming across stacks is a bit new for us
totally reasonable case, but complex due to this asynchrony issue
p
yeah it just really sucks to have to manually input those as config. i'll probably just keep going in that direction (already built) then
l
understood
we'll hopefully get consensus on that PR by monday
p
appreciate the help!