Thread
#general
    l

    late-energy-66663

    7 months ago
    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:
    Machine 1
    hostname: <http://ec2-15-161-152-141.eu-south-1.compute.amazonaws.com|ec2-15-161-152-141.eu-south-1.compute.amazonaws.com>
    Public ip : 15.161.152.141
    Machine2
    hostname: <http://ec2-15-160-154-234.eu-south-1.compute.amazonaws.com|ec2-15-160-154-234.eu-south-1.compute.amazonaws.com>
    Public ip : 15.160.154.234
    Current 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:
    publicHostName0: "<http://ec2-15-161-152-141.eu-south-1.compute.amazonaws.com|ec2-15-161-152-141.eu-south-1.compute.amazonaws.com>"
    publicHostName1: "<http://ec2-15-160-154-234.eu-south-1.compute.amazonaws.com|ec2-15-160-154-234.eu-south-1.compute.amazonaws.com>"
    
        publicIp0      : "15.161.152.141"
        publicIp1      : "15.160.154.234"
    Hi Team, would appreciate any answer on the question