Skip to content

Commit

Permalink
fix(backend): remove auto_loadbalance from compute service (#657)
Browse files Browse the repository at this point in the history
  • Loading branch information
Integralist authored Mar 7, 2023
1 parent ff14642 commit 27dd25f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
1 change: 0 additions & 1 deletion docs/resources/service_compute.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ Required:

Optional:

- `auto_loadbalance` (Boolean) Denotes if this Backend should be included in the pool of backends that requests are load balanced against. Default `false`
- `between_bytes_timeout` (Number) How long to wait between bytes in milliseconds. Default `10000`
- `connect_timeout` (Number) How long to wait for a timeout in milliseconds. Default `1000`
- `error_threshold` (Number) Number of errors to allow before the Backend is marked as down. Default `0`
Expand Down
20 changes: 11 additions & 9 deletions fastly/block_fastly_service_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@ func (h *BackendServiceAttributeHandler) GetSchema() *schema.Schema {
Required: true,
Description: "An IPv4, hostname, or IPv6 address for the Backend",
},
"auto_loadbalance": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Denotes if this Backend should be included in the pool of backends that requests are load balanced against. Default `false`",
},
"between_bytes_timeout": {
Type: schema.TypeInt,
Optional: true,
Expand Down Expand Up @@ -176,6 +170,12 @@ func (h *BackendServiceAttributeHandler) GetSchema() *schema.Schema {
required := false

if h.GetServiceMetadata().serviceType == ServiceTypeVCL {
blockAttributes["auto_loadbalance"] = &schema.Schema{
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Denotes if this Backend should be included in the pool of backends that requests are load balanced against. Default `false`",
}
blockAttributes["request_condition"] = &schema.Schema{
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -270,7 +270,6 @@ func (h *BackendServiceAttributeHandler) createDeleteBackendInput(service string
func (h *BackendServiceAttributeHandler) buildCreateBackendInput(service string, latestVersion int, resource map[string]any) gofastly.CreateBackendInput {
opts := gofastly.CreateBackendInput{
Address: gofastly.String(resource["address"].(string)),
AutoLoadbalance: gofastly.CBool(resource["auto_loadbalance"].(bool)),
BetweenBytesTimeout: gofastly.Int(resource["between_bytes_timeout"].(int)),
ConnectTimeout: gofastly.Int(resource["connect_timeout"].(int)),
ErrorThreshold: gofastly.Int(resource["error_threshold"].(int)),
Expand Down Expand Up @@ -319,6 +318,7 @@ func (h *BackendServiceAttributeHandler) buildCreateBackendInput(service string,
}

if h.GetServiceMetadata().serviceType == ServiceTypeVCL {
opts.AutoLoadbalance = gofastly.CBool(resource["auto_loadbalance"].(bool))
opts.RequestCondition = gofastly.String(resource["request_condition"].(string))
}
return opts
Expand Down Expand Up @@ -358,7 +358,9 @@ func (h *BackendServiceAttributeHandler) buildUpdateBackendInput(serviceID strin
opts.BetweenBytesTimeout = gofastly.Int(v.(int))
}
if v, ok := modified["auto_loadbalance"]; ok {
opts.AutoLoadbalance = gofastly.CBool(v.(bool))
if h.GetServiceMetadata().serviceType == ServiceTypeVCL {
opts.AutoLoadbalance = gofastly.CBool(v.(bool))
}
}
if v, ok := modified["weight"]; ok {
opts.Weight = gofastly.Int(v.(int))
Expand Down Expand Up @@ -415,7 +417,6 @@ func flattenBackend(remoteState []*gofastly.Backend, sa ServiceMetadata) []map[s
for _, resource := range remoteState {
data := map[string]any{
"address": resource.Address,
"auto_loadbalance": resource.AutoLoadbalance,
"between_bytes_timeout": int(resource.BetweenBytesTimeout),
"connect_timeout": int(resource.ConnectTimeout),
"error_threshold": int(resource.ErrorThreshold),
Expand All @@ -440,6 +441,7 @@ func flattenBackend(remoteState []*gofastly.Backend, sa ServiceMetadata) []map[s
}

if sa.serviceType == ServiceTypeVCL {
data["auto_loadbalance"] = resource.AutoLoadbalance
data["request_condition"] = resource.RequestCondition
}

Expand Down
4 changes: 1 addition & 3 deletions fastly/block_fastly_service_backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ func TestResourceFastlyFlattenBackendCompute(t *testing.T) {
Address: "www.notexample.com",
OverrideHost: "origin.example.com",
Port: 80,
AutoLoadbalance: true,
BetweenBytesTimeout: 10000,
ConnectTimeout: 1000,
ErrorThreshold: 0,
Expand Down Expand Up @@ -132,7 +131,6 @@ func TestResourceFastlyFlattenBackendCompute(t *testing.T) {
"address": "www.notexample.com",
"override_host": "origin.example.com",
"port": 80,
"auto_loadbalance": true,
"between_bytes_timeout": 10000,
"connect_timeout": 1000,
"error_threshold": 0,
Expand Down Expand Up @@ -333,7 +331,7 @@ func testAccCheckFastlyServiceVCLBackendAttributes(service *gofastly.ServiceDeta
// we don't know these things ahead of time, so populate them now
w.ServiceID = service.ID
w.ServiceVersion = service.ActiveVersion.Number
// We don't track these, so clear them out because we also wont know
// We don't track these, so clear them out because we also won't know
// these ahead of time
h.CreatedAt = nil
h.UpdatedAt = nil
Expand Down

0 comments on commit 27dd25f

Please sign in to comment.