Skip to content

Commit

Permalink
Add creation_timestamp field to google_compute_instance and templ…
Browse files Browse the repository at this point in the history
…ate resources (#11955) (#19906)

[upstream:dcc3ee085bbe1f19ed72924c8ee4c6c53fc6743f]

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored Oct 17, 2024
1 parent 17ee30b commit c9a5896
Show file tree
Hide file tree
Showing 14 changed files with 50 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/11955.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
compute: added `creation_timestamp` field to `google_compute_instance`, `google_compute_instance_template`, `google_compute_region_instance_template`
```
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ func dataSourceGoogleComputeInstanceRead(d *schema.ResourceData, meta interface{
if err := d.Set("name", instance.Name); err != nil {
return fmt.Errorf("Error setting name: %s", err)
}
if err := d.Set("creation_timestamp", instance.CreationTimestamp); err != nil {
return fmt.Errorf("Error setting creation_timestamp: %s", err)
}
d.SetId(fmt.Sprintf("projects/%s/zones/%s/instances/%s", project, tpgresource.GetResourceNameFromSelfLink(instance.Zone), instance.Name))
return nil
}
9 changes: 9 additions & 0 deletions google/services/compute/resource_compute_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,12 @@ be from 0 to 999,999,999 inclusive.`,
Description: `The server-assigned unique identifier of this instance.`,
},

"creation_timestamp": {
Type: schema.TypeString,
Computed: true,
Description: `Creation timestamp in RFC3339 text format.`,
},

"label_fingerprint": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -1699,6 +1705,9 @@ func resourceComputeInstanceRead(d *schema.ResourceData, meta interface{}) error
if err := d.Set("instance_id", fmt.Sprintf("%d", instance.Id)); err != nil {
return fmt.Errorf("Error setting instance_id: %s", err)
}
if err := d.Set("creation_timestamp", instance.CreationTimestamp); err != nil {
return fmt.Errorf("Error setting creation_timestamp: %s", err)
}
if err := d.Set("project", project); err != nil {
return fmt.Errorf("Error setting project: %s", err)
}
Expand Down
10 changes: 10 additions & 0 deletions google/services/compute/resource_compute_instance_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,13 @@ be from 0 to 999,999,999 inclusive.`,
Description: `A special URI of the created resource that uniquely identifies this instance template.`,
},

"creation_timestamp": {
Type: schema.TypeString,
ForceNew: true,
Computed: true,
Description: `Creation timestamp in RFC3339 text format.`,
},

"service_account": {
Type: schema.TypeList,
MaxItems: 1,
Expand Down Expand Up @@ -1738,6 +1745,9 @@ func resourceComputeInstanceTemplateRead(d *schema.ResourceData, meta interface{
if err = d.Set("self_link_unique", fmt.Sprintf("%v?uniqueId=%v", instanceTemplate.SelfLink, instanceTemplate.Id)); err != nil {
return fmt.Errorf("Error setting self_link_unique: %s", err)
}
if err = d.Set("creation_timestamp", instanceTemplate.CreationTimestamp); err != nil {
return fmt.Errorf("Error setting creation_timestamp: %s", err)
}
if err = d.Set("name", instanceTemplate.Name); err != nil {
return fmt.Errorf("Error setting name: %s", err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func TestAccComputeInstanceTemplate_basic(t *testing.T) {
testAccCheckComputeInstanceTemplateMetadata(&instanceTemplate, "foo", "bar"),
testAccCheckComputeInstanceTemplateContainsLabel(&instanceTemplate, "my_label", "foobar"),
testAccCheckComputeInstanceTemplateLacksShieldedVmConfig(&instanceTemplate),
resource.TestCheckResourceAttrSet("google_compute_instance_template.foobar", "creation_timestamp"),
),
},
{
Expand Down
1 change: 1 addition & 0 deletions google/services/compute/resource_compute_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ func TestAccComputeInstance_basic1(t *testing.T) {
testAccCheckComputeInstanceMetadata(&instance, "baz", "qux"),
testAccCheckComputeInstanceDisk(&instance, instanceName, true, true),
resource.TestCheckResourceAttr("google_compute_instance.foobar", "current_status", "RUNNING"),
resource.TestCheckResourceAttrSet("google_compute_instance.foobar", "creation_timestamp"),

// by default, DeletionProtection is implicitly false. This should be false on any
// instance resource without an explicit deletion_protection = true declaration.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,13 @@ be from 0 to 999,999,999 inclusive.`,
Description: `The URI of the created resource.`,
},

