import { App, Stack, GcsBackend } from "tfts";
import { GoogleProvider } from "./.gen/providers/google/provider";
import { ComputeNetwork } from "./.gen/providers/google/compute-network";
import { ComputeFirewall } from "./.gen/providers/google/compute-firewall";
import { ComputeInstance } from "./.gen/providers/google/compute-instance";
class MyGcpStack extends Stack {
constructor(scope: App, id: string) {
super(scope, id);
const project = "my-gcp-project-id";
const region = "us-central1";
// Configure the Google Provider
new GoogleProvider(this, "google", {
project: project,
region: region,
});
// Configure GCS Backend
new GcsBackend(this, {
bucket: "my-terraform-state-bucket",
prefix: "terraform/state",
});
// Create a VPC Network
const network = new ComputeNetwork(this, "main-network", {
name: "main-network",
autoCreateSubnetworks: true,
});
// Create a Firewall Rule
new ComputeFirewall(this, "allow-http", {
name: "allow-http",
network: network.name,
allow: [
{
protocol: "tcp",
ports: ["80"],
},
],
sourceRanges: ["0.0.0.0/0"],
});
// Create a Compute Instance
new ComputeInstance(this, "web-instance", {
name: "web-instance",
machineType: "f1-micro",
zone: "us-central1-a",
bootDisk: {
initializeParams: {
image: "debian-cloud/debian-11",
},
},
networkInterface: [
{
network: network.id,
accessConfig: [{}], // Assigns an ephemeral public IP
},
],
});
}
}
const app = new App();
new MyGcpStack(app, "gcp-example");
app.synth();