Skip to main content

Infrastructure Components

The infrastructure is organized into modular components, each responsible for a specific set of GCP resources. Components are built using Pulumi's ComponentResource pattern for reusability and clear dependency management.

Component Architecture

Component Pattern

Each component follows a consistent TypeScript pattern:

import * as pulumi from '@pulumi/pulumi';
import * as gcp from '@pulumi/gcp';

// Configuration interface
export interface ComponentConfig {
projectId: string;
region: string;
// Component-specific config...
}

// Output interface
export interface ComponentOutputs {
resourceId: pulumi.Output<string>;
resourceName: pulumi.Output<string>;
// Component-specific outputs...
}

// Component class
export class Component extends pulumi.ComponentResource {
public readonly resource: gcp.SomeResource;

constructor(
name: string,
config: ComponentConfig,
opts?: pulumi.ComponentResourceOptions
) {
super('serko:gcp:Component', name, {}, opts);

// Create resources...
this.resource = new gcp.SomeResource(name, {
// configuration...
}, { parent: this });

this.registerOutputs({
resourceId: this.resource.id,
});
}

public getOutputs(): ComponentOutputs {
return {
resourceId: this.resource.id,
resourceName: this.resource.name,
};
}
}

Available Components

ComponentSource FilePurpose
Networksrc/gcp/network.tsVPC, subnets, firewall, NAT
GKEsrc/gcp/gke.tsKubernetes Autopilot cluster
Artifact Registrysrc/gcp/artifact-registry.tsDocker image repository
AlloyDBsrc/gcp/alloydb.tsPostgreSQL database cluster
Memorystoresrc/gcp/memorystore.tsRedis cache
Cloud Storagesrc/gcp/gcs.tsObject storage buckets
IAMsrc/gcp/iam.tsService accounts and roles
Secretssrc/gcp/secrets.tsSecret Manager

Dependency Order

Components must be created in a specific order due to dependencies:

  1. GCP APIs - Enable required services
  2. Network - VPC and networking foundation
  3. IAM - Service accounts (needed for GKE workload identity)
  4. GKE - Kubernetes cluster (depends on network)
  5. Artifact Registry - Container registry
  6. Cloud Storage - Storage buckets
  7. AlloyDB - Database (depends on network private service connection)
  8. Memorystore - Redis cache (depends on network)
  9. Secrets - Secrets with connection strings (depends on databases)

Main Entry Point

The src/index.ts file orchestrates component creation:

// Enable APIs first
const apis = new GcpApis('apis', { projectId });

// Create network
const network = new Network('network', networkConfig, {
dependsOn: [apis],
});

// Create GKE cluster
const gke = new GkeCluster('gke', gkeConfig, {
dependsOn: [network],
});

// Continue with other components...