Skip to content

Commit

Permalink
Add max_connection/rate_per_endpoint to backend services (#3863)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored and emilymye committed Jun 19, 2019
1 parent d1229ed commit e72c5c8
Show file tree
Hide file tree
Showing 5 changed files with 329 additions and 10 deletions.
75 changes: 69 additions & 6 deletions google/resource_compute_backend_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,23 @@ func resourceGoogleComputeBackendServiceBackendHash(v interface{}) int {
// the hash function doesn't return something else.
buf.WriteString(fmt.Sprintf("%f-", v.(float64)))
}
if v, ok := m["max_connections_per_endpoint"]; ok {
if v == nil {
v = 0
}

buf.WriteString(fmt.Sprintf("%v-", v))
}
if v, ok := m["max_rate_per_endpoint"]; ok {
if v == nil {
v = 0.0
}

// floats can't be added to the hash with %v as the other values are because
// %v and %f are not equivalent strings so this must remain as a float so that
// the hash function doesn't return something else.
buf.WriteString(fmt.Sprintf("%f-", v.(float64)))
}

log.Printf("[DEBUG] computed hash value of %v from %v", hashcode.String(buf.String()), buf.String())
return hashcode.String(buf.String())
Expand Down Expand Up @@ -333,6 +350,10 @@ func computeBackendServiceBackendSchema() *schema.Resource {
Type: schema.TypeInt,
Optional: true,
},
"max_connections_per_endpoint": {
Type: schema.TypeInt,
Optional: true,
},
"max_connections_per_instance": {
Type: schema.TypeInt,
Optional: true,
Expand All @@ -341,6 +362,10 @@ func computeBackendServiceBackendSchema() *schema.Resource {
Type: schema.TypeInt,
Optional: true,
},
"max_rate_per_endpoint": {
Type: schema.TypeFloat,
Optional: true,
},
"max_rate_per_instance": {
Type: schema.TypeFloat,
Optional: true,
Expand Down Expand Up @@ -852,8 +877,10 @@ func flattenComputeBackendServiceBackend(v interface{}, d *schema.ResourceData)
"group": flattenComputeBackendServiceBackendGroup(original["group"], d),
"max_connections": flattenComputeBackendServiceBackendMaxConnections(original["maxConnections"], d),
"max_connections_per_instance": flattenComputeBackendServiceBackendMaxConnectionsPerInstance(original["maxConnectionsPerInstance"], d),
"max_connections_per_endpoint": flattenComputeBackendServiceBackendMaxConnectionsPerEndpoint(original["maxConnectionsPerEndpoint"], d),
"max_rate": flattenComputeBackendServiceBackendMaxRate(original["maxRate"], d),
"max_rate_per_instance": flattenComputeBackendServiceBackendMaxRatePerInstance(original["maxRatePerInstance"], d),
"max_rate_per_endpoint": flattenComputeBackendServiceBackendMaxRatePerEndpoint(original["maxRatePerEndpoint"], d),
"max_utilization": flattenComputeBackendServiceBackendMaxUtilization(original["maxUtilization"], d),
})
}
Expand Down Expand Up @@ -898,6 +925,16 @@ func flattenComputeBackendServiceBackendMaxConnectionsPerInstance(v interface{},
return v
}

func flattenComputeBackendServiceBackendMaxConnectionsPerEndpoint(v interface{}, d *schema.ResourceData) interface{} {
// Handles the string fixed64 format
if strVal, ok := v.(string); ok {
if intVal, err := strconv.ParseInt(strVal, 10, 64); err == nil {
return intVal
} // let terraform core handle it if we can't convert the string to an int.
}
return v
}

func flattenComputeBackendServiceBackendMaxRate(v interface{}, d *schema.ResourceData) interface{} {
// Handles the string fixed64 format
if strVal, ok := v.(string); ok {
Expand All @@ -912,6 +949,10 @@ func flattenComputeBackendServiceBackendMaxRatePerInstance(v interface{}, d *sch
return v
}

func flattenComputeBackendServiceBackendMaxRatePerEndpoint(v interface{}, d *schema.ResourceData) interface{} {
return v
}

func flattenComputeBackendServiceBackendMaxUtilization(v interface{}, d *schema.ResourceData) interface{} {
return v
}
Expand Down Expand Up @@ -1122,7 +1163,7 @@ func expandComputeBackendServiceBackend(v interface{}, d TerraformResourceData,
transformedCapacityScaler, err := expandComputeBackendServiceBackendCapacityScaler(original["capacity_scaler"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedCapacityScaler); val.IsValid() && !isEmptyValue(val) {
} else {
transformed["capacityScaler"] = transformedCapacityScaler
}

Expand All @@ -1143,35 +1184,49 @@ func expandComputeBackendServiceBackend(v interface{}, d TerraformResourceData,
transformedMaxConnections, err := expandComputeBackendServiceBackendMaxConnections(original["max_connections"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedMaxConnections); val.IsValid() && !isEmptyValue(val) {
} else {
transformed["maxConnections"] = transformedMaxConnections
}

transformedMaxConnectionsPerInstance, err := expandComputeBackendServiceBackendMaxConnectionsPerInstance(original["max_connections_per_instance"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedMaxConnectionsPerInstance); val.IsValid() && !isEmptyValue(val) {
} else {
transformed["maxConnectionsPerInstance"] = transformedMaxConnectionsPerInstance
}

transformedMaxConnectionsPerEndpoint, err := expandComputeBackendServiceBackendMaxConnectionsPerEndpoint(original["max_connections_per_endpoint"], d, config)
if err != nil {
return nil, err
} else {
transformed["maxConnectionsPerEndpoint"] = transformedMaxConnectionsPerEndpoint
}

transformedMaxRate, err := expandComputeBackendServiceBackendMaxRate(original["max_rate"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedMaxRate); val.IsValid() && !isEmptyValue(val) {
} else {
transformed["maxRate"] = transformedMaxRate
}

transformedMaxRatePerInstance, err := expandComputeBackendServiceBackendMaxRatePerInstance(original["max_rate_per_instance"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedMaxRatePerInstance); val.IsValid() && !isEmptyValue(val) {
} else {
transformed["maxRatePerInstance"] = transformedMaxRatePerInstance
}

transformedMaxRatePerEndpoint, err := expandComputeBackendServiceBackendMaxRatePerEndpoint(original["max_rate_per_endpoint"], d, config)
if err != nil {
return nil, err
} else {
transformed["maxRatePerEndpoint"] = transformedMaxRatePerEndpoint
}

transformedMaxUtilization, err := expandComputeBackendServiceBackendMaxUtilization(original["max_utilization"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedMaxUtilization); val.IsValid() && !isEmptyValue(val) {
} else {
transformed["maxUtilization"] = transformedMaxUtilization
}

Expand Down Expand Up @@ -1204,6 +1259,10 @@ func expandComputeBackendServiceBackendMaxConnectionsPerInstance(v interface{},
return v, nil
}

func expandComputeBackendServiceBackendMaxConnectionsPerEndpoint(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandComputeBackendServiceBackendMaxRate(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}
Expand All @@ -1212,6 +1271,10 @@ func expandComputeBackendServiceBackendMaxRatePerInstance(v interface{}, d Terra
return v, nil
}

func expandComputeBackendServiceBackendMaxRatePerEndpoint(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandComputeBackendServiceBackendMaxUtilization(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}
Expand Down
Loading

0 comments on commit e72c5c8

Please sign in to comment.