# general


02/05/2022, 6:19 PM
Hi I am creating multiple EC2 multiple instances with following Code . I would like to export , publicip, ec2name , hostname for each ec2 machine in a separate record . I am creating a ec2.Instance slice and then exporting their value . What would be the best way to get the output in the following format, desired output:
Copy code
Machine 1
hostname: <|>
Public ip :
hostname: <|>
Public ip :
Current Code :
Copy code
var nodeList []*ec2.Instance

for i := 1; i <= args.NumberOfNodes; i++ {
   vm.Instance, err = ec2.NewInstance(ctx, fmt.Sprintf("machine-%d", i), &ec2.InstanceArgs{
      Tags: pulumi.StringMap{"Name": pulumi.String(fmt.Sprintf("kafka-%d", i))},
      //InstanceType:        pulumi.String("t3.large"),
      InstanceType:        args.InstanceType,
      VpcSecurityGroupIds: pulumi.StringArray{vm.SecurityGroup.ID()},
      Ami:                 pulumi.String("ami-0f8ce9c417115413d"),
      UserData:            userData,
      KeyName:             deployer.KeyName,
   if err != nil {
      panic("error creating ec2 instance")
   nodeList = append(nodeList, vm.Instance)

for k, v := range nodeList {
   ctx.Export("publicIp"+strconv.Itoa(k), v.PublicIp)
   ctx.Export("publicHostName"+strconv.Itoa(k), v.PublicDns)

Current Outputs:
Copy code
publicHostName0: "<|>"
publicHostName1: "<|>"

    publicIp0      : ""
    publicIp1      : ""
Hi Team, would appreciate any answer on the question