async routeTableOperations()

in source/networkFirewallAutomation/lib/ec2-manager.ts [52:88]


  async routeTableOperations(): Promise<routeStatus[]> {
    try {
      let response: routeStatus[] = []
      for (let endpoint of this.envProps) {
        Logger.log(LOG_LEVEL.INFO, `Processing `, endpoint)

        // check if routes already exist
        if (endpoint.routeTableId && endpoint.availabilityZone) {
          const attachmentProps = this.firewallSyncStates[endpoint.availabilityZone]
          this.vpcEndpoint = attachmentProps.Attachment?.EndpointId
          const foundExistingRoute = await this.checkRouteTable(endpoint.routeTableId)

          if (!foundExistingRoute) {
            Logger.log(LOG_LEVEL.INFO, `Default route to Network Firewall does not exist. Creating a new default route using endpoint: ${this.vpcEndpoint} in the ready state.`)
            await this.service.createRoute({
              DestinationCidrBlock: Route.default,
              VpcEndpointId: this.vpcEndpoint,
              RouteTableId: endpoint.routeTableId
            })
          }
          let status = {
            VpcEndpointId: this.vpcEndpoint,
            RouteTableId: endpoint.routeTableId,
            DefaultRouteCreated: !foundExistingRoute
          }
          response.push(status)
        }
      }

      return response

    } catch
      (error) {
      Logger.log(LOG_LEVEL.ERROR, error)
      throw new Error(error["message"])
    }
  }