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 #11955

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package compute
import (
"fmt"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-google/google/tpgresource"
transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func DataSourceGoogleComputeInstance() *schema.Resource {
Expand All @@ -23,7 +23,7 @@ func DataSourceGoogleComputeInstance() *schema.Resource {

func dataSourceGoogleComputeInstanceRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*transport_tpg.Config)
userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent)
userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent)
if err != nil {
return err
}
Expand Down Expand Up @@ -202,6 +202,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
}
Original file line number Diff line number Diff line change
Expand Up @@ -1177,6 +1177,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 @@ -1803,6 +1809,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
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,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 @@ -1800,6 +1807,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 @@ -52,6 +52,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 @@ -192,6 +192,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 @@ -775,6 +775,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 @@ -1298,6 +1305,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 @@ -47,6 +47,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
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
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
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,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
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