-
Notifications
You must be signed in to change notification settings - Fork 65
/
schema_external_security_groups.go
67 lines (58 loc) · 1.95 KB
/
schema_external_security_groups.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
66
67
package octopusdeploy
import (
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/core"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func expandExternalSecurityGroups(externalSecurityGroups []interface{}) []core.NamedReferenceItem {
expandedExternalSecurityGroups := []core.NamedReferenceItem{}
for _, externalSecurityGroup := range externalSecurityGroups {
if externalSecurityGroup != nil {
rawExternalSecurityGroup := externalSecurityGroup.(map[string]interface{})
displayIDAndName := false
if rawExternalSecurityGroup["display_id_and_name"] != nil {
displayIDAndName = rawExternalSecurityGroup["display_id_and_name"].(bool)
}
displayName := ""
if rawExternalSecurityGroup["display_name"] != nil {
displayName = rawExternalSecurityGroup["display_name"].(string)
}
id := ""
if rawExternalSecurityGroup["id"] != nil {
id = rawExternalSecurityGroup["id"].(string)
}
item := core.NamedReferenceItem{
DisplayIDAndName: displayIDAndName,
DisplayName: displayName,
ID: id,
}
expandedExternalSecurityGroups = append(expandedExternalSecurityGroups, item)
}
}
return expandedExternalSecurityGroups
}
func flattenExternalSecurityGroups(externalSecurityGroups []core.NamedReferenceItem) []interface{} {
flattenedExternalSecurityGroups := []interface{}{}
for _, v := range externalSecurityGroups {
flattenedExternalSecurityGroups = append(flattenedExternalSecurityGroups, map[string]interface{}{
"display_id_and_name": v.DisplayIDAndName,
"display_name": v.DisplayName,
"id": v.ID,
})
}
return flattenedExternalSecurityGroups
}
func getExternalSecurityGroupsSchema() map[string]*schema.Schema {
return map[string]*schema.Schema{
"display_id_and_name": {
Computed: true,
Optional: true,
Type: schema.TypeBool,
},
"display_name": {
Computed: true,
Optional: true,
Type: schema.TypeString,
},
"id": getIDSchema(),
}
}