-
Notifications
You must be signed in to change notification settings - Fork 65
/
schema_machine_cleanup_policy.go
48 lines (41 loc) · 1.39 KB
/
schema_machine_cleanup_policy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package octopusdeploy
import (
"time"
"github.com/OctopusDeploy/go-octopusdeploy/octopusdeploy"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func expandMachineCleanupPolicy(values interface{}) *octopusdeploy.MachineCleanupPolicy {
flattenedValues := values.([]interface{})
flattenedMap := flattenedValues[0].(map[string]interface{})
return &octopusdeploy.MachineCleanupPolicy{
DeleteMachinesBehavior: flattenedMap["delete_machines_behavior"].(string),
DeleteMachinesElapsedTimeSpan: time.Duration(flattenedMap["delete_machines_elapsed_timespan"].(int)),
}
}
func flattenMachineCleanupPolicy(machineCleanupPolicy *octopusdeploy.MachineCleanupPolicy) []interface{} {
if machineCleanupPolicy == nil {
return nil
}
return []interface{}{map[string]interface{}{
"delete_machines_behavior": machineCleanupPolicy.DeleteMachinesBehavior,
"delete_machines_elapsed_timespan": machineCleanupPolicy.DeleteMachinesElapsedTimeSpan,
}}
}
func getMachineCleanupPolicySchema() map[string]*schema.Schema {
return map[string]*schema.Schema{
"delete_machines_behavior": {
Default: "DoNotDelete",
Optional: true,
Type: schema.TypeString,
ValidateDiagFunc: validateValueFunc([]string{
"DeleteUnavailableMachines",
"DoNotDelete",
}),
},
"delete_machines_elapsed_timespan": {
Computed: true,
Optional: true,
Type: schema.TypeInt,
},
}
}