Hey folks! I’m trying to automate making changes t...
# typescript
Hey folks! I’m trying to automate making changes to a git repo via pulumi, but I’m having issues. I created a dynamic provider in TypeScript that uses
to call out to a bash script, but it seems like the “black magic” that pulumi resorts to for dynamic providers doesn’t like
. Is there any way around that? What I need to do is clone a git repo into a temp dir, copy some files in a branch, commit, push and create a PR using the GitHub CLI. The bash script does all of that very nicely, if only I could invoke it! 🤔
we are using this inside a custom resource class and not in a dynamic provider, in our case to render a helm chart
const SPAWN_PROCESS_BUFFER_SIZE = 104857600;
const helmArgs = [
--version 3.15.2
--namespace default
--repo <https://kubernetes.github.io/ingress-nginx>
--set controller.service.annotations."service\\\.beta\\\.kubernetes\\\.io/azure-load-balancer-internal"=true
--set controller.service.loadBalancerIP=${props.backendIpAddress}
, ].join(" "); const helmCmd = `helm template ${name} ingress-nginx ${helmArgs}`; console.log(helmCmd) const rendered = child_process.execSync(helmCmd, { maxBuffer: SPAWN_PROCESS_BUFFER_SIZE }).toString(); new k8s.yaml.ConfigGroup(name, { yaml: rendered, }, { provider: cluster, customTimeouts: { create: "30m" }, parent: this, });
Yes indeed, that’s ok when your process invocation can be made on every
pulumi up
, however in our case, we need to call the external script only when the resource is created, and we have another script that needs to be called when the resource gets deleted. Hence the need for a dynamic provider, which handles that life-cycle. Unfortunately, currently, dynamic providers seem to be rather limited in what you can do with them, because of the special tricks that pulumi pulls behind the scene to make them execute within the pulumi engine! 😕
What’s the problem or error you’re actually getting? We have an example of a dynamic provider using
at https://github.com/pulumi/examples/blob/3736042d67c422d703b97cef4fc63b91aca3273a/azure-ts-static-website/staticWebsite.ts#L46 that works just fine.
@future-nail-59564 This worked on windows for me.
Copy code
import * as pulumi from "@pulumi/pulumi";
import * as child from 'child_process';

const myProvider: pulumi.dynamic.ResourceProvider = {
    async create(inputs) {
        var foo: child.ChildProcess = child.exec("powershell ./test.ps1", (error: any, stdout: string, stderr: string) => {
        return { id: "foo", outs: {} };
class MyResource extends pulumi.dynamic.Resource {
    constructor(name: string, props: {}, opts?: pulumi.CustomResourceOptions) {
        super(myProvider, name, props, opts);
let x = new MyResource('thisisatest', {});
export const makes = x;
part of the output
Copy code
  pulumi:pulumi:Stack (pulumi-company1):
        Directory: C:\Users\abrothers\Desktop\pulumi
    Mode                 LastWriteTime         Length Name
    ----                 -------------         ------ ----
    -a----         2/19/2021  10:12 AM              0 i_came_from_a_script.txt
test.ps1 just
Copy code
New-Item $PSScriptRoot\i_came_from_a_script.txt
Some gotchas i encountered: 1. notice i'm on windows but had to forward slash the powershell invocation
even though cmd on windows wants
2. i found that i needed
infront of the script These probably get simplified on non windows
Thanks @gentle-monitor-55086, will try to figure if I’m doing something different… @gentle-diamond-70147: I’m getting this error:
And this is my dynamic provider:
Thank you all for confirming that it should work! It gave me confidence to keep digging and I finally figured that it was the call to
that made it break. More specifically, moving the call to
directly into the
functions fixed the error! Thank you so much for your support! 🎉
🙌 1
👍 1
nice! i fell down a rabbit whole of trying to get VS2019 to let me debug. Glad you got it working
👍 1