ArticCon 2022 (continued)
transforming it
This can be as simple as a function with some nested loops. In typescript it still winds up being a nested loop, but additionally we can use the type system to enforce some guarantees around our data structures.
import { topo, peers, firewall } from './config';
export class GcpNetworkingConfig implements NetworkDefinition {
topo = topo;
peers = peers;
firewall = firewall;
config: NetworkConfig<S, N<S>>;
constructor(project: Project) {
this.config =
// for vpc in topo
[vpc]: {
project: project.name,
subnets: {
// for subnet in vpc.subNets
[subnet]: {
config: {
project: project.name,
ipCidrRange: this.topo[vpc].subNets[subnet].cidr,
gatewayAddress: this.topo[vpc].subNets[subnet].cidr,
},
},
}
}