diff --git a/backend/src/terraform/awsSubnet.ts b/backend/src/terraform/awsSubnet.ts index 443c9ab..7b8d680 100644 --- a/backend/src/terraform/awsSubnet.ts +++ b/backend/src/terraform/awsSubnet.ts @@ -1,11 +1,12 @@ import {jsonRoot} from "./util"; import {Resource} from "./resource"; +import {awsZone, char} from "../types/terraform"; export interface AwsSubnet { vpc: string; cidr_block: string; map_public_ip_on_launch: boolean; - availability_zone: string; + availability_zone: `${awsZone}${char}`; } export class AwsSubnet extends Resource implements AwsSubnet { @@ -14,7 +15,7 @@ export class AwsSubnet extends Resource implements AwsSubnet { cidr_block: string, map_public_ip_on_launch: boolean, id: string, - availability_zone = "us-west-2a", + availability_zone: `${awsZone}${char}` = "us-west-2a", autoIam?: boolean, name?: string ) { diff --git a/backend/src/terraform/gce.ts b/backend/src/terraform/gce.ts index 5202dcf..b2ccf5f 100644 --- a/backend/src/terraform/gce.ts +++ b/backend/src/terraform/gce.ts @@ -1,11 +1,11 @@ -import {machineType} from "../types/terraform"; +import {machineType, gcpZone} from "../types/terraform"; import {jsonRoot} from "./util"; import {Resource} from "./resource"; export interface Gce { project: string; machine_type: machineType; - zone: string; + zone: gcpZone; disk_image: string; } export class Gce extends Resource implements Gce { @@ -20,7 +20,7 @@ export class Gce extends Resource implements Gce { id: string, machine_type: machineType, disk_image: string, - zone = "us-west1-a" + zone: gcpZone = "us-west1-a" ) { super(id, "Gce"); this.project = project; diff --git a/backend/src/terraform/googleProvider.ts b/backend/src/terraform/googleProvider.ts index 8c621aa..d48ef6f 100644 --- a/backend/src/terraform/googleProvider.ts +++ b/backend/src/terraform/googleProvider.ts @@ -3,14 +3,16 @@ import {DatabaseModel, generateSchema} from "../types/database"; import { named, NamedRequiredProvider, - RequiredProvider + RequiredProvider, + gcpZone, + gcpRegion } from "../types/terraform"; import {removeName} from "./util"; export interface GoogleProvider extends named { project: string; - region?: string; - zone?: string; + region?: gcpRegion; + zone?: gcpZone; credentials?: string; } export class GoogleProvider @@ -20,14 +22,14 @@ export class GoogleProvider name: "google"; constructor(project: string); - constructor(project: string, region: string); - constructor(project: string, region: string, zone: string); + constructor(project: string, region: gcpRegion); + constructor(project: string, region: gcpRegion, zone: gcpZone); constructor( project: string, source = "hashicorp/google", version = ">= 4.10.0", - region = "us-west1", - zone: string | null = null, + region: gcpRegion = "us-west1", + zone: gcpZone | null = null, credentials: string | null = null ) { super(source, version, "google"); diff --git a/backend/src/types/terraform.ts b/backend/src/types/terraform.ts index bd615fc..6112a52 100644 --- a/backend/src/types/terraform.ts +++ b/backend/src/types/terraform.ts @@ -296,6 +296,39 @@ export interface Firewall { cidr_blocks?: string[]; } +export type char = + | "a" + | "b" + | "c" + | "d" + | "e" + | "f" + | "g" + | "h" + | "i" + | "j" + | "k" + | "l" + | "m" + | "n" + | "o" + | "p" + | "q" + | "r" + | "s" + | "t" + | "u" + | "v" + | "w" + | "x" + | "y" + | "z"; +export type digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"; +export type countryCode = "us" | "af" | "ap" | "ca" | "eu" | "me" | "sa"; +export type awsZone = `${countryCode}-${string}-${digit}`; +export type gcpRegion = `${string}-${string}${digit}`; +export type gcpZone = `${string}-${string}${digit}-${char}`; + // ----------------------------Terraform Root-------------------------------- // export interface Terraform {