"creation_timestamp": {
Type: schema.TypeString,
Computed: true,
ForceNew: true,
Description: `The time at which the instance was created in RFC 3339 format.`,
},

"service_account": {
Type: schema.TypeList,
MaxItems: 1,
Expand Down Expand Up @@ -1236,6 +1243,9 @@ func resourceComputeRegionInstanceTemplateRead(d *schema.ResourceData, meta inte
if err = d.Set("self_link", instanceTemplate["selfLink"]); err != nil {
return fmt.Errorf("Error setting self_link: %s", err)
}
if err := d.Set("creation_timestamp", instanceTemplate["creationTimestamp"]); err != nil {
return fmt.Errorf("Error setting creation_timestamp: %s", err)
}
if err = d.Set("name", instanceTemplate["name"]); err != nil {
return fmt.Errorf("Error setting name: %s", err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func TestAccComputeRegionInstanceTemplate_basic(t *testing.T) {
testAccCheckComputeRegionInstanceTemplateMetadata(&instanceTemplate, "foo", "bar"),
testAccCheckComputeRegionInstanceTemplateContainsLabel(&instanceTemplate, "my_label", "foobar"),
testAccCheckComputeRegionInstanceTemplateLacksShieldedVmConfig(&instanceTemplate),
resource.TestCheckResourceAttrSet("google_compute_region_instance_template.foobar", "creation_timestamp"),
),
},
{
Expand Down
2 changes: 2 additions & 0 deletions website/docs/d/compute_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ The following arguments are supported:

* `instance_id` - The server-assigned unique identifier of this instance.

* `creation_timestamp` - Creation timestamp in RFC3339 text format.

* `metadata_fingerprint` - The unique fingerprint of the metadata.

* `self_link` - The URI of the created resource.
Expand Down
2 changes: 2 additions & 0 deletions website/docs/d/compute_instance_template.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,8 @@ The `disk_encryption_key` block supports:

* `id` - an identifier for the resource with format `projects/{{project}}/global/instanceTemplates/{{name}}`

* `creation_timestamp` - Creation timestamp in RFC3339 text format.

* `metadata_fingerprint` - The unique fingerprint of the metadata.

* `self_link` - The URI of the created resource.
Expand Down
2 changes: 2 additions & 0 deletions website/docs/d/compute_region_instance_template.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,8 @@ The `disk_encryption_key` block supports:

* `id` - an identifier for the resource with format `projects/{{project}}/regions/{{region}}/instanceTemplates/{{name}}`

* `creation_timestamp` - Creation timestamp in RFC3339 text format.

* `metadata_fingerprint` - The unique fingerprint of the metadata.

* `self_link` - The URI of the created resource.
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/compute_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,8 @@ exported:

* `id` - an identifier for the resource with format `projects/{{project}}/zones/{{zone}}/instances/{{name}}`

* `creation_timestamp` - Creation timestamp in RFC3339 text format.

* `instance_id` - The server-assigned unique identifier of this instance.

* `metadata_fingerprint` - The unique fingerprint of the metadata.
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/compute_instance_template.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,8 @@ exported:

* `id` - an identifier for the resource with format `projects/{{project}}/global/instanceTemplates/{{name}}`

* `creation_timestamp` - Creation timestamp in RFC3339 text format.

* `metadata_fingerprint` - The unique fingerprint of the metadata.

* `self_link` - The URI of the created resource.
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/compute_region_instance_template.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,8 @@ exported:

* `id` - an identifier for the resource with format `projects/{{project}}/regions/{{region}}/instanceTemplates/{{name}}`

* `creation_timestamp` - Creation timestamp in RFC3339 text format.

* `metadata_fingerprint` - The unique fingerprint of the metadata.

* `self_link` - The URI of the created resource.
Expand Down

0 comments on commit c9a5896

Please sign in to comment.