-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathschema_property_value.go
65 lines (55 loc) · 1.53 KB
/
schema_property_value.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package octopusdeploy
import (
"github.com/OctopusDeploy/go-octopusdeploy/octopusdeploy"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func expandPropertyValue(value interface{}) *octopusdeploy.PropertyValue {
if value == nil {
return nil
}
flattenedValue := value.([]interface{})
if len(flattenedValue) == 0 {
return nil
}
flattenedPropertyValue := flattenedValue[0].(map[string]interface{})
isSensitive := flattenedPropertyValue["is_sensitive"].(bool)
if !isSensitive {
value := flattenedPropertyValue["value"].(string)
return &octopusdeploy.PropertyValue{
IsSensitive: isSensitive,
Value: value,
}
}
return &octopusdeploy.PropertyValue{
IsSensitive: isSensitive,
SensitiveValue: expandSensitiveValue(flattenedPropertyValue["sensitive_value"]),
}
}
func flattenPropertyValue(propertyValue *octopusdeploy.PropertyValue) []interface{} {
if propertyValue == nil {
return nil
}
return []interface{}{map[string]interface{}{
"is_sensitive": propertyValue.IsSensitive,
"sensitive_value": flattenSensitiveValue(propertyValue.SensitiveValue),
"value": propertyValue.Value,
}}
}
func getPropertyValueSchema() map[string]*schema.Schema {
return map[string]*schema.Schema{
"is_sensitive": {
Optional: true,
Type: schema.TypeBool,
},
"sensitive_value": {
Optional: true,
Elem: &schema.Resource{Schema: getSensitiveValueSchema()},
MaxItems: 1,
Type: schema.TypeList,
},
"value": {
Optional: true,
Type: schema.TypeString,
},
}
}