Ready to level-up your engineering skills? Join a Pulumi Workshop. Register Now

Modify the Program

Now that your storage bucket is provisioned, let’s add an object to it. First, create a new directory called site.

mkdir site

Next, create a new index.html file with some content in it.

cat <<EOT > site/index.html
<html>
    <body>
        <h1>Hello, Pulumi!</h1>
    </body>
</html>
EOT
cat <<EOT > site/index.html
<html>
    <body>
        <h1>Hello, Pulumi!</h1>
    </body>
</html>
EOT
@"
<html>
  <body>
    <h1>Hello, Pulumi!</h1>
  </body>
</html>
"@ | Out-File -FilePath site\index.html

Now that you have your new index.html with some content, open your IDE or text editor and modify your program to add the contents of your index.html file to your storage bucket.

To accomplish this, we will take advantage of your chosen programming language’s native libraries to read the content of the file and assign it as an input to a new BucketObject.

const fs = require("fs");

Next you will create a new bucket object on the lines right after creating the bucket itself.

const bucketObject = new gcp.storage.BucketObject("index.html", {
    bucket: bucket.name,
    content: fs.readFileSync("site/index.html").toString(),
});
import * as fs from "fs";

Next you will create a new bucket object on the lines right after creating the bucket itself.

const bucketObject = new gcp.storage.BucketObject("index.html", {
    bucket: bucket.name,
    content: fs.readFileSync("site/index.html").toString(),
});

Next you will create a new bucket object on the lines right after creating the bucket itself.

bucketObject = storage.BucketObject(
    'index.html',
    bucket=bucket,
    content=open('site/index.html').read(),
)
import (
    "io/ioutil"
    // Existing imports...
)

Next you will create a new bucket object on the lines right after creating the bucket itself.

htmlContent, err := ioutil.ReadFile("site/index.html")
if err != nil {
    return err
}

bucketObject, err := storage.NewBucketObject(ctx, "index.html", &storage.BucketObjectArgs{
    Bucket:  bucket.Name,
    Content: pulumi.String(string(htmlContent)),
})
if err != nil {
    return err
}
using System.IO;

Next you will create a new bucket object on the lines right after creating the bucket itself.

var filePath = Path.GetFullPath("./site/index.html");
var htmlString = File.ReadAllText(filePath);

var bucketObject = new BucketObject("index.html", new BucketObjectArgs
{
    Bucket = bucket.Name,
    Content = htmlString,
});

Notice how you provide the bucket you created earlier as an input to your new BucketObject. This is so Pulumi knows what storage bucket the object should live in.

Next, you’ll deploy your changes.