sparse-intern-71089
07/12/2018, 5:44 PMstocky-spoon-28903
07/12/2018, 5:45 PMimport * as aws from "@pulumi/aws";
async function main() {
const vpc = new aws.ec2.Vpc("vpc", {
cidrBlock: "10.0.0.0/16"
});
const rt = await aws.ec2.getRouteTable({
routeTableId: vpc.defaultRouteTableId
});
}
const _ = main();
stocky-spoon-28903
07/12/2018, 5:45 PMstocky-spoon-28903
07/12/2018, 5:45 PM❯ pulumi preview
Previewing update of stack 'unparented-from-read-dev'
Previewing changes:
Type Name Plan Info
+ pulumi:pulumi:Stack unparented-from-read-unparented-from-read-dev create 3 errors
+ └─ aws:ec2:Vpc vpc create
Diagnostics:
pulumi:pulumi:Stack: unparented-from-read-unparented-from-read-dev
error: Running program '/Users/James/Code/pulumi/repros/unparented-from-read' failed with an unhandled exception:
error: Error: invocation of aws:ec2/getRouteTable:getRouteTable returned an error: invoking aws:ec2/getRouteTable:getRouteTable: One of route_table_id, vpc_id, subnet_id, filters, or tags must be assigned
at monitor.invoke (/Users/James/Code/pulumi/repros/unparented-from-read/node_modules/@pulumi/pulumi/runtime/invoke.js:61:33)
at Object.onReceiveStatus (/Users/James/Code/pulumi/repros/unparented-from-read/node_modules/grpc/src/client_interceptors.js:1189:9)
at InterceptingListener._callNext (/Users/James/Code/pulumi/repros/unparented-from-read/node_modules/grpc/src/client_interceptors.js:564:42)
at InterceptingListener.onReceiveStatus (/Users/James/Code/pulumi/repros/unparented-from-read/node_modules/grpc/src/client_interceptors.js:614:8)
at callback (/Users/James/Code/pulumi/repros/unparented-from-read/node_modules/grpc/src/client_interceptors.js:841:24)
error: an unhandled error occurred: Program exited with non-zero exit code: 1
error: an error occurred while advancing the preview
white-balloon-205
preview
the VPC is not yet created, meaning that vpc.defaultRouteTableId
doesn't have any value and undefined
will get passed into data source, leading to the error you see.
We plan to "fix" this by not allowing you to write this code this way - by making data-sources not allow Input<T>
as inputs, only T
. See https://github.com/pulumi/pulumi/issues/1483#issuecomment-399282301.
The following is a way you can write this which should work correctly today, and will be the only way that works after the changes noted in the issue above.
import * as aws from "@pulumi/aws";
const vpc = new aws.ec2.Vpc("vpc", {
cidrBlock: "10.0.0.0/16"
});
const rt = vpc.defaultRouteTableId.apply(rtb => aws.ec2.getRouteTable({
routeTableId: rtb,
}));
white-balloon-205
.apply
that it will only run after there is a known value of the vpc.defaultRouteTableId
that this code depends on.stocky-spoon-28903
07/12/2018, 6:32 PMstocky-spoon-28903
07/12/2018, 6:35 PMResourceOptions
in order to “adopt” it?stocky-spoon-28903
07/12/2018, 6:37 PMstocky-spoon-28903
07/12/2018, 6:37 PMconst publicRouteTable = await vpc.defaultRouteTableId.apply(rtb => aws.ec2.getRouteTable({
routeTableId: rtb
}));
publicRouteTable.apply(id => {
const publicRouteTableOptions = Object.assign({
id: vpc.defaultRouteTableId
}, vpcParent);
const publicRouteTableTags = Object.assign({
Name: `${inputs.description} Public RT`
}, inputs.baseTags);
return new aws.ec2.RouteTable(`${baseName}-public-rt`, {
vpcId: vpc.id,
tags: publicRouteTableTags
}, publicRouteTableOptions);
});
new aws.ec2.Route(`${baseName}-route-public-sn-to-ig`, {
routeTableId: publicRouteTable.apply(prt => prt.id),
destinationCidrBlock: "0.0.0.0/0",
gatewayId: internetGateway.id
}, vpcParent);
white-balloon-205
stocky-spoon-28903
07/12/2018, 8:34 PMaws_default_route_table
(etc) to deal with that particular case.stocky-spoon-28903
07/12/2018, 8:35 PMwhite-balloon-205
stocky-spoon-28903
07/12/2018, 9:02 PMstocky-spoon-28903
07/12/2018, 9:02 PMstocky-spoon-28903
07/12/2018, 9:02 PMpublicRouteTable.apply(id => {
const publicRouteTableTags = Object.assign({
Name: `${inputs.description} Public RT`
}, inputs.baseTags);
return new aws.ec2.DefaultRouteTable(`${baseName}-public-rt`, {
defaultRouteTableId: id.id,
tags: publicRouteTableTags
}, vpcParent);
});
stocky-spoon-28903
07/12/2018, 9:04 PMstocky-spoon-28903
07/12/2018, 9:11 PMapply
is never executed at that time.stocky-spoon-28903
07/12/2018, 9:13 PMapply
!)stocky-spoon-28903
07/12/2018, 9:19 PMstocky-spoon-28903
07/12/2018, 9:19 PMDo you want to perform this update? yes
Updating stack 'pulumi-subnets-test-dev'
Performing changes:
Type Name Status Info
+ pulumi:pulumi:Stack pulumi-subnets-test-pulumi-subnets-test-dev created
+ └─ operator-error:aws:Vpc demo created
+ └─ aws:ec2:Vpc demo-vpc created
+ ├─ aws:ec2:VpcDhcpOptions demo-dhcp-options created
+ │ └─ aws:ec2:VpcDhcpOptionsAssociation demo-dhcp-options-assoc created
+ ├─ aws:ec2:InternetGateway demo-igw created
+ ├─ aws:ec2:Subnet demo-public-1 created
+ │ └─ aws:ec2:RouteTableAssociation demo-public-rta-1 created
+ ├─ aws:ec2:Subnet demo-public-2 created
+ │ └─ aws:ec2:RouteTableAssociation demo-public-rta-2 created
+ ├─ aws:ec2:Subnet demo-public-3 created
+ │ └─ aws:ec2:RouteTableAssociation demo-public-rta-3 created
+ ├─ aws:ec2:Subnet demo-private-1 created
+ ├─ aws:ec2:Subnet demo-private-2 created
+ ├─ aws:ec2:Subnet demo-private-3 created
+ ├─ aws:route53:Zone demo-private-hosted-zone created
+ └─ aws:ec2:DefaultRouteTable demo-public-rt created
+ └─ aws:ec2:Route demo-route-public-sn-to-ig created