This repository has been archived by the owner on Jul 22, 2020. It is now read-only.
forked from rancher/terraform-provider-rancher2
/
data_source_rancher2_project_logging.go
130 lines (120 loc) · 2.77 KB
/
data_source_rancher2_project_logging.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
119
120
121
122
123
124
125
126
127
128
129
130
package rancher2
import (
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)
func dataSourceRancher2ProjectLogging() *schema.Resource {
return &schema.Resource{
Read: dataSourceRancher2ProjectLoggingRead,
Schema: map[string]*schema.Schema{
"project_id": {
Type: schema.TypeString,
Required: true,
},
"kind": {
Type: schema.TypeString,
Computed: true,
},
"custom_target_config": {
Type: schema.TypeList,
MaxItems: 1,
Computed: true,
Elem: &schema.Resource{
Schema: loggingCustomTargetConfigFields(),
},
},
"enable_json_parsing": {
Type: schema.TypeBool,
Computed: true,
Description: "Optional enable json log parsing",
},
"elasticsearch_config": {
Type: schema.TypeList,
MaxItems: 1,
Computed: true,
Elem: &schema.Resource{
Schema: loggingElasticsearchConfigFields(),
},
},
"fluentd_config": {
Type: schema.TypeList,
MaxItems: 1,
Computed: true,
Elem: &schema.Resource{
Schema: loggingFluentdConfigFields(),
},
},
"kafka_config": {
Type: schema.TypeList,
MaxItems: 1,
Computed: true,
Elem: &schema.Resource{
Schema: loggingKafkaConfigFields(),
},
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"namespace_id": {
Type: schema.TypeString,
Computed: true,
},
"output_flush_interval": {
Type: schema.TypeInt,
Computed: true,
},
"output_tags": {
Type: schema.TypeMap,
Computed: true,
},
"splunk_config": {
Type: schema.TypeList,
MaxItems: 1,
Computed: true,
Elem: &schema.Resource{
Schema: loggingSplunkConfigFields(),
},
},
"syslog_config": {
Type: schema.TypeList,
MaxItems: 1,
Computed: true,
Elem: &schema.Resource{
Schema: loggingSyslogConfigFields(),
},
},
"annotations": {
Type: schema.TypeMap,
Computed: true,
},
"labels": {
Type: schema.TypeMap,
Computed: true,
},
},
}
}
func dataSourceRancher2ProjectLoggingRead(d *schema.ResourceData, meta interface{}) error {
client, err := meta.(*Config).ManagementClient()
if err != nil {
return err
}
projectID := d.Get("project_id").(string)
filters := map[string]interface{}{
"projectId": projectID,
}
listOpts := NewListOpts(filters)
projectLoggings, err := client.ProjectLogging.List(listOpts)
if err != nil {
return err
}
count := len(projectLoggings.Data)
if count <= 0 {
return fmt.Errorf("[ERROR] project logging on project ID \"%s\" not found", projectID)
}
if count > 1 {
return fmt.Errorf("[ERROR] found %d project logging on project ID \"%s\"", count, projectID)
}
return flattenProjectLogging(d, &projectLoggings.Data[0])
}