https://pulumi.com logo
#general
Title
# general
t

thousands-planet-78612

08/23/2021, 10:44 AM
Hi there! I am using Pulumi to create s3.NewBucket in golang and I am having trouble accessing the outputs of my resources.
Copy code
// this function defines our pulumi S3 static website in terms of the content that the caller passes in.
// this allows us to dynamically deploy websites based on user defined values from the POST body.
func createPulumiProgram(content string) pulumi.RunFunc {
	return func(ctx *pulumi.Context) error {
		// our program defines a s3 website.
		// here we create the bucket
		siteBucket, err := s3.NewBucket(ctx, "s3-website-bucket", &s3.BucketArgs{
			Website: s3.BucketWebsiteArgs{
				IndexDocument: pulumi.String("index.html"),
			},
		})
		if err != nil {
			return err
		}

		// here our HTML is defined based on what the caller curries in.
		indexContent := content
		// upload our index.html
		if _, err := s3.NewBucketObject(ctx, "index", &s3.BucketObjectArgs{
			Bucket:      siteBucket.ID(), // reference to the s3.Bucket object
			Content:     pulumi.String(indexContent),
			Key:         pulumi.String("index.html"),               // set the key of the object
			ContentType: pulumi.String("text/html; charset=utf-8"), // set the MIME type of the file
		}); err != nil {
			return err
		}

		// Set the access policy for the bucket so all objects are readable.
		if _, err := s3.NewBucketPolicy(ctx, "bucketPolicy", &s3.BucketPolicyArgs{
			Bucket: siteBucket.ID(), // refer to the bucket created earlier
			Policy: pulumi.Any(map[string]interface{}{
				"Version": "2012-10-17",
				"Statement": []map[string]interface{}{
					{
						"Effect":    "Allow",
						"Principal": "*",
						"Action": []interface{}{
							"s3:GetObject",
						},
						"Resource": []interface{}{
							pulumi.Sprintf("arn:aws:s3:::%s/*", siteBucket.ID()), // policy refers to bucket name explicitly
						},
					},
				},
			}),
		}); err != nil {
			return err
		}
		// export the website URL
		ctx.Export("websiteUrl", siteBucket.WebsiteEndpoint)
		return nil
	}
}
b

bored-table-20691

08/23/2021, 4:27 PM
Can you share a bit mroe about what you are having trouble with?
t

thousands-planet-78612

08/24/2021, 7:58 AM
Hi @bored-table-20691 Thanks for the message , I am looking for different properties of spacific s3 bucket bening created our pulumi code . for example BucketDomainName, Id, Region etc. I am using the following code create s3 bucket using automation api. In this example i am using
siteBucket
variable to get s3 resources properties in the form of string i am having trouble converting the values into string . Is there any thing i am missing.
Copy code
func createPulumiProgram(content string, bname string) pulumi.RunFunc {
	return func(ctx *pulumi.Context) error {
		// our program defines a s3 website.
		// here we create the bucket
		siteBucket, err := s3.NewBucket(ctx, bname, &s3.BucketArgs{
			Website: s3.BucketWebsiteArgs{
				IndexDocument: pulumi.String("index.html"),
			},
		})
		if err != nil {
			return err
		}
		Region := siteBucket.Region
		BucketDomainName := siteBucket.BucketDomainName
		Bucket := siteBucket.Bucket 
		}
I would like to store the following infromation in DB and that why i am trying to convert the value to string however
sitebucket
returns pulumi.string format which i can not store in DB.
Copy code
"outputs": {
                        "accelerationStatus": "",
                        "acl": "private",
                        "arn": "arn:aws:s3:::s3-website-bucket-7a7e85d",
                        "bucket": "s3-website-bucket-7a7e85d",
                        "bucketDomainName": "<http://s3-website-bucket-7a7e85d.s3.amazonaws.com|s3-website-bucket-7a7e85d.s3.amazonaws.com>",
                        "bucketRegionalDomainName": "<http://s3-website-bucket-7a7e85d.s3.us-east-2.amazonaws.com|s3-website-bucket-7a7e85d.s3.us-east-2.amazonaws.com>",
                        "corsRules": [],
                        "forceDestroy": false,
                        "grants": [],
                        "hostedZoneId": "Z2O1EMRO9K5GLX",
                        "id": "s3-website-bucket-7a7e85d",
                        "lifecycleRules": [],
                        "loggings": [],
                        "objectLockConfiguration": null,
                        "region": "us-east-2",
                        "replicationConfiguration": null,
                        "requestPayer": "BucketOwner",
                        "serverSideEncryptionConfiguration": null,
                        "tags": {},
                        "versioning": {
                            "enabled": false,
                            "mfaDelete": false
                        },
b

bored-table-20691

08/24/2021, 4:42 PM
Right - you would typically export the values you wanted, and then in your automation program, you would reference the outputs after the stack was created and then store that in the DB. Note that the “store in DB” part is not part of your Pulumi stack - it only references the outputs of the Pulumi stack.
t

thousands-planet-78612

08/25/2021, 12:40 PM
Hi @bored-table-20691 Thanks for rely , i will try as you suggested export the values.