https://pulumi.com logo
Docs
Join the conversationJoin Slack
Channels
announcements
automation-api
aws
azure
blog-posts
built-with-pulumi
cloudengineering
cloudengineering-support
content-share
contribex
contribute
docs
dotnet
finops
general
getting-started
gitlab
golang
google-cloud
hackathon-03-19-2020
hacktoberfest
install
java
jobs
kubernetes
learn-pulumi-events
linen
localstack
multi-language-hackathon
office-hours
oracle-cloud-infrastructure
plugin-framework
pulumi-cdk
pulumi-crosscode
pulumi-deployments
pulumi-kubernetes-operator
pulumi-service
pulumiverse
python
registry
status
testingtesting123
testingtesting321
typescript
welcome
workshops
yaml
Powered by Linen
golang
  • w

    white-balloon-205

    09/17/2018, 10:39 PM
    set the channel description: Using Pulumi in Go
  • c

    creamy-potato-29402

    09/17/2018, 10:41 PM
    🎉
  • a

    aloof-tailor-93191

    09/17/2018, 10:43 PM
    looks at
    RegisterResourceOutputs
    to see how scary it might be to make a stab at implementing it
  • w

    white-balloon-205

    09/17/2018, 10:43 PM
    cc @incalculable-sundown-82514 who I'm sure will be interested in anything we discuss here 😄
  • i

    incalculable-sundown-82514

    09/17/2018, 10:54 PM
    Hey @aloof-tailor-93191, glad to hear you’re interested in Go! 😄 Let me know if I can help at all! Feel free to DM me questions or ask in here
  • a

    aloof-tailor-93191

    09/17/2018, 10:55 PM
    @incalculable-sundown-82514 cool, I definitely will
  • a

    aloof-tailor-93191

    09/17/2018, 11:15 PM
    ok, here's what I'm working with:
  • a

    aloof-tailor-93191

    09/17/2018, 11:15 PM
    package main
    
    import (
    	"<http://github.com/pulumi/pulumi-aws/sdk/go/aws/ec2|github.com/pulumi/pulumi-aws/sdk/go/aws/ec2>"
    	"<http://github.com/pulumi/pulumi/sdk/go/pulumi|github.com/pulumi/pulumi/sdk/go/pulumi>"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		config := &ec2.InstanceArgs{
    			Ami:                      "ami-51537029",
    			AssociatePublicIpAddress: true,
    			InstanceType:             "t2.micro",
    		}
    		inst, err := ec2.NewInstance(ctx, "test", config)
    		if err != nil {
    			return err
    		}
    
    		// Export the public IP of the instance
    		ctx.Export("inst", inst.PublicIp)
    		return nil
    	})
    }
  • a

    aloof-tailor-93191

    09/17/2018, 11:15 PM
    trying to get the output to work
  • a

    aloof-tailor-93191

    09/17/2018, 11:16 PM
    here's my version of RegisterResourceOutputs:
    // RegisterResourceOutputs completes the resource registration, attaching an optional set of computed outputs.
    func (ctx *Context) RegisterResourceOutputs(urn URN, outs map[string]interface{}) error {
    	fmt.Println(outs)
    
    	_, outsMarshalled, _, err := marshalInputs(outs)
    	if err != nil {
    		return errors.Wrap(err, "marshaling arguments")
    	}
    
    	// Note that we're about to make an outstanding RPC request, so that we can rendezvous during shutdown.
    	if err = ctx.beginRPC(); err != nil {
    		return err
    	}
    
    	// Kick off the resource registration.  If we are actually performing a deployment, the resulting properties
    	// will be resolved asynchronously as the RPC operation completes.  If we're just planning, values won't resolve.
    	go func() {
    		glog.V(9).Infof("RegisterResourceOutputs(%s): Goroutine spawned, RPC call being made", urn)
    		_, err := ctx.monitor.RegisterResourceOutputs(ctx.ctx, &pulumirpc.RegisterResourceOutputsRequest{
    			Urn:     string(urn),
    			Outputs: outsMarshalled,
    		})
    		if err != nil {
    			glog.V(9).Infof("RegisterResource(%s): error: %v", urn, err)
    		} else {
    			glog.V(9).Infof("RegisterResource(%s): success: %s %s ...", urn)
    		}
    
    		// Signal the completion of this RPC and notify any potential awaiters.
    		ctx.endRPC()
    	}()
    	return nil
    }
  • a

    aloof-tailor-93191

    09/17/2018, 11:16 PM
    which compiles, at least
  • a

    aloof-tailor-93191

    09/17/2018, 11:17 PM
    Previewing update of stack 'ptest-dev'
    Previewing changes:
    
         Type                 Name             Plan          Info
     *   pulumi:pulumi:Stack  ptest-ptest-dev  no change     1 error, 2 info messages
      0x9e
    Diagnostics:
      pulumi:pulumi:Stack: ptest-ptest-dev
        info: map[inst:0x9eaef0]
    
      pulumi:pulumi:Stack: ptest-ptest-dev
        info: error: program failed: 1 error occurred:
            * marshaling arguments: awaiting input property inst: unrecognized input property type: 0x9eaef0 (func() *pulumi.StringOutput)
    
      pulumi:pulumi:Stack: ptest-ptest-dev
        error: an unhandled error occurred: program exited with non-zero exit code: 1
    
    error: an error occurred while advancing the preview
  • a

    aloof-tailor-93191

    09/17/2018, 11:17 PM
    @incalculable-sundown-82514 feels like I'm close, but I'm a little stumped on where to look
  • i

    incalculable-sundown-82514

    09/17/2018, 11:53 PM
    hmm
  • i

    incalculable-sundown-82514

    09/17/2018, 11:54 PM
    @aloof-tailor-93191 here is where that particular error is coming from: https://github.com/pulumi/pulumi/blob/f284112b4e281bcc84ffe0bd084a9f9f99864e83/sdk/go/pulumi/rpc.go#L31
  • i

    incalculable-sundown-82514

    09/17/2018, 11:55 PM
    It looks like we’re marshaling a function that returns a StringOutput and not a StringOutput
  • i

    incalculable-sundown-82514

    09/17/2018, 11:55 PM
    is inst.PublicIp a function?
  • a

    aloof-tailor-93191

    09/17/2018, 11:55 PM
    it is
  • i

    incalculable-sundown-82514

    09/17/2018, 11:56 PM
    yeah, so that’s the problem - looks like you need to call it in your program
  • a

    aloof-tailor-93191

    09/17/2018, 11:56 PM
    I tried
    ctx.Export("inst", inst.PublicIp())
    too
  • i

    incalculable-sundown-82514

    09/17/2018, 11:56 PM
    that doesn’t work?
  • a

    aloof-tailor-93191

    09/17/2018, 11:57 PM
    hm:
    Previewing update of stack 'ptest-dev'
    Previewing changes:
    
         Type                 Name             Plan       Info
     +   pulumi:pulumi:Stack  ptest-ptest-dev  create     1 error, 2 info messages
     +   └─ aws:ec2:Instance  test             create
    
    Diagnostics:
      pulumi:pulumi:Stack: ptest-ptest-dev
        info: error: program failed: 1 error occurred:
            * attempted illegal RPC after program completion
    
      pulumi:pulumi:Stack: ptest-ptest-dev
        info: map[inst:0xc00000e898]
    
      pulumi:pulumi:Stack: ptest-ptest-dev
        error: an unhandled error occurred: program exited with non-zero exit code: 1
    
    error: an error occurred while advancing the preview
  • a

    aloof-tailor-93191

    09/17/2018, 11:57 PM
    maybe it's just not given enough time to finish running?
  • i

    incalculable-sundown-82514

    09/17/2018, 11:57 PM
    hmm
  • a

    aloof-tailor-93191

    09/17/2018, 11:58 PM
    I put the rpc call in a go block, because that's what the RegisterResource call does
  • a

    aloof-tailor-93191

    09/17/2018, 11:58 PM
    tries again without the go block
  • i

    incalculable-sundown-82514

    09/17/2018, 11:58 PM
    yeah, that should be OK, I think?
  • a

    aloof-tailor-93191

    09/17/2018, 11:58 PM
    same error
  • a

    aloof-tailor-93191

    09/17/2018, 11:59 PM
    hm
  • i

    incalculable-sundown-82514

    09/17/2018, 11:59 PM
    hmm, maybe this needs to move? https://github.com/pulumi/pulumi/blob/f284112b4e281bcc84ffe0bd084a9f9f99864e83/sdk/go/pulumi/run.go#L85
Powered by Linen
Title
i

incalculable-sundown-82514

09/17/2018, 11:59 PM
hmm, maybe this needs to move? https://github.com/pulumi/pulumi/blob/f284112b4e281bcc84ffe0bd084a9f9f99864e83/sdk/go/pulumi/run.go#L85
View count: 3