https://pulumi.com logo
Title
n

nice-hairdresser-58013

02/09/2023, 8:09 PM
Hi everyone, I’m a rookie in the field of IaC and pulumi and I already like it. The pulumi docs is awesome. But there is a question: I want to create a new GCP bucket with the storage class
Nearline
and enabled data object protection with this config as shown in the images. How can I implement that? My code:
import * as gcp from "@pulumi/gcp";

// Create a GCP resource (Storage Bucket)
const bucket = new gcp.storage.Bucket("name", {
  location: "US",
  name: "name",
  storageClass: "NEARLINE",
  uniformBucketLevelAccess: true,
});

// Export the DNS name of the bucket
export const bucketName = bucket.url;
l

little-cartoon-10569

02/09/2023, 8:19 PM
What's not working? Are you looking for the versioning property? And it'd better to use the NEARLINE constant rather than the string, since then you get the hover docs.
Once you enable versioning, you can set up the noncurrent and max number properties via the lifecycleRules property.
n

nice-hairdresser-58013

02/09/2023, 8:39 PM
Alright, how do i get the
NEARLINE
as constant?
l

little-cartoon-10569

02/09/2023, 8:40 PM
It should come in the import gcp statement... let me look up the specific file...
Wow, it hasn't been turned into a constant. The string value is used everywhere. It is "NEARLINE", all caps.
n

nice-hairdresser-58013

02/09/2023, 8:46 PM
Okay 😄 So I’ve modified my
lifecycleRules
to this, would this behave like the
Expire noncurrent versions after
, so that all objects within this bucket is deleted after 30 days?
const bucket = new gcp.storage.Bucket("name", {
  location: "US",
  name: "name",
  storageClass: "NEAERLINE",
  uniformBucketLevelAccess: true,
  versioning: {
    enabled: true,
  },
  lifecycleRules: [
    {
      action: {
        type: "Delete",
      },
      condition: {
        age: 30,
      },
    },
  ],
});
l

little-cartoon-10569

02/09/2023, 8:47 PM
That'll include current versions, do you want that? Or only non-current versions?
n

nice-hairdresser-58013

02/09/2023, 8:48 PM
only non-current-versions 🙂
l

little-cartoon-10569

02/09/2023, 8:49 PM
Then remove
age
, and put in
daysSinceNoncurrentTime
. And probably
numNewerVersions
too.
n

nice-hairdresser-58013

02/09/2023, 8:50 PM
alright got it:
lifecycleRules: [
    {
      action: {
        type: "Delete",
      },
      condition: {
        daysSinceNoncurrentTime: 30,
        numNewerVersions: 2,
      },
    },
  ],
And that’ll include
Max. Number of versions per object
as well, right?
l

little-cartoon-10569

02/09/2023, 8:50 PM
You'd have to split it into two separate rules for that, I think.
Rules are _or_ed, conditions are _and_ed.
n

nice-hairdresser-58013

02/09/2023, 8:51 PM
okay, interesting
lifecycleRules: [
    {
      action: {
        type: "Delete",
      },
      condition: {
        daysSinceNoncurrentTime: 30,
      },
    },
    {
      action: {
        type: "Delete",
      },
      condition: {
        numNewerVersions: 2,
      },
    },
  ],
l

little-cartoon-10569

02/09/2023, 8:52 PM
Your 1st example means "delete objects that have at least 2 newer versions and haven't been current in at least 30 days".
The second one is "delete objects that haven't been current in 30 days, and delete objects that have at least 2 newer versions (any age)".
Which I think is what your screenshot says, too.
n

nice-hairdresser-58013

02/09/2023, 8:53 PM
yeah exactly
Thanks for the clarification :)
And obv thanks for helping 🙂