-
-
Save 1oglop1/5719c1fd11760472efe2b6af76bcec0b to your computer and use it in GitHub Desktop.
diffable container definition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Previewing update (test): pulumi:pulumi:Stack: (same) | |
[urn=urn:pulumi:test::dummy::pulumi:pulumi:Stack::dummy-test] error: Duplicate resource URN 'urn:pulumi:test::dummy::pulumi-nodejs:dynamic:Resource::v3'; try giving it a unique name | |
~ pulumi-nodejs:dynamic:Resource: (update) | |
[id=foo] | |
[urn=urn:pulumi:test::dummy::pulumi-nodejs:dynamic:Resource::v3] | |
~ taskDefArgs: { | |
~ containerDefinitions: { | |
~ asd : { | |
~ command: [ | |
~ [0]: "aaa" => "aaaaa" | |
] | |
} | |
+ asdf : { | |
+ command : [ | |
+ [0]: "bbbbb" | |
] | |
+ entryPoint : [ | |
+ [0]: "bb" | |
] | |
+ essential : false | |
+ image : "hashicorp/http-echo" | |
+ name : (yaml) [ | |
+ [0]: "secret" | |
] | |
} | |
- works: { | |
- command : [ | |
- [0]: "bbbb" | |
] | |
- entryPoint : [ | |
- [0]: "bb" | |
] | |
- essential : false | |
- image : "hashicorp/http-echo" | |
- name : "works" | |
} | |
} | |
} | |
Resources: | |
~ 1 to update | |
1 unchanged |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as awsnative from "@pulumi/aws-native"; | |
import * as pulumi from "@pulumi/pulumi"; | |
const image = "hashicorp/http-echo"; | |
const cfg = new pulumi.Config(); | |
const str = cfg.require<string>("str"); | |
const str2 = cfg.require<string>("str2"); | |
const environment: awsnative.types.input.ecs.TaskDefinitionKeyValuePairArgs[] = [ | |
{ name: "a", value: str2 }, | |
{ name: "c", value: str2 }, | |
{ name: "p", value: str2 }, | |
{ name: str2, value: "omg" }, | |
{ name: "x", value: str2 }, | |
]; | |
const containerDefinitions: awsnative.types.input.ecs.TaskDefinitionContainerDefinitionArgs[] = [ | |
{ | |
name: str, // this replaced 'a' | |
image, | |
essential: true, | |
entryPoint: ["3"], | |
command: ["aaa"], | |
environment, | |
}, | |
{ | |
name: pulumi.output<string>("asdf").apply((x) => x.toString()), // if this is an output/promise -> sandess | |
// name: "works", // this replaced 'b' | |
image, | |
essential: false, | |
entryPoint: ["bb"], | |
command: ["bbbbb"], | |
}, | |
{ | |
name: "b2", | |
image, | |
// essential: false, | |
entryPoint: ["b2b"], | |
}, | |
{ | |
name: "c", | |
image, | |
// essential: true | |
}, | |
{ | |
name: "d", | |
image, | |
essential: false, | |
entryPoint: ["ddd"], | |
}, | |
]; | |
type CustomResourceArgs = { | |
taskDefArgs: awsnative.ecs.TaskDefinitionArgs; | |
}; | |
type DiffableTaskDefArgs = Omit<awsnative.ecs.TaskDefinitionArgs, "containerDefinitions"> & { | |
containerDefinitions: Record<string, DiffableContainerDef>; | |
}; | |
type DiffableContainerDef = Omit<awsnative.types.input.ecs.TaskDefinitionContainerDefinitionArgs, "environment"> & { | |
environment: Record<string, string>; | |
}; | |
type ConvertedCustomResourceArgs = { | |
taskDefArgs: pulumi.Input<DiffableTaskDefArgs>; | |
}; | |
type ProviderInputs = unknown; | |
type ProviderOutputs = ProviderInputs; | |
class MyProvider implements pulumi.dynamic.ResourceProvider { | |
private readonly name: string; | |
constructor(name: string) { | |
this.name = name; | |
} | |
async check(olds: ProviderInputs, news: ProviderInputs): Promise<pulumi.dynamic.CheckResult> { | |
return { | |
inputs: news, | |
}; | |
} | |
async create(inputs: ProviderInputs): Promise<pulumi.dynamic.CreateResult> { | |
const outs: ProviderOutputs = inputs; | |
return { id: "foo", outs }; | |
} | |
async update( | |
id: string, | |
currentOutputs: ProviderOutputs, | |
newInputs: ProviderInputs | |
): Promise<pulumi.dynamic.UpdateResult> { | |
const outs: ProviderOutputs = newInputs; | |
return { outs }; | |
} | |
} | |
const myProvider = new MyProvider("myProvider"); | |
class MyResource extends pulumi.dynamic.Resource { | |
public readonly taskDefArgs: pulumi.Output<DiffableTaskDefArgs> | |
constructor(name: string, args: CustomResourceArgs, opts?: pulumi.CustomResourceOptions) { | |
let inputs = convert(args); | |
super(myProvider, name, inputs, opts); | |
} | |
} | |
function convert(args: CustomResourceArgs): ConvertedCustomResourceArgs { | |
let taskDefArgs = pulumi.output(args.taskDefArgs).apply((unwrapped) => { | |
let containerDefinitions = (unwrapped.containerDefinitions || []).reduce((containerDefObj, containerDef) => { | |
let environment = (containerDef.environment || []).reduce((envObj, kv) => { | |
if (kv.name && kv.value) { | |
envObj[kv.name] = kv.value; | |
} | |
return envObj; | |
}, {} as Record<string, string>); | |
containerDefObj[containerDef.name] = { ...containerDef, environment }; | |
return containerDefObj; | |
}, {} as Record<string, DiffableContainerDef>); | |
return { ...args.taskDefArgs, containerDefinitions }; | |
}); | |
return { taskDefArgs }; | |
} | |
export function v3() { | |
const mr = new MyResource("v3", { taskDefArgs: { containerDefinitions } }); | |
mr.taskDefArgs.apply(console.log) | |
} | |
v3() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment