-
Notifications
You must be signed in to change notification settings - Fork 4
/
datasource_service.go
118 lines (110 loc) · 3.15 KB
/
datasource_service.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package centrify
import (
"fmt"
"strings"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
logger "github.com/marcozj/golang-sdk/logging"
vault "github.com/marcozj/golang-sdk/platform"
"github.com/marcozj/golang-sdk/restapi"
)
func dataSourceService() *schema.Resource {
return &schema.Resource{
Read: dataSourceServiceRead,
Schema: map[string]*schema.Schema{
"system_id": {
Type: schema.TypeString,
Computed: true,
Description: "The target system id where the service runs",
},
"description": {
Type: schema.TypeString,
Computed: true,
Description: "Description of the service",
},
"service_type": {
Type: schema.TypeString,
Computed: true,
},
"service_name": {
Type: schema.TypeString,
Required: true,
Description: "The name of the service to be managed.",
},
"enable_management": {
Type: schema.TypeBool,
Computed: true,
Description: "Enable management of this service password",
},
"admin_account_id": {
Type: schema.TypeString,
Computed: true,
Description: "Administrative account id that used to manage the password for the service",
},
"multiplexed_account_id": {
Type: schema.TypeString,
Computed: true,
Description: "The multiplexed account id to run the service",
},
"restart_service": {
Type: schema.TypeBool,
Computed: true,
Description: "Restart Service when password is rotated",
},
"restart_time_restriction": {
Type: schema.TypeBool,
Computed: true,
Description: "Enforce restart time restrictions",
},
"days_of_week": {
Type: schema.TypeSet,
Computed: true,
Set: schema.HashString,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "Day of the week restart allowed",
},
"restart_start_time": {
Type: schema.TypeString,
Computed: true,
Description: "Start time of the time range restart is allowed",
},
"restart_end_time": {
Type: schema.TypeString,
Computed: true,
Description: "End time of the time range restart is allowed",
},
"use_utc_time": {
Type: schema.TypeBool,
Computed: true,
Description: "Whether to use UTC time",
},
},
}
}
func dataSourceServiceRead(d *schema.ResourceData, m interface{}) error {
logger.Infof("Finding Service")
client := m.(*restapi.RestClient)
object := vault.NewService(client)
object.Name = d.Get("service_name").(string)
// We can't use simple Query method because it doesn't return all attributes
err := object.GetByName()
if err != nil {
return fmt.Errorf("error retrieving Service with name '%s': %s", object.Name, err)
}
d.SetId(object.ID)
schemamap, err := vault.GenerateSchemaMap(object)
if err != nil {
return err
}
//logger.Debugf("Generated Map: %+v", schemamap)
for k, v := range schemamap {
if k == "days_of_week" {
// Convert "value1,value1" to schema.TypeSet
d.Set("days_of_week", schema.NewSet(schema.HashString, StringSliceToInterface(strings.Split(v.(string), ","))))
} else {
d.Set(k, v)
}
}
return nil
}