Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf42521d

Browse files
committed
add coder_monitoring component
1 parentc9dbd6f commitf42521d

File tree

2 files changed

+165
-0
lines changed

2 files changed

+165
-0
lines changed

‎provider/monitoring.go‎

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
package provider
2+
3+
import (
4+
"context"
5+
6+
"github.com/google/uuid"
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
8+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
9+
"github.com/mitchellh/mapstructure"
10+
)
11+
12+
typeMonitoringstruct {
13+
Thresholdint
14+
MemoryThresholdint
15+
DiskThresholdint
16+
Disks []string
17+
Enabledbool
18+
MemoryEnabledbool
19+
DiskEnabledbool
20+
AgentIDstring
21+
Validation []Validation
22+
}
23+
24+
funcmonitoringDataSource()*schema.Resource {
25+
return&schema.Resource{
26+
SchemaVersion:1,
27+
28+
Description:"Use this data source to configure editable options for workspaces.",
29+
ReadContext:func(ctx context.Context,rd*schema.ResourceData,iinterface{}) diag.Diagnostics {
30+
rd.SetId(uuid.NewString())
31+
32+
fixedValidation,err:=fixValidationResourceData(rd.GetRawConfig(),rd.Get("validation"))
33+
iferr!=nil {
34+
returndiag.FromErr(err)
35+
}
36+
37+
err=rd.Set("validation",fixedValidation)
38+
iferr!=nil {
39+
returndiag.FromErr(err)
40+
}
41+
42+
varmonitoringMonitoring
43+
err=mapstructure.Decode(struct {
44+
Thresholdinterface{}
45+
MemoryThresholdinterface{}
46+
DiskThresholdinterface{}
47+
Disksinterface{}
48+
Enabledinterface{}
49+
MemoryEnabledinterface{}
50+
DiskEnabledinterface{}
51+
AgentIDinterface{}
52+
Validationinterface{}
53+
}{
54+
Threshold:rd.Get("threshold"),
55+
MemoryThreshold:rd.Get("memory_threshold"),
56+
DiskThreshold:rd.Get("disk_threshold"),
57+
Disks:rd.Get("disks"),
58+
Enabled:rd.Get("enabled"),
59+
MemoryEnabled:rd.Get("memory_enabled"),
60+
DiskEnabled:rd.Get("disk_enabled"),
61+
AgentID:rd.Get("agent_id"),
62+
Validation:fixedValidation,
63+
},&monitoring)
64+
iferr!=nil {
65+
returndiag.FromErr(err)
66+
}
67+
68+
returnnil
69+
},
70+
Schema:map[string]*schema.Schema{
71+
"threshold": {
72+
Type:schema.TypeInt,
73+
Optional:true,
74+
Description:"The threshold for the monitoring module.",
75+
},
76+
"memory_threshold": {
77+
Type:schema.TypeInt,
78+
Optional:true,
79+
Description:"The memory threshold for the monitoring module.",
80+
},
81+
"disk_threshold": {
82+
Type:schema.TypeInt,
83+
Optional:true,
84+
Description:"The disk threshold for the monitoring module.",
85+
},
86+
"disks": {
87+
Type:schema.TypeList,
88+
Optional:true,
89+
MaxItems:10,
90+
Description:"The disks to monitor.",
91+
Elem:&schema.Schema{
92+
Type:schema.TypeString,
93+
},
94+
},
95+
"enabled": {
96+
Type:schema.TypeBool,
97+
Optional:true,
98+
Description:"Whether the monitoring module is enabled.",
99+
},
100+
"memory_enabled": {
101+
Type:schema.TypeBool,
102+
Optional:true,
103+
Description:"Whether the memory monitoring module is enabled.",
104+
},
105+
"disk_enabled": {
106+
Type:schema.TypeBool,
107+
Optional:true,
108+
Description:"Whether the disk monitoring module is enabled.",
109+
},
110+
"agent_id": {
111+
Type:schema.TypeString,
112+
Description:"The ID of the agent to use for the monitoring module.",
113+
ForceNew:true,
114+
Optional:false,
115+
},
116+
"validation": {
117+
Type:schema.TypeList,
118+
MaxItems:1,
119+
Optional:true,
120+
Description:"Validate the input of a parameter.",
121+
Elem:&schema.Resource{
122+
Schema:map[string]*schema.Schema{
123+
"min": {
124+
Type:schema.TypeInt,
125+
Optional:true,
126+
Description:"The minimum of a number parameter.",
127+
},
128+
"min_disabled": {
129+
Type:schema.TypeBool,
130+
Computed:true,
131+
Description:"Helper field to check if min is present",
132+
},
133+
"max": {
134+
Type:schema.TypeInt,
135+
Optional:true,
136+
Description:"The maximum of a number parameter.",
137+
},
138+
"max_disabled": {
139+
Type:schema.TypeBool,
140+
Computed:true,
141+
Description:"Helper field to check if max is present",
142+
},
143+
"monotonic": {
144+
Type:schema.TypeString,
145+
Optional:true,
146+
Description:"Number monotonicity, either increasing or decreasing.",
147+
},
148+
"regex": {
149+
Type:schema.TypeString,
150+
ConflictsWith: []string{"validation.0.min","validation.0.max","validation.0.monotonic"},
151+
Description:"A regex for the input parameter to match against.",
152+
Optional:true,
153+
},
154+
"error": {
155+
Type:schema.TypeString,
156+
Optional:true,
157+
Description:"An error message to display if the value breaks the validation rules. The following placeholders are supported: {max}, {min}, and {value}.",
158+
},
159+
},
160+
},
161+
},
162+
},
163+
}
164+
}

‎provider/provider.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ func New() *schema.Provider {
6565
"coder_workspace_tags":workspaceTagDataSource(),
6666
"coder_provisioner":provisionerDataSource(),
6767
"coder_parameter":parameterDataSource(),
68+
"coder_monitoring":monitoringDataSource(),
6869
"coder_external_auth":externalAuthDataSource(),
6970
"coder_workspace_owner":workspaceOwnerDataSource(),
7071
},

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp