import { App, Stack, TerraformOutput } from "tfts";
import { Vpc } from "./.gen/providers/aws/vpc";
import { Instance } from "./.gen/providers/aws/instance";
class NetworkStack extends Stack {
public readonly vpcId: string;
constructor(scope: App, id: string) {
super(scope, id);
const vpc = new Vpc(this, "vpc", {
cidrBlock: "10.0.0.0/16",
});
this.vpcId = vpc.id;
// Explicitly export the VPC ID
new TerraformOutput(this, "vpc_id_output", {
value: vpc.id,
});
}
}
class AppStack extends Stack {
constructor(scope: App, id: string, vpcId: string) {
super(scope, id);
new Instance(this, "server", {
ami: "ami-0c55b159cbfafe1f0",
instanceType: "t3.micro",
// Reference the VPC ID from the other stack
subnetId: vpcId,
});
}
}
const app = new App();
const network = new NetworkStack(app, "network");
new AppStack(app, "app", network.vpcId);
app.synth();