Skip to content

Commit

Permalink
link: fix edge case where links are not tracked correctly with new
Browse files Browse the repository at this point in the history
linking system
  • Loading branch information
thdxr committed Jul 17, 2024
1 parent a2083c2 commit 64cd149
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
9 changes: 3 additions & 6 deletions pkg/project/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -852,16 +852,13 @@ func getCompletedEvent(ctx context.Context, stack auto.Stack) (*CompleteEvent, e
if hint, ok := outputs["_hint"].(string); ok {
complete.Hints[string(resource.URN)] = hint
}
}

outputs := decrypt(deployment.Resources[0].Outputs).(map[string]interface{})
linksOutput, ok := outputs["_links"]
if ok {
for key, value := range linksOutput.(map[string]interface{}) {
complete.Links[key] = value
if resource.Type == "sst:sst:LinkRef" && outputs["target"] != nil && outputs["properties"] != nil {
complete.Links[outputs["target"].(string)] = outputs["properties"].(map[string]interface{})
}
}

outputs := decrypt(deployment.Resources[0].Outputs).(map[string]interface{})
for key, value := range outputs {
if strings.HasPrefix(key, "_") {
continue
Expand Down
1 change: 0 additions & 1 deletion platform/src/auto/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export async function run(program: automation.PulumiFn) {
});
Link.reset();
const outputs = (await program()) || {};
outputs._links = Link.list();
return outputs;
}

Expand Down
32 changes: 26 additions & 6 deletions platform/src/components/link.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,35 @@
import { Input, Output, runtime, output, all } from "@pulumi/pulumi";
import {
Input,
Output,
runtime,
output,
all,
ComponentResource,
} from "@pulumi/pulumi";
import { FunctionPermissionArgs } from "./aws/function.js";

export module Link {
export interface Definition {
properties: Input<Record<string, any>>;
}

class LinkRef extends ComponentResource {
constructor(target: string, properties: any) {
super(
"sst:sst:LinkRef",
target + "LinkRef",
{
properties,
},
{},
);
this.registerOutputs({
target: output(target),
properties: output(properties),
});
}
}

let links: Record<string, Record<string, any>> = {};
export function reset() {
links = {};
Expand All @@ -18,12 +42,8 @@ export module Link {
if (links[args.name]) {
throw new Error(`Component name ${args.name} is not unique`);
}

const link = resource.getSSTLink();
links[args.name] = output(link.properties).apply((props) => ({
type: args.type.replaceAll(":", "."),
...props,
}));
new LinkRef(args.name, link.properties);
}
});
return {
Expand Down

0 comments on commit 64cd149

Please sign in to comment.