Hi all! I am trying to create a folder inside an S...
# golang
p
Hi all! I am trying to create a folder inside an S3 bucket. The name of the bucket is taken from a stack reference, and I need to concatenate its name with the new folder name So I did applyT on the stack reference and passed the concatenated variable - the issue is that I still get a pointer value and not the string value:
Copy code
bucketName = stackReference.GetStringOutput(pulumi.String("BucketName"))
appliedBucket := bucketName.ApplyT(func(name string) string {
	return name
}).(pulumi.StringInput)

resourceName := fmt.Sprintf("%v/%s/", appliedBucket, "testFolder")
key := fmt.Sprintf("testFolder")

// Create S3 folder
bucket, err := s3.NewBucketObjectv2(ctx, resourceName, &s3.BucketObjectv2Args{
	Key:    pulumi.String(key),
	Bucket: appliedBucket,
	Tags:   tags,
})
So when I do pulumi up I get this:
Copy code
Type                      Name                                      Plan       Info
     pulumi:pulumi:Stack       audio-player-sdk-staging                             1 message
 +   └─ aws:s3:BucketObjectv2  {0xc000782d90}/testFodler/
b
@prehistoric-sandwich-7272 if you’re going to do it this way, you need to create the bucketObject inside the apply
but I think you want this to be on the key, not the bucket name
p
@billowy-army-68599 Something like this?
Copy code
//Create folder
folder := bucketname.ApplyT(func(appliedBucket string) *s3Pkg.BucketObjectv2 {
   folder, err := s3Pkg.NewBucketObjectv2(ctx, resourceName, &s3Pkg.BucketObjectv2Args{
      Key:    pulumi.String(key),
      Bucket: pulumi.String(appliedBucket),
   })
   if err != nil {
      log.Fatalf("Got error while trying to create new S3 bucket! Error: %s", err)
   }
   return folder
})

log.Println(folder)
b
yes
p
@billowy-army-68599 Does it make sense that I get no resource created when I put it inside the applyT? because when I run it I get nothing 😞
b
it won’t show up in preview, but again - i don’t think this is the correct solution
p
@billowy-army-68599 what solution do you recommend?
I think the bucket must come from a stack reference in order for this function to work with any bucket so the bucket will always be a stringOutput which I will need to apply, no?
b
if it’s a stringOutput, you should be able to pass the name directly.
Copy code
bucketName = stackReference.GetStringOutput(pulumi.String("BucketName"))

bucket, err := s3.NewBucketObjectv2(ctx, resourceName, &s3.BucketObjectv2Args{
	Key:    bucketName,
	Bucket: key/appliedBucket,
	Tags:   tags,
})
p
@billowy-army-68599 still doesn’t work 😞 tried like this:
Copy code
bucket := stackReference.GetStringOutput(pulumi.String("ProgrammaticSdkBucketName"))
appliedBucket := bucket.ApplyT(func(name string) string {
  return name
}).(pulumi.StringOutput)

folderName := "myFolder"
_, err := s3.NewBucketObjectv2(ctx, folderName+"/"+ctx.Stack(), &s3.BucketObjectv2Args{
  Key:    bucket,
  Bucket: pulumi.String(fmt.Sprintf("%s/%v", folderName, appliedBucket)),
})
and I get:
Copy code
error: program failed: waiting for RPCs: marshaling properties: awaiting input property key: failed to convert <nil> to string
    exit status 1

    Provided name to get stack reference from: matanchetz//staging

    error: an unhandled error occurred: program exited with non-zero exit code: 1
ok I did manage to get it working that way, had a mixture with the parameter values thanks a lot!
🎉 1
156 Views