I'm struggling with outputs. I'm trying to make a ...
# getting-started
I'm struggling with outputs. I'm trying to make a pair of security groups in AWS with go and then use NewSecurityGroupRule to add rules to the security group. But when I try and access the .Id of the created security group I get an error
privateSg.Id undefined (type *ec2.SecurityGroup has no field or method Id)
I feel there's something really simple I'm missing here.
Copy code
func main() {
        pulumi.Run(func(ctx *pulumi.Context) error {
                // Read in some ENV, which will be the branch name eventually
                branch := os.Getenv("BRANCH")
                // Read back the Test VPC and public subnets
                v := "vpc-###############"
                vpc, err := ec2.LookupVpc(ctx, &ec2.LookupVpcArgs{Id: &v})
                if err != nil {
                        return err
                privateSg, err := ec2.NewSecurityGroup(ctx, "Test-" + branch + "-priv", &ec2.SecurityGroupArgs{
                        VpcId: pulumi.String(vpc.Id),
                if err != nil{
                        return err
                ctx.Export("sg", privateSg.Id)
                return nil
I've removed the vpc Id from the variable and replaced it with ####s
There might be a documentation issue - try
I noticed in this example: https://github.com/pulumi/examples/blob/master/aws-go-webserver/main.go
is used to reference the sg id.
Hmmm. That gives a different error:
Copy code
./main.go:121:29: cannot use privateSg.CustomResourceState.ID (type func() pulumi.IDOutput) as type pulumi.Input in argument to ctx.Export:
        func() pulumi.IDOutput does not implement pulumi.Input (missing ElementType method)
no wait... my bad... I needed
it seems
That seems to work ok now. I'm not sure I completely understand why, but it keeps me moving forward, thanks.