Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add creation_timestamp field to google_compute_instance and template resources #19906

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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
Loading