Skip to content

add server-side id for a few resources #8736

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

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
18 changes: 18 additions & 0 deletions .changelog/12351.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
```release-note: enhancement
compute: added server generated id as `forwarding_rule_id` to `google_compute_global_forwarding_rule`
```
```release-note: enhancement
compute: added server generated id as `health_check_id` to `google_region_health_check`
```
```release-note: enhancement
compute: added server generated id as `instance_group_manager_id` to `google_region_instance_group_manager`
```
```release-note: enhancement
compute: added server generated id as `instance_group_manager_id` to `google_instance_group_manager`
```
```release-note: enhancement
compute: added server generated id as `network_endpoint_id` to `google_region_network_endpoint`
```
```release-note: enhancement
compute: added server generated id as `subnetwork_id` to `google_subnetwork`
```
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,11 @@ mode or when creating external forwarding rule with IPv6.`,
Description: `All of labels (key/value pairs) present on the resource in GCP, including the labels configured through Terraform, other clients and services.`,
Elem: &schema.Schema{Type: schema.TypeString},
},
"forwarding_rule_id": {
Type: schema.TypeInt,
Computed: true,
Description: `The unique identifier number for the resource. This identifier is defined by the server.`,
},
"label_fingerprint": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -693,6 +698,9 @@ func resourceComputeGlobalForwardingRuleRead(d *schema.ResourceData, meta interf
if err := d.Set("description", flattenComputeGlobalForwardingRuleDescription(res["description"], d, config)); err != nil {
return fmt.Errorf("Error reading GlobalForwardingRule: %s", err)
}
if err := d.Set("forwarding_rule_id", flattenComputeGlobalForwardingRuleForwardingRuleId(res["id"], d, config)); err != nil {
return fmt.Errorf("Error reading GlobalForwardingRule: %s", err)
}
if err := d.Set("ip_address", flattenComputeGlobalForwardingRuleIPAddress(res["IPAddress"], d, config)); err != nil {
return fmt.Errorf("Error reading GlobalForwardingRule: %s", err)
}
Expand Down Expand Up @@ -961,6 +969,23 @@ func flattenComputeGlobalForwardingRuleDescription(v interface{}, d *schema.Reso
return v
}

func flattenComputeGlobalForwardingRuleForwardingRuleId(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
// Handles the string fixed64 format
if strVal, ok := v.(string); ok {
if intVal, err := tpgresource.StringToFixed64(strVal); err == nil {
return intVal
}
}

// number values are represented as float64
if floatVal, ok := v.(float64); ok {
intVal := int(floatVal)
return intVal
}

return v // let terraform core handle it otherwise
}

func flattenComputeGlobalForwardingRuleIPAddress(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ func TestAccComputeGlobalForwardingRule_updateTarget(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
resource.TestMatchResourceAttr(
"google_compute_global_forwarding_rule.forwarding_rule", "target", regexp.MustCompile(proxy+"$")),
),
resource.TestCheckResourceAttrSet(
"google_compute_global_forwarding_rule.forwarding_rule", "forwarding_rule_id")),
},
{
ResourceName: "google_compute_global_forwarding_rule.forwarding_rule",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ func ResourceComputeInstanceGroupManager() *schema.Resource {
Description: `An optional textual description of the instance group manager.`,
},

"instance_group_manager_id": {
Type: schema.TypeInt,
Computed: true,
Description: `The unique identifier number for the resource. This identifier is defined by the server.`,
},

"fingerprint": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -827,6 +833,11 @@ func resourceComputeInstanceGroupManagerRead(d *schema.ResourceData, meta interf
if err := d.Set("description", manager.Description); err != nil {
return fmt.Errorf("Error setting description: %s", err)
}

if err := d.Set("instance_group_manager_id", manager.Id); err != nil {
return fmt.Errorf("Error setting description: %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 @@ -27,6 +27,9 @@ func TestAccInstanceGroupManager_basic(t *testing.T) {
Steps: []resource.TestStep{
{
Config: testAccInstanceGroupManager_basic(template, target, igm1, igm2),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(
"google_compute_instance_group_manager.igm-no-tp", "instance_group_manager_id")),
},
{
ResourceName: "google_compute_instance_group_manager.igm-basic",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,11 @@ consecutive failures. The default value is 2.`,
Computed: true,
Description: `Creation timestamp in RFC3339 text format.`,
},
"health_check_id": {
Type: schema.TypeInt,
Computed: true,
Description: `The unique identifier number for the resource. This identifier is defined by the server.`,
},
"type": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -799,6 +804,9 @@ func resourceComputeRegionHealthCheckRead(d *schema.ResourceData, meta interface
if err := d.Set("description", flattenComputeRegionHealthCheckDescription(res["description"], d, config)); err != nil {
return fmt.Errorf("Error reading RegionHealthCheck: %s", err)
}
if err := d.Set("health_check_id", flattenComputeRegionHealthCheckHealthCheckId(res["id"], d, config)); err != nil {
return fmt.Errorf("Error reading RegionHealthCheck: %s", err)
}
if err := d.Set("healthy_threshold", flattenComputeRegionHealthCheckHealthyThreshold(res["healthyThreshold"], d, config)); err != nil {
return fmt.Errorf("Error reading RegionHealthCheck: %s", err)
}
Expand Down Expand Up @@ -1094,6 +1102,23 @@ func flattenComputeRegionHealthCheckDescription(v interface{}, d *schema.Resourc
return v
}

func flattenComputeRegionHealthCheckHealthCheckId(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
// Handles the string fixed64 format
if strVal, ok := v.(string); ok {
if intVal, err := tpgresource.StringToFixed64(strVal); err == nil {
return intVal
}
}

// number values are represented as float64
if floatVal, ok := v.(float64); ok {
intVal := int(floatVal)
return intVal
}

return v // let terraform core handle it otherwise
}

func flattenComputeRegionHealthCheckHealthyThreshold(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
// Handles the string fixed64 format
if strVal, ok := v.(string); ok {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ func TestAccComputeRegionHealthCheck_tcp_update(t *testing.T) {
Steps: []resource.TestStep{
{
Config: testAccComputeRegionHealthCheck_tcp(hckName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(
"google_compute_region_health_check.foobar", "health_check_id"),
),
},
{
ResourceName: "google_compute_region_health_check.foobar",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ func ResourceComputeRegionInstanceGroupManager() *schema.Resource {
Description: `An optional textual description of the instance group manager.`,
},

"instance_group_manager_id": {
Type: schema.TypeInt,
Computed: true,
Description: `The unique identifier number for the resource. This identifier is defined by the server.`,
},

"fingerprint": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -812,6 +818,9 @@ func resourceComputeRegionInstanceGroupManagerRead(d *schema.ResourceData, meta
if err := d.Set("description", manager.Description); err != nil {
return fmt.Errorf("Error setting description: %s", err)
}
if err := d.Set("instance_group_manager_id", manager.Id); err != nil {
return fmt.Errorf("Error setting description: %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 @@ -28,6 +28,9 @@ func TestAccRegionInstanceGroupManager_basic(t *testing.T) {
Steps: []resource.TestStep{
{
Config: testAccRegionInstanceGroupManager_basic(template, target, igm1, igm2),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(
"google_compute_region_instance_group_manager.igm-basic", "instance_group_manager_id")),
},
{
ResourceName: "google_compute_region_instance_group_manager.igm-basic",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ This can only be specified when network_endpoint_type of the NEG is INTERNET_IP_
DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName,
Description: `Region where the containing network endpoint group is located.`,
},
"network_endpoint_id": {
Type: schema.TypeInt,
Computed: true,
Description: `The unique identifier number for the resource. This identifier is defined by the server.`,
},
"project": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -304,6 +309,9 @@ func resourceComputeRegionNetworkEndpointRead(d *schema.ResourceData, meta inter
if err := d.Set("ip_address", flattenNestedComputeRegionNetworkEndpointIpAddress(res["ipAddress"], d, config)); err != nil {
return fmt.Errorf("Error reading RegionNetworkEndpoint: %s", err)
}
if err := d.Set("network_endpoint_id", flattenNestedComputeRegionNetworkEndpointNetworkEndpointId(res["id"], d, config)); err != nil {
return fmt.Errorf("Error reading RegionNetworkEndpoint: %s", err)
}
if err := d.Set("fqdn", flattenNestedComputeRegionNetworkEndpointFqdn(res["fqdn"], d, config)); err != nil {
return fmt.Errorf("Error reading RegionNetworkEndpoint: %s", err)
}
Expand Down Expand Up @@ -463,6 +471,23 @@ func flattenNestedComputeRegionNetworkEndpointIpAddress(v interface{}, d *schema
return v
}

func flattenNestedComputeRegionNetworkEndpointNetworkEndpointId(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
// Handles the string fixed64 format
if strVal, ok := v.(string); ok {
if intVal, err := tpgresource.StringToFixed64(strVal); err == nil {
return intVal
}
}

// number values are represented as float64
if floatVal, ok := v.(float64); ok {
intVal := int(floatVal)
return intVal
}

return v // let terraform core handle it otherwise
}

func flattenNestedComputeRegionNetworkEndpointFqdn(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ func TestAccComputeRegionNetworkEndpoint_regionNetworkEndpointBasic(t *testing.T
{
// Create one endpoint
Config: testAccComputeRegionNetworkEndpoint_regionNetworkEndpointBasic(context),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(
"google_compute_region_network_endpoint.default", "network_endpoint_id"),
),
},
{
ResourceName: "google_compute_region_network_endpoint.default",
Expand Down
25 changes: 25 additions & 0 deletions google-beta/services/compute/resource_compute_subnetwork.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,11 @@ outside this subnetwork.`,
Computed: true,
Description: `The range of internal IPv6 addresses that are owned by this subnetwork.`,
},
"subnetwork_id": {
Type: schema.TypeInt,
Computed: true,
Description: `The unique identifier number for the resource. This identifier is defined by the server.`,
},
"send_secondary_ip_range_if_empty": {
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -647,6 +652,9 @@ func resourceComputeSubnetworkRead(d *schema.ResourceData, meta interface{}) err
if err := d.Set("description", flattenComputeSubnetworkDescription(res["description"], d, config)); err != nil {
return fmt.Errorf("Error reading Subnetwork: %s", err)
}
if err := d.Set("subnetwork_id", flattenComputeSubnetworkSubnetworkId(res["id"], d, config)); err != nil {
return fmt.Errorf("Error reading Subnetwork: %s", err)
}
if err := d.Set("gateway_address", flattenComputeSubnetworkGatewayAddress(res["gatewayAddress"], d, config)); err != nil {
return fmt.Errorf("Error reading Subnetwork: %s", err)
}
Expand Down Expand Up @@ -1270,6 +1278,23 @@ func flattenComputeSubnetworkDescription(v interface{}, d *schema.ResourceData,
return v
}

func flattenComputeSubnetworkSubnetworkId(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
// Handles the string fixed64 format
if strVal, ok := v.(string); ok {
if intVal, err := tpgresource.StringToFixed64(strVal); err == nil {
return intVal
}
}

// number values are represented as float64
if floatVal, ok := v.(float64); ok {
intVal := int(floatVal)
return intVal
}

return v // let terraform core handle it otherwise
}

func flattenComputeSubnetworkGatewayAddress(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ func TestAccComputeSubnetwork_basic(t *testing.T) {
t, "google_compute_subnetwork.network-ref-by-url", &subnetwork1),
testAccCheckComputeSubnetworkExists(
t, "google_compute_subnetwork.network-ref-by-name", &subnetwork2),
),
resource.TestCheckResourceAttrSet(
"google_compute_subnetwork.network-ref-by-name", "subnetwork_id")),
},
{
ResourceName: "google_compute_subnetwork.network-ref-by-url",
Expand Down
3 changes: 3 additions & 0 deletions website/docs/r/compute_global_forwarding_rule.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -1427,6 +1427,9 @@ In addition to the arguments listed above, the following computed attributes are
* `psc_connection_status` -
The PSC connection status of the PSC Forwarding Rule. Possible values: `STATUS_UNSPECIFIED`, `PENDING`, `ACCEPTED`, `REJECTED`, `CLOSED`

* `forwarding_rule_id` -
The unique identifier number for the resource. This identifier is defined by the server.

* `label_fingerprint` -
The fingerprint used for optimistic locking of this resource. Used
internally during updates.
Expand Down
3 changes: 3 additions & 0 deletions website/docs/r/compute_region_health_check.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,9 @@ In addition to the arguments listed above, the following computed attributes are
* `creation_timestamp` -
Creation timestamp in RFC3339 text format.

* `health_check_id` -
The unique identifier number for the resource. This identifier is defined by the server.

* `type` -
The type of the health check. One of HTTP, HTTP2, HTTPS, TCP, or SSL.
* `self_link` - The URI of the created resource.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ In addition to the arguments listed above, the following computed attributes are

* `id` - an identifier for the resource with format `{{project}}/{{region}}/{{region_network_endpoint_group}}/{{ip_address}}/{{fqdn}}/{{port}}`

* `network_endpoint_id` -
The unique identifier number for the resource. This identifier is defined by the server.


## Timeouts

Expand Down
3 changes: 3 additions & 0 deletions website/docs/r/compute_subnetwork.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,9 @@ In addition to the arguments listed above, the following computed attributes are
* `creation_timestamp` -
Creation timestamp in RFC3339 text format.

* `subnetwork_id` -
The unique identifier number for the resource. This identifier is defined by the server.

* `gateway_address` -
The gateway address for default routes to reach destination addresses
outside this subnetwork.
Expand Down