Closed ynikitin-etsy closed 1 day ago
This is a general problem, especially in the compute surface for in Go with how default types are handled. I believe this is documented in TF. There are likely many more fields that could also be converted to pointers to help with this. I think in this case you can tease out what the value is as the docs for Fixed state: "Specifies a fixed number of VM instances. This must be a positive integer". The long term solution here would be for TF to use the newer compute client that makes most(all?) the surface pointer types: cloud.google.com/go/compute/apiv1. In the subpackage computepb
the equivalent type looks like:
// Encapsulates numeric value that can be either absolute or relative.
type FixedOrPercent struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
// [Output Only] Absolute value of VM instances calculated based on the specific mode. - If the value is fixed, then the calculated value is equal to the fixed value. - If the value is a percent, then the calculated value is percent/100 * targetSize. For example, the calculated value of a 80% of a managed instance group with 150 instances would be (80/100 * 150) = 120 VM instances. If there is a remainder, the number is rounded.
Calculated *int32 `protobuf:"varint,472082878,opt,name=calculated,proto3,oneof" json:"calculated,omitempty"`
// Specifies a fixed number of VM instances. This must be a positive integer.
Fixed *int32 `protobuf:"varint,97445748,opt,name=fixed,proto3,oneof" json:"fixed,omitempty"`
// Specifies a percentage of instances between 0 to 100%, inclusive. For example, specify 80 for 80%.
Percent *int32 `protobuf:"varint,394814533,opt,name=percent,proto3,oneof" json:"percent,omitempty"`
}
Thank you for the response! I still don't see a clear way of figuring out the actual value, but I'll try a few things.
I obviously have no impact if the Terraform provider can use this different library, but will hope something eventually changes. Thank again!
Closing this as working as intended for now. As mentioned above the best solution is to use the newer library that does not have these issues.
Environment details
Steps to reproduce
InstanceGroupManager.Versions.TargetSize
with type*FixedOrPercent
contains two important fields:Fixed int64
, andPercent int64
. When getting a response, no matter if onlyTargetSize.Fixed
is set to 0 or onlyTargetSize.Percent
is set to 0, both are returned as zero, since they are int64 and need default values. Thus, (importantly in context of gcp terraform provider), it is impossible to tell what value is actually set (fixed or percent).Those types should be
Fixed *int64
, andPercent *int64
.Sample raw API snippet response:
This is what the library returns as a response formatted into json.
Zeros are valid values here. This change is needed to fix this bug in TF: https://github.com/hashicorp/terraform-provider-google/issues/14826
Thank you for any help or support!