Is there an any example to run SSH commands in Dyn...
# general
m
Is there an any example to run SSH commands in Dynamic provider's CRUD operation? I'm trying to manage CLI based application through pulumi. For example dynamic provider's create: function will run create command on the server etc.. I looked through ec2-provisioners example, I can't comprehend it well. Here is my
create
function implementation. SSH connection part just doesn't run. Any guidance will be much appreciated.
Copy code
import * as pulumi from '@pulumi/pulumi';
import { Client } from 'ssh2';

interface MyProviderInputs {
  readonly username: string;
}

export class MyProvider implements pulumi.dynamic.ResourceProvider {
  async create(
    inputs: MyProviderInputs
  ): Promise<pulumi.dynamic.CreateResult> {
    const conn = new Client();

    conn
      .on('ready', () => {
        console.log('Client :: ready');
        conn.exec('./create-user.py', (err, stream) => {
          if (err) throw err;
          stream
            .on('close', (code: any, signal: any) => {
              console.log(
                'Stream :: close :: code: ' + code + ', signal: ' + signal
              );
              conn.end();
            })
            .on('data', (data: any) => {
              console.log('User created ...')
            })
            .stderr.on('data', (data) => {
              console.log('STDERR: ' + data);
            });
        });
      })
      .on('error', (err) => {
        throw err;
      });

    conn.connect({
      host: '10.10.2.2',
      username: 'ubuntu',
      password: '123'
    });

    return {
      id: '1',
      outs: inputs,
    };
  }
}