This message was deleted.
# general
s
This message was deleted.
c
I have created a number of dynamic resources so I don't think I am doing anything wrong. Here is the code from the very beginning of my resource I did not get very far I was just making sure I could read the Network Interface information. I am doing this because the behavior of the default resource to attach Network Interfaces does not fit our desired flow. This is a major concern for me if I can't interact with AWS through the sdk at all in custom resources there are so many potential use cases. I can spend some time debugging pulumi I am okay with go but I would need to be pointed in the right direction.
Copy code
import * as pulumi from '@pulumi/pulumi';
import { v4 as uuidv4 } from 'uuid';
import * as _ from 'lodash';
import * as aws_sdk from 'aws-sdk';
let ec2 = new aws_sdk.EC2();

export interface AttachSecurityGroupsArgs {
  /**
   * Security Groups to attach to network interfaces
   */
  securityGroupIds: pulumi.Input<string>[];
  /**
   * Network Interface Id to attache security groups to
   */
  networkInterfaceId?: pulumi.Input<string>;
}

interface State {
  securityGroupIds: pulumi.Unwrap<string>[];
  networkInterfaceId: pulumi.Unwrap<string>;
}

export class AttachSecurityGroups extends pulumi.dynamic.Resource {
  public readonly securityGroupIds!: pulumi.Input<string>[];
  public readonly networkInterfaceId!: pulumi.Input<string>;
  constructor(
    name: string,
    attachSecurityGroupsArgs: AttachSecurityGroupsArgs,
    opts?: pulumi.CustomResourceOptions
  ) {
    const provider: pulumi.dynamic.ResourceProvider = {
      diff: async (id: pulumi.ID, olds: State, news: State) => {
        let changes = true;
        let replacementProperties: string[] = ['securityGroupIds'];
        return {
          changes: changes,
          replaces: replacementProperties.length > 0 ? replacementProperties : undefined,
          deleteBeforeReplace: true,
        };
      },
      create: async (inputs: State) => {
        let networkInterface = await describeNetworkInterface(inputs.networkInterfaceId);
        console.log(networkInterface);
        return { id: uuidv4(), outs: inputs };
      },
      update: async (id: pulumi.ID, inputs: State, olds: State) => {
        return { id: uuidv4(), outs: inputs };
      },
      delete: async (id: pulumi.ID, props: State) => {
        return;
      },
      read: async (id: pulumi.ID, props: State) => {
        return { id: uuidv4(), props: props };
      },
    };
    super(provider, name, attachSecurityGroupsArgs, opts);
  }
}

let describeNetworkInterface = (
  networkInterfaceId: string
): Promise<aws_sdk.EC2.DescribeNetworkInterfacesResult> => {
  return new Promise((resolve, reject) => {
    var params = {
      NetworkInterfaceIds: [networkInterfaceId],
    };
    console.log(params);
    ec2.describeNetworkInterfaces(params, (err, data) => {
      if (err) {
        reject(err);
      } else {
        resolve(data);
      }
    });
  });
};
still hanging 40 minutes in