stale-secretary-86178
09/18/2023, 2:37 PMmillions-furniture-75402
09/18/2023, 3:11 PMimport * as awsxClassic from "@pulumi/awsx/classic";
import { ComponentResourceOptions, Input, all } from "@pulumi/pulumi";
export interface BaseArgs {
tags?: aws.Tags;
}
export class BaseComponentResource extends ComponentResource {
private readonly name: string;
public getName(): string {
return this.name;
}
constructor(type: string, name: string, args: BaseArgs, opts?: ComponentResourceOptions) {
super(type, name, args, opts);
this.name = name;
}
}
export interface ExistingVpcArgs extends BaseArgs {
privateSubnetIds: Input<Input<string>[]>;
publicSubnetIds: Input<Input<string>[]>;
vpcId: Input<string>;
}
export class ExistingVpc extends BaseComponentResource {
vpc: any;
constructor(name: string, args: ExistingVpcArgs, opts?: ComponentResourceOptions) {
super("shared-vpc", name, args, opts);
this.vpc = all([args.publicSubnetIds, args.privateSubnetIds, args.vpcId]).apply(
([publicSubnetIds, privateSubnetIds, vpcId]) => {
return awsxClassic.ec2.Vpc.fromExistingIds(this.getName(), {
vpcId,
publicSubnetIds,
privateSubnetIds,
});
},
);
}
}
usage:
const vpc = new sansVpc.ExistingVpc("default-vpc", {
privateSubnetIds,
publicSubnetIds,
vpcId
});
shared-infrastructure
stack, I can export
my privateSubnetIds
, publicSubnetIds
and vpcId
, and use StackReferences to get the values in the "child" stack, and the custom component to simplify the getting of the resource.stale-secretary-86178
09/18/2023, 6:08 PMmillions-furniture-75402
09/18/2023, 6:19 PMstale-secretary-86178
09/18/2023, 6:35 PMnew MegaComponent()
which does a bunch of stuff - creates VPC, ecs cluster, database, etc.
Now I would like to untangle this, so that VPC stuff would go into a separate pulumi project/stack/whatever you call it. In pulumi aws package there is the import
option, but here it is missing. In 1.0 there isn't even the .fromExistingIds
. I tried exporting and importing the stack, but the urn's are messed up. Is what I am attempting even possible? Should I recreate the state by hand?millions-furniture-75402
09/18/2023, 7:23 PMstale-secretary-86178
09/18/2023, 10:27 PMVPC.fromExistingIds
does not import the resource (from my understanding). Is there a way to import the awsx.ec2.VPC component or is this impossible ATM?millions-furniture-75402
09/19/2023, 12:58 PMimport
in the opts
?stale-secretary-86178
09/19/2023, 12:59 PMmillions-furniture-75402
09/19/2023, 12:59 PMstale-secretary-86178
09/19/2023, 1:00 PMmillions-furniture-75402
09/19/2023, 1:01 PMconst defaultVpc = new aws.ec2.Vpc("defaultVpc", {}, {
import: "<vpc-id>",
});
stale-secretary-86178
09/19/2023, 1:01 PMmillions-furniture-75402
09/19/2023, 1:02 PMawsx
and VPCs have been a major pain point for me in my projects as well 😞stale-secretary-86178
09/20/2023, 6:52 AMmillions-furniture-75402
09/20/2023, 1:16 PMstale-secretary-86178
09/20/2023, 1:24 PMmillions-furniture-75402
09/20/2023, 2:07 PMstale-secretary-86178
09/20/2023, 2:07 PMmillions-furniture-75402
09/20/2023, 2:11 PMstale-secretary-86178
09/20/2023, 2:13 PMmillions-furniture-75402
09/20/2023, 2:14 PMstale-secretary-86178
09/20/2023, 2:15 PMmillions-furniture-75402
09/20/2023, 2:15 PMstale-secretary-86178
09/20/2023, 2:20 PMmillions-furniture-75402
09/20/2023, 2:21 PM