Skip to content

Commit

Permalink
Merge pull request #124 from controlplane-com/majid/workload-options-fix
Browse files Browse the repository at this point in the history
Fix workload options bug
  • Loading branch information
enk21 authored Oct 1, 2024
2 parents 1f3edb5 + 6f020b7 commit 0cd6947
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 32 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ HOSTNAME=controlplane.com
NAMESPACE=com
NAME=cpln
BINARY=terraform-provider-${NAME}
VERSION=1.1.34
VERSION=1.1.35
OS_ARCH=linux_amd64

default: install
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,4 +302,6 @@ tar -cvzf terraform-provider-cpln_1.0.0_windows_amd64.zip terraform-provider-cpl
- v1.1.33
- Add import support to mk8s resource.
- v1.1.34
- Make workload options optional.
- Make workload options optional.
- v1.1.35
- Fix empty options bug in workload resource.
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ terraform {
required_providers {
cpln = {
source = "controlplane-com/cpln"
version = "1.1.34"
version = "1.1.35"
}
}
}
Expand Down
55 changes: 26 additions & 29 deletions internal/provider/resource_workload.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ func resourceWorkload() *schema.Resource {
Type: schema.TypeBool,
Description: "Capacity AI. Default: `true`.",
Optional: true,
Default: true,
Default: false,
},
"debug": {
Type: schema.TypeBool,
Expand Down Expand Up @@ -1606,51 +1606,48 @@ func buildLifeCycleSpec(lifecycle []interface{}, containerSpec *client.Container

func buildOptions(options []interface{}, workloadSpec *client.WorkloadSpec, localOptions bool, org string) {

if options == nil {
if len(options) == 0 {
return
}

output := []client.Options{}

if len(options) > 0 {

for _, o := range options {

option := o.(map[string]interface{})
for _, o := range options {

newOptions := client.Options{}
option := o.(map[string]interface{})

if localOptions {
newOptions.Location = GetString(fmt.Sprintf("/org/%s/location/%s", org, option["location"].(string)))
}
newOptions := client.Options{}

newOptions.CapacityAI = GetBool(option["capacity_ai"])
newOptions.TimeoutSeconds = GetInt(option["timeout_seconds"])
newOptions.Debug = GetBool(option["debug"])
newOptions.Suspend = GetBool(option["suspend"])
if localOptions {
newOptions.Location = GetString(fmt.Sprintf("/org/%s/location/%s", org, option["location"].(string)))
}

autoScaling := option["autoscaling"].([]interface{})
newOptions.CapacityAI = GetBool(option["capacity_ai"])
newOptions.TimeoutSeconds = GetInt(option["timeout_seconds"])
newOptions.Debug = GetBool(option["debug"])
newOptions.Suspend = GetBool(option["suspend"])

if len(autoScaling) > 0 {
autoScaling := option["autoscaling"].([]interface{})

as := autoScaling[0].(map[string]interface{})
if len(autoScaling) > 0 {

cas := client.AutoScaling{
as := autoScaling[0].(map[string]interface{})

Metric: GetString(as["metric"]),
MetricPercentile: GetString(as["metric_percentile"]),
Target: GetInt(as["target"]),
MaxScale: GetInt(as["max_scale"]),
MinScale: GetInt(as["min_scale"]),
MaxConcurrency: GetInt(as["max_concurrency"]),
ScaleToZeroDelay: GetInt(as["scale_to_zero_delay"]),
}
cas := client.AutoScaling{

newOptions.AutoScaling = &cas
Metric: GetString(as["metric"]),
MetricPercentile: GetString(as["metric_percentile"]),
Target: GetInt(as["target"]),
MaxScale: GetInt(as["max_scale"]),
MinScale: GetInt(as["min_scale"]),
MaxConcurrency: GetInt(as["max_concurrency"]),
ScaleToZeroDelay: GetInt(as["scale_to_zero_delay"]),
}

output = append(output, newOptions)
newOptions.AutoScaling = &cas
}

output = append(output, newOptions)
}

if workloadSpec == nil {
Expand Down

0 comments on commit 0cd6947

Please sign in to comment.