https://pulumi.com logo
#general
Title
# general
p

proud-alarm-92546

06/13/2019, 5:13 PM
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

lemon-spoon-91807

06/13/2019, 5:23 PM
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

proud-alarm-92546

06/13/2019, 5:26 PM
if I try to consume the subnetIDs, they're always blank
l

lemon-spoon-91807

06/13/2019, 5:26 PM
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

proud-alarm-92546

06/13/2019, 5:27 PM
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

lemon-spoon-91807

06/13/2019, 5:27 PM
right.
let's try to figure out hte publicSubnetIds issue.
p

proud-alarm-92546

06/13/2019, 5:27 PM
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

lemon-spoon-91807

06/13/2019, 5:28 PM
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

proud-alarm-92546

06/13/2019, 5:28 PM
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

lemon-spoon-91807

06/13/2019, 5:30 PM
where is vpcObject defined.
p

proud-alarm-92546

06/13/2019, 5:31 PM
Copy code
vpcObject = awsx.ec2.Vpc.fromExistingIds("vpcObject", {
        vpcId: vpcId,
        publicSubnetIds: subnets
});
oh missing the let (it was in an if)
l

lemon-spoon-91807

06/13/2019, 5:32 PM
something seems odd about that error.
p

proud-alarm-92546

06/13/2019, 5:32 PM
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

lemon-spoon-91807

06/13/2019, 5:32 PM
ahhh
yes.
thinking
p

proud-alarm-92546

06/13/2019, 5:32 PM
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

lemon-spoon-91807

06/13/2019, 5:32 PM
i understand the problem there.
p

proud-alarm-92546

06/13/2019, 5:33 PM
cool 🙂
l

lemon-spoon-91807

06/13/2019, 5:33 PM
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

proud-alarm-92546

06/13/2019, 5:35 PM
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

lemon-spoon-91807

06/13/2019, 5:36 PM
ok. so:
Copy code
"vpcPublicSubnetIds":["subnet-0ce946c7c70d9b413","subnet-082c54f7d53c685f8"]
so the data is there, as i would expect
p

proud-alarm-92546

06/13/2019, 5:36 PM
yep
l

lemon-spoon-91807

06/13/2019, 5:36 PM
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

proud-alarm-92546

06/13/2019, 5:36 PM
if I were to guess, there's a async related problem somewhere
l

lemon-spoon-91807

06/13/2019, 5:36 PM
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

proud-alarm-92546

06/13/2019, 5:38 PM
yeah, this is effectively the same problem I had trying to pass in getSubnetIds output
l

lemon-spoon-91807

06/13/2019, 5:38 PM
(thinking hard)
(thinking intensifies)
p

proud-alarm-92546

06/13/2019, 5:39 PM

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

l

lemon-spoon-91807

06/13/2019, 5:47 PM
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

proud-alarm-92546

06/13/2019, 8:08 PM
thanks, sorry storm rolled in and knocked cable out. still down.
l

lemon-spoon-91807

06/13/2019, 8:08 PM
suckkkkkkks 🙂
p

proud-alarm-92546

06/13/2019, 8:09 PM
yep. hard to do aws stuff without network!
finally added this slack ti my phone to check in :)
l

lemon-spoon-91807

06/13/2019, 8:09 PM
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

proud-alarm-92546

06/13/2019, 8:10 PM
for my current case, the stack name would likely always be a config.
l

lemon-spoon-91807

06/13/2019, 8:10 PM
great
p

proud-alarm-92546

06/13/2019, 8:15 PM
reading the pr - fun. i can only guess at the comlexities behind this
l

lemon-spoon-91807

06/13/2019, 8:16 PM
yeah, we've been screwed because we have a hard grpc dependency
and grpc is only async on nodejs
p

proud-alarm-92546

06/13/2019, 8:22 PM
ahhhh
btw if there is a super hacky for now workaround, i'd appreciate it. it would let me get unblocked tomorrow.
l

lemon-spoon-91807

06/13/2019, 9:31 PM
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

proud-alarm-92546

06/13/2019, 9:33 PM
the vpc...get inside the async or the whole thing? got a pointed to a similar sample structure?
and yeah 😿
l

lemon-spoon-91807

06/13/2019, 9:33 PM
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

proud-alarm-92546

06/13/2019, 9:34 PM
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

lemon-spoon-91807

06/13/2019, 9:36 PM
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

proud-alarm-92546

06/13/2019, 9:41 PM
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

lemon-spoon-91807

06/13/2019, 9:41 PM
understood
we'll hopefully get consensus on that PR by monday
p

proud-alarm-92546

06/13/2019, 9:42 PM
appreciate the help!