Skip to content

Config should live in entry point file, use a specified shape and type checking. #3

@a-bigelow

Description

@a-bigelow

To start, I am offering to implement this refactor -- gauging interest here first.

Currently the config for the server lives in a config.ts file that the user must copy from the sample.

What I propose is for stack config to live in the CDK App entry point file, in this case server-hosting.ts. This would look similar to the below:

#!/usr/bin/env node
import 'source-map-support/register';
import * as cdk from 'aws-cdk-lib';
import { ServerHostingStack } from './server-hosting-stack';

const app = new cdk.App();
new ServerHostingStack(app, 'ServerHostingStack', {
  env: { account: Config.account, region: Config.region},
  prefix: 'SatisfactoryHosting',
  restartApi: true,
  useExperimentalBuild: false,
  bucketName: 'someBucket',
  vpcId: 'vpc-abc123youandme',
  subnetId: 'subnet-blablabla',
  availabilityZone: 'us-east-1a',
});

To get this to work, we just need to implement an extension of the StackProps interface:

interface satisfactoryStackProps extends StackProps {
  /**
   * Prefix for all named components of this stack.
   */
  prefix: string,
  /**
   * Whether or not to create the server-restart API
   */
  restartApi: boolean,
  /**
   * Whether or not to use the Satisfactory Experimental Build
   */
  useExperimentalBuild: boolean,
  /**
   * Name of the S3 buckt to use for server backups.
   * @default - A new bucket is created and used.
   */
  bucketName?: string,
  /**
   * ID of the VPC in which to host the Instance.
   * @default - the default VPC for your given region is used.
   */
  vpcId?: string,
  /**
   * The subnet where your instance will be placed.
   * NOTE: If you have already defined availabilityZone, this is redundant.
   * @default - a random public subnet from your VPC is selected.
   */
  subnetId?: string,
  /**
   * The Availability zone in which to host your server.
   * NOTE: If you have already defined subnetId, this is redundant.
   */
  availabilityZone?: string,
}

Then we tell the stack itself to use that interface instead, and we're good to go.

export class ServerHostingStack extends Stack {
  constructor(scope: Construct, id: string, props?: satisfactoryStackProps) {
    super(scope, id, props);

Let me know your thoughts. Happy to implement this (or a version of it).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions