Skip to content

Commit

Permalink
memorydb support (#949)
Browse files Browse the repository at this point in the history
  • Loading branch information
jhsinger-klotho authored Mar 1, 2024
1 parent 129d819 commit 2d21b3c
Show file tree
Hide file tree
Showing 20 changed files with 558 additions and 3,388 deletions.
35 changes: 34 additions & 1 deletion pkg/engine/operational_eval/vertex_edge.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"

construct "github.com/klothoplatform/klotho/pkg/construct"
"github.com/klothoplatform/klotho/pkg/engine/constraints"
"github.com/klothoplatform/klotho/pkg/engine/operational_rule"
"github.com/klothoplatform/klotho/pkg/engine/solution_context"
knowledgebase "github.com/klothoplatform/klotho/pkg/knowledgebase"
Expand Down Expand Up @@ -134,5 +135,37 @@ func (ev *edgeVertex) Evaluate(eval *Evaluator) error {
}
}
}
return errs

if errs != nil {
return errs
}

src, err := eval.Solution.DataflowGraph().Vertex(ev.Edge.Source)
if err != nil {
return err
}
target, err := eval.Solution.DataflowGraph().Vertex(ev.Edge.Target)
if err != nil {
return err
}

delays, err := knowledgebase.ConsumeFromResource(
src,
target,
solution_context.DynamicCtx(eval.Solution),
)
if err != nil {
return err
}
// we add constrains for the delayed consumption here since their property has not yet been evaluated
c := eval.Solution.Constraints()
for _, delay := range delays {
c.Resources = append(c.Resources, constraints.ResourceConstraint{
Operator: constraints.AddConstraintOperator,
Target: delay.Resource,
Property: delay.PropertyPath,
Value: delay.Value,
})
}
return nil
}
27 changes: 27 additions & 0 deletions pkg/infra/iac/templates/aws/memorydb_acl/factory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import * as aws from '@pulumi/aws'
import { ModelCaseWrapper } from '../../wrappers'

interface Args {
Name: string
UserNames: string[]
Tags: ModelCaseWrapper<Record<string, string>>
}

// noinspection JSUnusedLocalSymbols
function create(args: Args): aws.memorydb.Acl {
return new aws.memorydb.Acl(args.Name, {
//TMPL {{- if .UserNames }}
userNames: args.UserNames,
//TMPL {{- end }}
//TMPL {{- if .Tags }}
tags: args.Tags,
//TMPL {{- end }}
})
}

function properties(object: aws.memorydb.Acl, args: Args) {
return {
Arn: object.arn,
Id: object.id,
}
}
6 changes: 6 additions & 0 deletions pkg/infra/iac/templates/aws/memorydb_acl/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "memorydb_acl",
"dependencies": {
"@pulumi/aws": "^5.37.0"
}
}
103 changes: 103 additions & 0 deletions pkg/infra/iac/templates/aws/memorydb_cluster/factory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import * as aws from '@pulumi/aws'
import { ModelCaseWrapper } from '../../wrappers'
import * as pulumi from '@pulumi/pulumi'

interface Args {
Name: string
Acl: string
NodeType: string
AutoMinorVersionUpgrade: boolean
DataTiering: string
Description: string
EngineVersion: string
FinalSnapshotName: string
MaintenanceWindow: string
NumReplicasPerShard: number
NumShards: number
ParameterGroupName: string
Port: number
SecurityGroups: aws.ec2.SecurityGroup[]
SnapshotArns: string[]
SnapshotName: string
SnapshotRetentionLimit: number
SnapshotWindow: string
SubnetGroup: aws.memorydb.SubnetGroup
Tags: ModelCaseWrapper<Record<string, string>>
TlsEnabled: boolean
}

// noinspection JSUnusedLocalSymbols
function create(args: Args): aws.memorydb.Cluster {
return new aws.memorydb.Cluster(args.Name, {
aclName: args.Acl,
nodeType: args.NodeType,
//TMPL {{- if .AutoMinorVersionUpgrade }}
autoMinorVersionUpgrade: args.AutoMinorVersionUpgrade,
//TMPL {{- end }}
//TMPL {{- if .DataTiering }}
dataTiering: args.DataTiering,
//TMPL {{- end }}
//TMPL {{- if .Description }}
description: args.Description,
//TMPL {{- end }}
//TMPL {{- if .EngineVersion }}
engineVersion: args.EngineVersion,
//TMPL {{- end }}
//TMPL {{- if .FinalSnapshotName }}
finalSnapshotName: args.FinalSnapshotName,
//TMPL {{- end }}
//TMPL {{- if .MaintenanceWindow }}
maintenanceWindow: args.MaintenanceWindow,
//TMPL {{- end }}
//TMPL {{- if .NumReplicasPerShard }}
numReplicasPerShard: args.NumReplicasPerShard,
//TMPL {{- end }}
//TMPL {{- if .NumShards }}
numShards: args.NumShards,
//TMPL {{- end }}
//TMPL {{- if .ParameterGroupName }}
parameterGroupName: args.ParameterGroupName,
//TMPL {{- end }}
//TMPL {{- if .Port }}
port: args.Port,
//TMPL {{- end }}
//TMPL {{- if .SecurityGroups }}
securityGroupIds: args.SecurityGroups.map((sg) => sg.id),
//TMPL {{- end }}
//TMPL {{- if .SnapshotArns }}
snapshotArns: args.SnapshotArns,
//TMPL {{- end }}
//TMPL {{- if .SnapshotName }}
snapshotName: args.SnapshotName,
//TMPL {{- end }}
//TMPL {{- if .SnapshotRetentionLimit }}
snapshotRetentionLimit: args.SnapshotRetentionLimit,
//TMPL {{- end }}
//TMPL {{- if .SnapshotWindow }}
snapshotWindow: args.SnapshotWindow,
//TMPL {{- end }}
//TMPL {{- if .SubnetGroup }}
subnetGroupName: args.SubnetGroup.name,
//TMPL {{- end }}
//TMPL {{- if .Tags }}
tags: args.Tags,
//TMPL {{- end }}
//TMPL {{- if .TlsEnabled }}
tlsEnabled: args.TlsEnabled,
//TMPL {{- end }}
})
}

function properties(object: aws.memorydb.Cluster, args: Args) {
return {
Arn: object.arn,
ClusterEndpoints: object.clusterEndpoints,
ClusterEndpointString: pulumi.interpolate`${object.clusterEndpoints.apply((endpoints) => {
const endpointStrings: string[] = []
for (const endpoint of endpoints) {
endpointStrings.push(`${endpoint.address}:${endpoint.port}`)
}
return endpointStrings.join(',')
})}`,
}
}
7 changes: 7 additions & 0 deletions pkg/infra/iac/templates/aws/memorydb_cluster/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "memorydb_cluster",
"dependencies": {
"@pulumi/aws": "^5.37.0",
"@pulumi/pulumi": "^3.69.0"
}
}
30 changes: 30 additions & 0 deletions pkg/infra/iac/templates/aws/memorydb_subnetgroup/factory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import * as aws from '@pulumi/aws'
import * as awsInputs from '@pulumi/aws/types/input'
import { ModelCaseWrapper } from '../../wrappers'

interface Args {
Name: string
Subnets: aws.ec2.Subnet[]
Description: string
Tags: ModelCaseWrapper<Record<string, string>>
}

// noinspection JSUnusedLocalSymbols
function create(args: Args): aws.memorydb.SubnetGroup {
return new aws.memorydb.SubnetGroup(args.Name, {
subnetIds: args.Subnets.map((subnet) => subnet.id),
//TMPL {{- if .Description }}
description: args.Description,
//TMPL {{- end }}
//TMPL {{- if .Tags }}
tags: args.Tags,
//TMPL {{- end }}
})
}

function properties(object: aws.memorydb.SubnetGroup, args: Args) {
return {
Arn: object.arn,
Id: object.id,
}
}
6 changes: 6 additions & 0 deletions pkg/infra/iac/templates/aws/memorydb_subnetgroup/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "memorydb_subnetgroup",
"dependencies": {
"@pulumi/aws": "^5.37.0"
}
}
35 changes: 35 additions & 0 deletions pkg/infra/iac/templates/aws/memorydb_user/factory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import * as aws from '@pulumi/aws'
import * as awsInputs from '@pulumi/aws/types/input'
import { ModelCaseWrapper } from '../../wrappers'
import * as pulumi from '@pulumi/pulumi'

interface Args {
Name: string
AccessString: string
AuthenticationMode: awsInputs.memorydb.UserAuthenticationMode
Tags: ModelCaseWrapper<Record<string, string>>
}

// noinspection JSUnusedLocalSymbols
function create(args: Args): aws.memorydb.User {
return new aws.memorydb.User(args.Name, {
accessString: args.AccessString,
authenticationMode: {
type: 'password',
passwords: [kloConfig.requireSecret(`${args.Name}-password`)],
},
userName: args.Name,
//TMPL {{- if .Tags }}
tags: args.Tags,
//TMPL {{- end }}
})
}

function properties(object: aws.memorydb.User, args: Args) {
return {
Arn: object.arn,
Id: object.id,
Username: object.userName,
Password: kloConfig.requireSecret(`${args.Name}-password`),
}
}
7 changes: 7 additions & 0 deletions pkg/infra/iac/templates/aws/memorydb_user/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "memorydb_user",
"dependencies": {
"@pulumi/aws": "^5.37.0",
"@pulumi/pulumi": "^3.69.0"
}
}
Loading

0 comments on commit 2d21b3c

Please sign in to comment.