Skip to content

Commit

Permalink
Handle Manager bool which default to true with GetOkExists
Browse files Browse the repository at this point in the history
Otherwise, these cannot be set to false.

The downside is that `GetOkExists` is deprecated and unsure how to handle
it differently (without a rewrite of one resource per manager type).
  • Loading branch information
PChambino committed Mar 17, 2024
1 parent 375b14c commit b5132eb
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion client/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ type Manager struct {
DownscaleTimeout int `json:"downscale_timeout"`
UpscaleLimit int `json:"upscale_limit"`
DownscaleLimit int `json:"downscale_limit"`
UpscaleOnInitialJob *bool `json:"upscale_on_initial_job"`
ScaleUpOn503 *bool `json:"scale_up_on_503"`
NewRelicApiKey *string `json:"new_relic_api_key"`
NewRelicAccountId *string `json:"new_relic_account_id"`
NewRelicAppId *string `json:"new_relic_app_id"`
Notify bool `json:"notify"`
NotifyQuantity int `json:"notify_quantity"`
NotifyAfter int `json:"notify_after"`
UpscaleOnInitialJob *bool `json:"upscale_on_initial_job"`
}

type wrappedManager struct {
Expand Down
6 changes: 3 additions & 3 deletions client/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ func TestGetManagerEverything(t *testing.T) {
"downscale_timeout": 2,
"upscale_limit": 0,
"downscale_limit": 2,
"upscale_on_initial_job": true,
"scale_up_on_503": true,
"new_relic_api_key": "newrelic-api-key",
"new_relic_account_id": "newrelic-account-id",
"new_relic_app_id": "newrelic-app-id",
"notify": true,
"notify_quantity": 5,
"notify_after": 10,
"upscale_on_initial_job": true
"notify_after": 10
}
}`))
}))
Expand Down Expand Up @@ -136,14 +136,14 @@ func TestGetManagerEverything(t *testing.T) {
DownscaleTimeout: 2,
UpscaleLimit: 0,
DownscaleLimit: 2,
UpscaleOnInitialJob: ptr.Bool(true),
ScaleUpOn503: ptr.Bool(true),
NewRelicApiKey: ptr.String("newrelic-api-key"),
NewRelicAccountId: ptr.String("newrelic-account-id"),
NewRelicAppId: ptr.String("newrelic-app-id"),
Notify: true,
NotifyQuantity: 5,
NotifyAfter: 10,
UpscaleOnInitialJob: ptr.Bool(true),
}
assert.Equals(t, expected, manager)
}
4 changes: 2 additions & 2 deletions docs/resources/application.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ The following arguments are supported:

- `account_id` - (required) The ID of the account this application belongs to.
- `name` - (required) The name of the application as registered with Heroku.
- `checkup_frequency` - (optional) The frequency (in seconds) at which autoscaling
operations are performed. Default is `60`.
- `custom_domain` - (optional) The custom domain of the Heroku application, if
any is being used.
- `logplex_drain_token` - (optional) The Heroku drain token, if using Logplex
Expand All @@ -35,8 +37,6 @@ The following arguments are supported:
`false`.
- `resolved_issue_notifications` - (optional) Notify about resolved issues.
Default is `false`.
- `checkup_frequency` - (optional) The frequency (in seconds) at which autoscaling
operations are performed. Default is `60`.

## Attribute Reference

Expand Down
1 change: 0 additions & 1 deletion docs/resources/manager.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ resource "hirefire_manager" "my_manager" {
upscale_sensitivity = 1
downscale_timeout = 1
upscale_timeout = 1
upscale_on_initial_job = true
}
```

