https://pulumi.com logo
#golang
Title
# golang
n

numerous-printer-41511

11/06/2021, 10:09 PM
hey everyone — I know the
terraform import
and
pulumi import
don’t generate the associated HCL (in TF) or Go code (in Pulumi). Is there a reason this can’t be done?
f

freezing-van-87649

11/06/2021, 10:38 PM
Looking for something like terraformer?
b

billowy-army-68599

11/07/2021, 4:36 AM
@numerous-printer-41511 we obviously aren't familiar with
terraform import
, but can you clarify what you mean regarding
pulumi import
?
I just imported an S3 bucket with
pulumi import
and it generated the Go code for me?
Copy code
pulumi import aws:s3/bucket:Bucket simple-bucket s3-website-bucket-01411d8                                                                                                                         <aws:pulumi-dev-sandbox>
Previewing import (dev)

View Live: <https://app.pulumi.com/jaxxstorm/example/dev/previews/50708d81-556f-4bb6-a455-5d3473568e9e>

     Type                 Name           Plan
 +   pulumi:pulumi:Stack  example-dev    create
 =   └─ aws:s3:Bucket     simple-bucket  import

Resources:
    + 1 to create
    = 1 to import
    2 changes

Do you want to perform this import? yes
Importing (dev)

View Live: <https://app.pulumi.com/jaxxstorm/example/dev/updates/1>

     Type                 Name           Status
 +   pulumi:pulumi:Stack  example-dev    created
 =   └─ aws:s3:Bucket     simple-bucket  imported

Resources:
    + 1 created
    = 1 imported
    2 changes

Duration: 6s

Please copy the following code into your Pulumi application. Not doing so
will cause Pulumi to report that an update will happen on the next update command.

Please note that the imported resources are marked as protected. To destroy them
you will need to remove the `protect` option and run `pulumi update` *before*
the destroy will take effect.

package main

import (
	"<http://github.com/pulumi/pulumi-aws/sdk/v4/go/aws/s3|github.com/pulumi/pulumi-aws/sdk/v4/go/aws/s3>"
	"<http://github.com/pulumi/pulumi/sdk/v3/go/pulumi|github.com/pulumi/pulumi/sdk/v3/go/pulumi>"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := s3.NewBucket(ctx, "simple_bucket", &s3.BucketArgs{
			Acl:          pulumi.String("private"),
			Bucket:       pulumi.String("s3-website-bucket-01411d8"),
			ForceDestroy: pulumi.Bool(false),
			Website: &s3.BucketWebsiteArgs{
				IndexDocument: pulumi.String("index.html"),
			},
		}, pulumi.Protect(true))
		if err != nil {
			return err
		}
		return nil
	})
}
n

numerous-printer-41511

11/07/2021, 4:37 AM
ah thank you! Got a bit confused. Thanks for showing me an example!!
b

billowy-army-68599

11/07/2021, 4:37 AM
you just need to make sure you have the associated project set up with the go runtime in your
Pulumi.yaml
n

numerous-printer-41511

11/07/2021, 4:40 AM
ty!!
I followed these instructions, but the generated code does not have a
pulumi.Import
option
b

billowy-army-68599

11/08/2021, 3:09 PM
@numerous-printer-41511 if you used the import command line option, you don't need to add a pulumi.import option, it's already been added to your state and is under management
n

numerous-printer-41511

11/08/2021, 9:47 PM
awesome thx
3 Views