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

adamant-dress-73325

04/27/2020, 4:18 PM
Hello, I have some questions on the pulumi 2 migration I didn’t see covered in the migration guide. Is the pulumi v2 cli compatible with running pulumi v1 projects? Can I upgrade the cli and deploy old projects as usual? How would I rewrite the following code to avoid requireOutputSync? I’ve tried casting to
pulumi.Output<string>[]
but this just produces weird type error I’m unable to resolve without casting to
unknown
.
Copy code
const vpcId = stackRef.requireOutput('vpcId');
const vpcPrivateSubnetIds = <string[]>stackRef.requireOutputSync('vpcPrivateSubnetIds');
const vpcPublicSubnetIds = <string[]>stackRef.requireOutputSync('vpcPublicSubnetIds');
const vpc = awsx.ec2.Vpc.fromExistingIds('vpc', {
  privateSubnetIds: vpcPrivateSubnetIds,
  publicSubnetIds: vpcPublicSubnetIds,
  vpcId,
});
f

faint-table-42725

04/27/2020, 5:57 PM
Yes — you can use the v2 CLI with v1 projects.
a

adamant-dress-73325

04/27/2020, 9:32 PM
great, thats good news
@faint-table-42725 Regarding my 2nd question, this code typechecks on v2, but now pulumi is trying to delete my vpc, which is not what I want.
Copy code
const vpcId = stackRef.requireOutput('vpcId');
const vpcPrivateSubnetIds = (stackRef.requireOutput('vpcPrivateSubnetIds') as unknown) as pulumi.Output<string>[];
const vpcPublicSubnetIds = (stackRef.requireOutput('vpcPublicSubnetIds') as unknown) as pulumi.Output<string>[];
const vpc = awsx.ec2.Vpc.fromExistingIds('vpc', {
  privateSubnetIds: vpcPrivateSubnetIds,
  publicSubnetIds: vpcPublicSubnetIds,
  vpcId,
});
f

faint-table-42725

04/28/2020, 12:31 AM
What does the diff show?
I don’t know if you can cast like that because I would expect the actual type to be
Output<string[]>
?
a

adamant-dress-73325

04/28/2020, 4:03 AM
I ended up casting to Output<string[]> like you said, and it does work if I then wrap the rest of my code in apply, like so:
Copy code
const vpcId = stackRef.requireOutput('vpcId');
let vpcPrivateSubnetIds = stackRef.requireOutput('vpcPrivateSubnetIds') as pulumi.Output<string[]>;
let vpcPublicSubnetIds = stackRef.requireOutput('vpcPublicSubnetIds') as pulumi.Output<string[]>;

pulumi.all([vpcPrivateSubnetIds, vpcPublicSubnetIds]).apply(([priv, pub]) => {
  const vpc = awsx.ec2.Vpc.fromExistingIds('vpc', {
    privateSubnetIds: priv,
    publicSubnetIds: pub,
    vpcId,
  });
...