Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/v2/components/database/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as awsx from '@pulumi/awsx-v3';
import * as pulumi from '@pulumi/pulumi';
import { Password } from '../password';
import { commonTags } from '../../../constants';
import { mergeWithDefaults } from '../../shared/merge-with-defaults';

export namespace Database {
export type Instance = {
Expand Down Expand Up @@ -72,7 +73,7 @@ export class Database extends pulumi.ComponentResource {

this.name = name;

const argsWithDefaults = Object.assign({}, defaults, args);
const argsWithDefaults = mergeWithDefaults(defaults, args);
const { vpc, kmsKeyId, enableMonitoring, snapshotIdentifier } =
argsWithDefaults;

Expand Down
3 changes: 2 additions & 1 deletion src/v2/components/ecs-service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as aws from '@pulumi/aws-v7';
import * as awsx from '@pulumi/awsx-v3';
import { CustomSize, Size } from '../../../types/size';
import { PredefinedSize, commonTags } from '../../../constants';
import { mergeWithDefaults } from '../../shared/merge-with-defaults';
import { assumeRolePolicy } from './policies';

const config = new pulumi.Config('aws');
Expand Down Expand Up @@ -192,7 +193,7 @@ export class EcsService extends pulumi.ComponentResource {
opts: pulumi.ComponentResourceOptions = {},
) {
super('studion:ecs:Service', name, {}, opts);
const argsWithDefaults = Object.assign({}, defaults, args);
const argsWithDefaults = mergeWithDefaults(defaults, args);
const taskExecutionRoleInlinePolicies = pulumi.output(
args.taskExecutionRoleInlinePolicies ||
defaults.taskExecutionRoleInlinePolicies,
Expand Down
3 changes: 2 additions & 1 deletion src/v2/components/redis/elasticache-redis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as aws from '@pulumi/aws-v7';
import * as pulumi from '@pulumi/pulumi';
import * as awsx from '@pulumi/awsx-v3';
import { commonTags } from '../../../constants';
import { mergeWithDefaults } from '../../shared/merge-with-defaults';

type RedisArgs = {
vpc: pulumi.Input<awsx.ec2.Vpc>;
Expand Down Expand Up @@ -44,7 +45,7 @@ export class ElastiCacheRedis extends pulumi.ComponentResource {
opts: pulumi.ComponentResourceOptions = {},
) {
super('studion:Redis:ElastiCache', name, {}, opts);
const argsWithDefaults = Object.assign({}, defaults, args);
const argsWithDefaults = mergeWithDefaults(defaults, args);

this.name = name;
this.vpc = pulumi.output(argsWithDefaults.vpc);
Expand Down
9 changes: 4 additions & 5 deletions src/v2/components/redis/upstash-redis.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as pulumi from '@pulumi/pulumi';
import * as upstash from '@upstash/pulumi';
import { Password } from '../../../components/password';
import { mergeWithDefaults } from '../../shared/merge-with-defaults';

export type RedisArgs = {
dbName: pulumi.Input<string>;
Expand Down Expand Up @@ -37,15 +38,13 @@ export class UpstashRedis extends pulumi.ComponentResource {
) {
super('studion:Redis:Upstash', name, {}, opts);

const argsWithDefaults = Object.assign({}, defaults, args);

const dbName =
argsWithDefaults.dbName ?? `${pulumi.getProject()}-${pulumi.getStack()}`;
const dbName = `${pulumi.getProject()}-${pulumi.getStack()}`;
const argsWithDefaults = mergeWithDefaults({ ...defaults, dbName }, args);

this.instance = new upstash.RedisDatabase(
name,
{
databaseName: dbName,
databaseName: argsWithDefaults.dbName,
region: argsWithDefaults.region,
primaryRegion: argsWithDefaults.primaryRegion,
eviction: true,
Expand Down
3 changes: 2 additions & 1 deletion src/v2/components/vpc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as pulumi from '@pulumi/pulumi';
import * as awsx from '@pulumi/awsx-v3';
import { commonTags } from '../../../constants';
import { enums } from '@pulumi/awsx-v3/types';
import { mergeWithDefaults } from '../../shared/merge-with-defaults';

export type VpcArgs = {
/**
Expand All @@ -28,7 +29,7 @@ export class Vpc extends pulumi.ComponentResource {
) {
super('studion:Vpc', name, {}, opts);

const argsWithDefaults = Object.assign({}, defaults, args);
const argsWithDefaults = mergeWithDefaults(defaults, args);

this.vpc = new awsx.ec2.Vpc(
`${name}-vpc`,
Expand Down
8 changes: 5 additions & 3 deletions src/v2/components/web-server/load-balancer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as pulumi from '@pulumi/pulumi';
import * as aws from '@pulumi/aws-v7';
import * as awsx from '@pulumi/awsx-v3';
import { commonTags } from '../../../constants';
import { mergeWithDefaults } from '../../shared/merge-with-defaults';

export namespace WebServerLoadBalancer {
export type Args = {
Expand Down Expand Up @@ -59,8 +60,9 @@ export class WebServerLoadBalancer extends pulumi.ComponentResource {

this.name = name;
const vpc = pulumi.output(args.vpc);
const argsWithDefaults = mergeWithDefaults(defaults, args);
const { port, certificate, healthCheckPath, loadBalancingAlgorithmType } =
args;
argsWithDefaults;

this.securityGroup = this.createLbSecurityGroup(vpc.vpcId);

Expand Down Expand Up @@ -160,7 +162,7 @@ export class WebServerLoadBalancer extends pulumi.ComponentResource {
private createLbTargetGroup(
port: pulumi.Input<number>,
vpcId: awsx.ec2.Vpc['vpcId'],
healthCheckPath: pulumi.Input<string> | undefined,
healthCheckPath: pulumi.Input<string>,
loadBalancingAlgorithmType?: pulumi.Input<string>,
): aws.lb.TargetGroup {
return new aws.lb.TargetGroup(
Expand All @@ -177,7 +179,7 @@ export class WebServerLoadBalancer extends pulumi.ComponentResource {
unhealthyThreshold: 2,
interval: 60,
timeout: 5,
path: healthCheckPath || defaults.healthCheckPath,
path: healthCheckPath,
},
tags: { ...commonTags, Name: `${this.name}-target-group` },
},
Expand Down
10 changes: 10 additions & 0 deletions src/v2/shared/merge-with-defaults.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export function mergeWithDefaults<
T extends Record<PropertyKey, unknown>,
U extends Record<PropertyKey, unknown>,
>(defaults: T, args: U): T & U {
const argsWithoutUndefined = Object.fromEntries(
Object.entries(args).filter(([, value]) => value !== undefined),
) as U;

return Object.assign({}, defaults, argsWithoutUndefined);
}