Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix using custom providers with VPCs #843

Merged
merged 1 commit into from
May 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion awsx/ec2/defaultVpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class DefaultVpc extends schema.DefaultVpc {
) {
super(name, args, opts);

const defaultVpc = pulumi.output(getDefaultVpc());
const defaultVpc = pulumi.output(getDefaultVpc({ parent: this }));
this.vpcId = defaultVpc.vpcId;
this.publicSubnetIds = defaultVpc.publicSubnetIds;
this.privateSubnetIds = defaultVpc.privateSubnetIds;
Expand Down
6 changes: 4 additions & 2 deletions awsx/ec2/getDefaultVpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ import * as aws from "@pulumi/aws";
import * as pulumi from "@pulumi/pulumi";
import * as schema from "../schema-types";

export async function getDefaultVpc(): Promise<schema.getDefaultVpcOutputs> {
const vpc = await aws.ec2.getVpc({ default: true });
export async function getDefaultVpc(
opts: pulumi.InvokeOptions,
): Promise<schema.getDefaultVpcOutputs> {
const vpc = await aws.ec2.getVpc({ default: true }, opts);

if (vpc === undefined) {
throw new Error("unable to find default VPC for this region and account");
Expand Down
2 changes: 1 addition & 1 deletion awsx/ec2/vpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ export class Vpc extends schema.Vpc<VpcData> {

async getDefaultAzs(azCount?: number): Promise<string[]> {
const desiredCount = azCount ?? 3;
const result = await aws.getAvailabilityZones();
const result = await aws.getAvailabilityZones(undefined, { parent: this });
if (result.names.length < desiredCount) {
throw new Error(
`The configured region for this provider does not have at least ${desiredCount} Availability Zones. Either specify an explicit list of zones in availabilityZoneNames or choose a region with at least ${desiredCount} AZs.`,
Expand Down
2 changes: 1 addition & 1 deletion awsx/ecs/fargateService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function getDefaultNetworkConfiguration(
name: string,
parent: pulumi.Resource,
): aws.types.input.ecs.ServiceNetworkConfiguration {
const defaultVpc = pulumi.output(getDefaultVpc());
const defaultVpc = pulumi.output(getDefaultVpc({ parent }));
const sg = new aws.ec2.SecurityGroup(
`${name}-sg`,
{
Expand Down
2 changes: 1 addition & 1 deletion awsx/lb/applicationLoadBalancer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class ApplicationLoadBalancer extends schema.ApplicationLoadBalancer {
.output(restArgs.subnetMappings!)
.apply((s) => aws.ec2.getSubnet({ id: s[0].subnetId })).vpcId;
} else {
const defaultVpc = pulumi.output(getDefaultVpc());
const defaultVpc = pulumi.output(getDefaultVpc({ parent: this }));
this.vpcId = defaultVpc.vpcId;
lbArgs.subnets = defaultVpc.publicSubnetIds;
}
Expand Down
2 changes: 1 addition & 1 deletion awsx/lb/networkLoadBalancer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class NetworkLoadBalancer extends schema.NetworkLoadBalancer {
.output(restArgs.subnetMappings!)
.apply((s) => aws.ec2.getSubnet({ id: s[0].subnetId })).vpcId;
} else {
const defaultVpc = pulumi.output(getDefaultVpc());
const defaultVpc = pulumi.output(getDefaultVpc({ parent: this }));
this.vpcId = defaultVpc.vpcId;
lbArgs.subnets = defaultVpc.publicSubnetIds;
}
Expand Down
2 changes: 1 addition & 1 deletion awsx/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@ export function construct(
}

export const functions: schemaTypes.Functions = {
"awsx:ec2:getDefaultVpc": ec2.getDefaultVpc,
"awsx:ec2:getDefaultVpc": () => ec2.getDefaultVpc({}),
};
2 changes: 2 additions & 0 deletions examples/vpc/nodejs/custom-provider/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/bin/
/node_modules/
3 changes: 3 additions & 0 deletions examples/vpc/nodejs/custom-provider/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: nodejs
runtime: nodejs
description: AWSX VPC - default args
8 changes: 8 additions & 0 deletions examples/vpc/nodejs/custom-provider/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import * as aws from "@pulumi/aws";
import * as awsx from "@pulumi/awsx";

const provider = new aws.Provider("eu-west-1", { region: "us-east-1" });

export const defaultVpc = new awsx.ec2.DefaultVpc("default-vpc", {}, { provider });

export const vpc1 = new awsx.ec2.Vpc("vpc-1", {}, { provider });
10 changes: 10 additions & 0 deletions examples/vpc/nodejs/custom-provider/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "nodejs",
"devDependencies": {
"@types/node": "^14"
},
"dependencies": {
"@pulumi/aws": "^5.4.0",
"@pulumi/pulumi": "^3.0.0"
}
}
18 changes: 18 additions & 0 deletions examples/vpc/nodejs/custom-provider/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"compilerOptions": {
"strict": true,
"outDir": "bin",
"target": "es2016",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"experimentalDecorators": true,
"pretty": true,
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.ts"
]
}