Expand Down
1 change: 1 addition & 0 deletions main.tf.example
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ resource "hirefire_manager" "foobar" {
minimum = 1
maximum = 10

decrementable = true
ratio = 5
upscale_sensitivity = 1
downscale_sensitivity = 2
Expand Down
22 changes: 11 additions & 11 deletions resources/manager/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ func Resource() *schema.Resource {
Type: schema.TypeInt,
Optional: true,
},
"upscale_on_initial_job": &schema.Schema{
Type: schema.TypeBool,
Optional: true,
},
"scale_up_on_503": &schema.Schema{
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -197,10 +201,6 @@ func Resource() *schema.Resource {
Type: schema.TypeInt,
Optional: true,
},
"upscale_on_initial_job": &schema.Schema{
Type: schema.TypeBool,
Optional: true,
},
},
}
}
Expand Down Expand Up @@ -239,14 +239,14 @@ func setAttributes(d *schema.ResourceData, manager *client.Manager) {
d.Set("downscale_timeout", manager.DownscaleTimeout)
d.Set("upscale_limit", manager.UpscaleLimit)
d.Set("downscale_limit", manager.DownscaleLimit)
d.Set("upscale_on_initial_job", manager.UpscaleOnInitialJob)
d.Set("scale_up_on_503", manager.ScaleUpOn503)
d.Set("new_relic_api_key", manager.NewRelicApiKey)
d.Set("new_relic_account_id", manager.NewRelicAccountId)
d.Set("new_relic_app_id", manager.NewRelicAppId)
d.Set("notify", manager.Notify)
d.Set("notify_quantity", manager.NotifyQuantity)
d.Set("notify_after", manager.NotifyAfter)
d.Set("upscale_on_initial_job", manager.UpscaleOnInitialJob)
}

func getAttributes(d *schema.ResourceData) client.Manager {
Expand Down Expand Up @@ -340,7 +340,7 @@ func getAttributes(d *schema.ResourceData) client.Manager {
manager.Ratio = &value
}

if v, ok := d.GetOk("decrementable"); ok {
if v, ok := d.GetOkExists("decrementable"); ok {
value := v.(bool)
manager.Decrementable = &value
}
Expand Down Expand Up @@ -390,6 +390,11 @@ func getAttributes(d *schema.ResourceData) client.Manager {
manager.DownscaleLimit = value
}

if v, ok := d.GetOkExists("upscale_on_initial_job"); ok {
value := v.(bool)
manager.UpscaleOnInitialJob = &value
}

if v, ok := d.GetOk("scale_up_on_503"); ok {
value := v.(bool)
manager.ScaleUpOn503 = &value
Expand Down Expand Up @@ -425,11 +430,6 @@ func getAttributes(d *schema.ResourceData) client.Manager {
manager.NotifyAfter = value
}

if v, ok := d.GetOk("upscale_on_initial_job"); ok {
value := v.(bool)
manager.UpscaleOnInitialJob = &value
}

return manager
}

Expand Down
6 changes: 3 additions & 3 deletions resources/manager/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ func config(orgName string, manager *client.Manager) string {
downscale_sensitivity = %d
upscale_timeout = %d
downscale_timeout = %d
upscale_on_initial_job = %d
upscale_on_initial_job = %t
`,
*manager.MinimumLatency,
*manager.MaximumLatency,
Expand All @@ -281,7 +281,7 @@ func config(orgName string, manager *client.Manager) string {
*manager.DownscaleSensitivity,
manager.UpscaleTimeout,
manager.DownscaleTimeout,
manager.UpscaleOnInitialJob,
*manager.UpscaleOnInitialJob,
))
default:
return configBase(orgName, manager, "")
Expand Down Expand Up @@ -329,14 +329,14 @@ func checkAttributes(manager client.Manager) resource.TestCheckFunc {
"downscale_timeout": strconv.Itoa(manager.DownscaleTimeout),
"upscale_limit": strconv.Itoa(manager.UpscaleLimit),
"downscale_limit": strconv.Itoa(manager.DownscaleLimit),
"upscale_on_initial_job": helper.BoolOrFalse(manager.UpscaleOnInitialJob),
"scale_up_on_503": helper.BoolOrFalse(manager.ScaleUpOn503),
"new_relic_api_key": helper.StringOrEmpty(manager.NewRelicApiKey),
"new_relic_account_id": helper.StringOrEmpty(manager.NewRelicAccountId),
"new_relic_app_id": helper.StringOrEmpty(manager.NewRelicAppId),
"notify": strconv.FormatBool(manager.Notify),
"notify_quantity": strconv.Itoa(manager.NotifyQuantity),
"notify_after": strconv.Itoa(manager.NotifyAfter),
"upscale_on_initial_job": helper.BoolOrFalse(manager.UpscaleOnInitialJob),
})
}

Expand Down

0 comments on commit b5132eb

Please sign in to comment.