Skip to content

Commit b45ba67

Browse files
feat: (storage) added time_created and updated timestamps for storage bucket (#13763) (#22500)
[upstream:56d67adbf83210d2f344472c5d89fefe0fc6c5eb] Signed-off-by: Modular Magician <[email protected]>
1 parent e1fe2ff commit b45ba67

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

.changelog/13763.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
storage: added new fields `time_created` and `updated` in `google_storage_bucket`
3+
```

google/services/storage/resource_storage_bucket.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,16 @@ func ResourceStorageBucket() *schema.Resource {
568568
},
569569
},
570570
},
571+
"time_created": {
572+
Type: schema.TypeString,
573+
Computed: true,
574+
Description: `The creation time of the bucket in RFC 3339 format.`,
575+
},
576+
"updated": {
577+
Type: schema.TypeString,
578+
Computed: true,
579+
Description: `The time at which the bucket's metadata or IAM policy was last updated, in RFC 3339 format.`,
580+
},
571581
},
572582
UseJSONNumber: true,
573583
}
@@ -1308,6 +1318,14 @@ func flattenBucketCustomPlacementConfig(cfc *storage.BucketCustomPlacementConfig
13081318
return customPlacementConfig
13091319
}
13101320

1321+
func flattenTimeCreated(v interface{}) interface{} {
1322+
return v
1323+
}
1324+
1325+
func flattenUpdated(v interface{}) interface{} {
1326+
return v
1327+
}
1328+
13111329
func expandBucketDataLocations(configured interface{}) []string {
13121330
l := configured.(*schema.Set).List()
13131331

@@ -2034,6 +2052,12 @@ func setStorageBucket(d *schema.ResourceData, config *transport_tpg.Config, res
20342052
if err := d.Set("custom_placement_config", flattenBucketCustomPlacementConfig(res.CustomPlacementConfig)); err != nil {
20352053
return fmt.Errorf("Error setting custom_placement_config: %s", err)
20362054
}
2055+
if err := d.Set("time_created", flattenTimeCreated(res.TimeCreated)); err != nil {
2056+
return fmt.Errorf("Error setting time_created: %s", err)
2057+
}
2058+
if err := d.Set("updated", flattenUpdated(res.Updated)); err != nil {
2059+
return fmt.Errorf("Error setting updated: %s", err)
2060+
}
20372061
// Needs to hide rpo field for single-region buckets.
20382062
// Check the Rpo field from API response to determine whether bucket is in single region config or not.
20392063
if res.Rpo != "" {

google/services/storage/resource_storage_bucket_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ func TestAccStorageBucket_basic(t *testing.T) {
4242
"google_storage_bucket.bucket", "project_number"),
4343
resource.TestCheckResourceAttr(
4444
"google_storage_bucket.bucket", "rpo", "DEFAULT"),
45+
resource.TestCheckResourceAttrSet(
46+
"google_storage_bucket.bucket", "time_created"),
47+
resource.TestCheckResourceAttrSet(
48+
"google_storage_bucket.bucket", "updated"),
4549
),
4650
},
4751
{

website/docs/r/storage_bucket.html.markdown

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ The following arguments are supported:
173173

174174
* `hierarchical_namespace` - (Optional, ForceNew) The bucket's hierarchical namespace policy, which defines the bucket capability to handle folders in logical structure. Structure is [documented below](#nested_hierarchical_namespace). To use this configuration, `uniform_bucket_level_access` must be enabled on bucket.
175175

176+
* `time_created` - (Computed) The creation time of the bucket in RFC 3339 format.
177+
178+
* `updated` - (Computed) The time at which the bucket's metadata or IAM policy was last updated, in RFC 3339 format.
179+
176180
<a name="nested_lifecycle_rule"></a>The `lifecycle_rule` block supports:
177181

178182
* `action` - (Required) The Lifecycle Rule's action configuration. A single block of this type is supported. Structure is [documented below](#nested_action).

0 commit comments

Comments
 (0)