Skip to content

Commit 4499a2e

Browse files
shivam-thakur12Harness
authored andcommitted
feat: [CCM-26311]: Support disabled field through terraform (#1301)
* ebec10 documentation updated * 0b1fa9 sdk version update * dd50fc add disabled in example * 815f4d add disabled in data source * 78aaf1 tests * ad77b9 add disabled field support in resource
1 parent 614bc5a commit 4499a2e

File tree

7 files changed

+133
-2
lines changed

7 files changed

+133
-2
lines changed

docs/data-sources/cluster_orchestrator_config.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ data "harness_cluster_orchestrator_config" "example" {
2929

3030
- `binpacking` (Block List, Max: 1) Binpacking preferences for Cluster Orchestrator (see [below for nested schema](#nestedblock--binpacking))
3131
- `commitment_integration` (Block List, Max: 1) Commitment integration configuration for Cluster Orchestrator (see [below for nested schema](#nestedblock--commitment_integration))
32+
- `disabled` (Boolean) Whether the cluster orchestrator is disabled
3233
- `distribution` (Block List, Max: 1) Spot and Ondemand Distribution Preferences for workload replicas (see [below for nested schema](#nestedblock--distribution))
3334
- `node_preferences` (Block List, Max: 1) Node preferences for Cluster Orchestrator (see [below for nested schema](#nestedblock--node_preferences))
3435
- `replacement_schedule` (Block List, Max: 1) Replacement schedule for Cluster Orchestrator (see [below for nested schema](#nestedblock--replacement_schedule))

docs/resources/cluster_orchestrator_config.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Resource for ClusterOrchestrator Config.
1515
```terraform
1616
resource "harness_cluster_orchestrator_config" "example" {
1717
orchestrator_id = "orch-cvifpfl9rbg8neldj97g"
18+
disabled = false # Set to true to disable the orchestrator
1819
distribution {
1920
base_ondemand_capacity = 2
2021
ondemand_replica_percentage = 50
@@ -83,6 +84,7 @@ resource "harness_cluster_orchestrator_config" "example" {
8384

8485
- `binpacking` (Block List, Max: 1) Binpacking preferences for Cluster Orchestrator (see [below for nested schema](#nestedblock--binpacking))
8586
- `commitment_integration` (Block List, Max: 1) Commitment integration configuration for Cluster Orchestrator (see [below for nested schema](#nestedblock--commitment_integration))
87+
- `disabled` (Boolean) Whether the cluster orchestrator is disabled
8688
- `node_preferences` (Block List, Max: 1) Node preferences for Cluster Orchestrator (see [below for nested schema](#nestedblock--node_preferences))
8789
- `replacement_schedule` (Block List, Max: 1) Replacement schedule for Cluster Orchestrator (see [below for nested schema](#nestedblock--replacement_schedule))
8890

examples/resources/harness_cluster_orchestrator_config/resource.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
resource "harness_cluster_orchestrator_config" "example" {
22
orchestrator_id = "orch-cvifpfl9rbg8neldj97g"
3+
disabled = false # Set to true to disable the orchestrator
34
distribution {
45
base_ondemand_capacity = 2
56
ondemand_replica_percentage = 50

internal/service/platform/cluster_orchestrator/clusterorch_config_data_source.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ func DataSourceClusterOrchestratorConfig() *schema.Resource {
2222
Type: schema.TypeString,
2323
Required: true,
2424
},
25+
"disabled": {
26+
Description: "Whether the cluster orchestrator is disabled",
27+
Type: schema.TypeBool,
28+
Optional: true,
29+
},
2530
"distribution": {
2631
Description: "Spot and Ondemand Distribution Preferences for workload replicas",
2732
Type: schema.TypeList,

internal/service/platform/cluster_orchestrator/clusterorch_config_resource.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ func ResourceClusterOrchestratorConfig() *schema.Resource {
5353
Type: schema.TypeString,
5454
Required: true,
5555
},
56+
"disabled": {
57+
Description: "Whether the cluster orchestrator is disabled",
58+
Type: schema.TypeBool,
59+
Optional: true,
60+
Default: false,
61+
},
5662
"distribution": {
5763
Description: "Spot and Ondemand Distribution Preferences for workload replicas",
5864
Type: schema.TypeList,
@@ -403,13 +409,27 @@ func resourceClusterOrchestratorConfigCreateOrUpdate(ctx context.Context, d *sch
403409
return helpers.HandleApiError(err, d, httpResp)
404410
}
405411

406-
if resp.Success != true {
412+
if !resp.Success {
407413
return diag.Errorf(strings.Join(resp.Errors, ","))
408414
}
415+
416+
disabled := d.Get("disabled").(bool)
417+
if diags := updateClusterOrchestratorStatus(ctx, c, orchID, disabled); diags.HasError() {
418+
return diags
419+
}
420+
409421
d.SetId(orchID)
410422
return nil
411423
}
412424

425+
func updateClusterOrchestratorStatus(ctx context.Context, c *nextgen.APIClient, orchID string, disabled bool) diag.Diagnostics {
426+
_, httpResp, err := c.CloudCostClusterOrchestratorApi.ToggleClusterOrchestratorState(ctx, c.AccountId, orchID, disabled)
427+
if err != nil {
428+
return helpers.HandleApiError(err, nil, httpResp)
429+
}
430+
return nil
431+
}
432+
413433
func resourceClusterOrchestratorConfigDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
414434
return nil
415435
}

internal/service/platform/cluster_orchestrator/clusterorch_config_test.go

Lines changed: 102 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,41 @@ func TestResourceClusterOrchestratorConfig(t *testing.T) {
1919
{
2020
Config: testClusterOrchConfig(orchID),
2121
Check: resource.ComposeTestCheckFunc(
22-
resource.TestCheckResourceAttr(resourceName, "orchID", orchID),
22+
resource.TestCheckResourceAttr(resourceName, "orchestrator_id", orchID),
23+
resource.TestCheckResourceAttr(resourceName, "disabled", "false"),
24+
),
25+
},
26+
},
27+
})
28+
}
29+
30+
func TestResourceClusterOrchestratorConfigDisabled(t *testing.T) {
31+
orchID := "terraform-clusterorch-disabled-test"
32+
resourceName := "harness_cluster_orchestrator_config.test"
33+
34+
resource.UnitTest(t, resource.TestCase{
35+
PreCheck: func() { acctest.TestAccPreCheck(t) },
36+
ProviderFactories: acctest.ProviderFactories,
37+
Steps: []resource.TestStep{
38+
{
39+
Config: testClusterOrchConfigDisabled(orchID, false),
40+
Check: resource.ComposeTestCheckFunc(
41+
resource.TestCheckResourceAttr(resourceName, "orchestrator_id", orchID),
42+
resource.TestCheckResourceAttr(resourceName, "disabled", "false"),
43+
),
44+
},
45+
{
46+
Config: testClusterOrchConfigDisabled(orchID, true),
47+
Check: resource.ComposeTestCheckFunc(
48+
resource.TestCheckResourceAttr(resourceName, "orchestrator_id", orchID),
49+
resource.TestCheckResourceAttr(resourceName, "disabled", "true"),
50+
),
51+
},
52+
{
53+
Config: testClusterOrchConfigDisabled(orchID, false),
54+
Check: resource.ComposeTestCheckFunc(
55+
resource.TestCheckResourceAttr(resourceName, "orchestrator_id", orchID),
56+
resource.TestCheckResourceAttr(resourceName, "disabled", "false"),
2357
),
2458
},
2559
},
@@ -30,6 +64,7 @@ func testClusterOrchConfig(orchID string) string {
3064
return fmt.Sprintf(`
3165
resource "harness_cluster_orchestrator_config" "test" {
3266
orchestrator_id = "%s"
67+
disabled = false
3368
distribution {
3469
base_ondemand_capacity = 1
3570
ondemand_replica_percentage = 60
@@ -90,3 +125,69 @@ func testClusterOrchConfig(orchID string) string {
90125
}
91126
`, orchID)
92127
}
128+
129+
func testClusterOrchConfigDisabled(orchID string, disabled bool) string {
130+
return fmt.Sprintf(`
131+
resource "harness_cluster_orchestrator_config" "test" {
132+
orchestrator_id = "%s"
133+
disabled = %t
134+
distribution {
135+
base_ondemand_capacity = 1
136+
ondemand_replica_percentage = 60
137+
selector = "ALL"
138+
strategy = "COST OPTIMIZED"
139+
}
140+
binpacking {
141+
pod_eviction {
142+
threshold {
143+
cpu = 60
144+
memory = 80
145+
}
146+
}
147+
disruption {
148+
criteria = "EmptyOrUnderUtilized"
149+
delay = "10m"
150+
budget {
151+
reasons = ["Drift","UnderUtilized","Empty"]
152+
nodes = "20"
153+
schedule {
154+
frequency = "@daily"
155+
duration = "10m"
156+
}
157+
}
158+
budget {
159+
reasons = ["Drift","Empty"]
160+
nodes = "1"
161+
schedule {
162+
frequency = "@monthly"
163+
duration = "10m"
164+
}
165+
}
166+
}
167+
}
168+
node_preferences {
169+
ttl = "1h"
170+
reverse_fallback_interval = "6h"
171+
}
172+
commitment_integration {
173+
enabled = true
174+
master_account_id = "dummyAccountId"
175+
}
176+
replacement_schedule {
177+
window_type = "Custom"
178+
applies_to {
179+
consolidation = true
180+
harness_pod_eviction = true
181+
reverse_fallback = true
182+
}
183+
window_details {
184+
days = ["SUN", "WED", "SAT"]
185+
time_zone = "Asia/Calcutta"
186+
all_day = false
187+
start_time = "10:30"
188+
end_time = "11:30"
189+
}
190+
}
191+
}
192+
`, orchID, disabled)
193+
}

internal/service/platform/cluster_orchestrator/service.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ func parseTimeInDay(timeInDayStr string, defaultTimeInDay nextgen.TimeInDayForWi
191191

192192
func readClusterOrchConfig(d *schema.ResourceData, orch *nextgen.ClusterOrchestrator) {
193193
d.SetId(orch.ID)
194+
d.Set("disabled", orch.Disabled)
194195
d.Set("distribution", []interface{}{map[string]interface{}{
195196
"base_ondemand_capacity": orch.Config.BaseOnDemandCapacity,
196197
"ondemand_replica_percentage": orch.Config.OnDemandSplit,

0 commit comments

Comments
 (0)