@@ -2,6 +2,7 @@ package discord
2
2
3
3
import (
4
4
"fmt"
5
+ "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
5
6
6
7
"github.com/bwmarrin/discordgo"
7
8
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
@@ -66,20 +67,11 @@ func baseServerSchema() map[string]*schema.Schema {
66
67
Description : "ID of the channel AFK users will be moved to." ,
67
68
},
68
69
"afk_timeout" : {
69
- Type : schema .TypeInt ,
70
- Optional : true ,
71
- Default : 300 ,
72
- Description : "How many seconds before moving an AFK user." ,
73
- ValidateFunc : func (val interface {}, key string ) (warns []string , errors []error ) {
74
- v := val .(int )
75
- // See: https://discord.com/developers/docs/resources/guild#guild-object-guild-structure
76
- expected := []int {60 , 300 , 900 , 1800 , 3600 }
77
- if ! contains (expected , v ) {
78
- errors = append (errors , fmt .Errorf ("afk_timeout must be set to one of the following values: %d, but got: %d" , expected , v ))
79
- }
80
-
81
- return
82
- },
70
+ Type : schema .TypeInt ,
71
+ Optional : true ,
72
+ Default : 300 ,
73
+ Description : "How many seconds before moving an AFK user." ,
74
+ ValidateFunc : validation .IntInSlice ([]int {60 , 300 , 900 , 1800 , 3600 }),
83
75
},
84
76
"icon_url" : {
85
77
Type : schema .TypeString ,
@@ -122,6 +114,55 @@ func baseServerSchema() map[string]*schema.Schema {
122
114
Computed : true ,
123
115
Description : "The ID of the server." ,
124
116
},
117
+ "roles" : {
118
+ Type : schema .TypeList ,
119
+ Computed : true ,
120
+ Description : "List of roles in the server." ,
121
+ Elem : & schema.Resource {
122
+ Schema : map [string ]* schema.Schema {
123
+ "name" : {
124
+ Type : schema .TypeString ,
125
+ Computed : true ,
126
+ Description : "The name of the role." ,
127
+ },
128
+ "permissions" : {
129
+ Type : schema .TypeInt ,
130
+ Computed : true ,
131
+ Description : "The permission bits of the role." ,
132
+ },
133
+ "color" : {
134
+ Type : schema .TypeInt ,
135
+ Computed : true ,
136
+ Description : "Integer representation of the role color with decimal color code." ,
137
+ },
138
+ "hoist" : {
139
+ Type : schema .TypeBool ,
140
+ Computed : true ,
141
+ Description : "If the role is hoisted." ,
142
+ },
143
+ "mentionable" : {
144
+ Type : schema .TypeBool ,
145
+ Computed : true ,
146
+ Description : "If the role is mentionable." ,
147
+ },
148
+ "position" : {
149
+ Type : schema .TypeInt ,
150
+ Computed : true ,
151
+ Description : "Position of the role. This is reverse indexed, with `@everyone` being `0`." ,
152
+ },
153
+ "managed" : {
154
+ Type : schema .TypeBool ,
155
+ Computed : true ,
156
+ Description : "If role is managed by another service." ,
157
+ },
158
+ "id" : {
159
+ Type : schema .TypeString ,
160
+ Computed : true ,
161
+ Description : "The ID of the role." ,
162
+ },
163
+ },
164
+ },
165
+ },
125
166
}
126
167
}
127
168
@@ -270,6 +311,21 @@ func resourceServerCreate(ctx context.Context, d *schema.ResourceData, m interfa
270
311
d .Set ("icon_hash" , server .Icon )
271
312
d .Set ("splash_hash" , server .Splash )
272
313
314
+ var roleMap []map [string ]interface {}
315
+ for _ , role := range server .Roles {
316
+ roleMap = append (roleMap , map [string ]interface {}{
317
+ "name" : role .Name ,
318
+ "permissions" : role .Permissions ,
319
+ "color" : role .Color ,
320
+ "hoist" : role .Hoist ,
321
+ "mentionable" : role .Mentionable ,
322
+ "position" : role .Position ,
323
+ "managed" : role .Managed ,
324
+ "id" : role .ID ,
325
+ })
326
+ }
327
+ d .Set ("roles" , roleMap )
328
+
273
329
return diags
274
330
}
275
331
@@ -316,7 +372,20 @@ func resourceServerRead(ctx context.Context, d *schema.ResourceData, m interface
316
372
if d .Get ("owner_id" ).(string ) != "" && server .OwnerID != "" {
317
373
d .Set ("owner_id" , server .OwnerID )
318
374
}
319
-
375
+ roleMap := make ([]map [string ]interface {}, len (server .Roles ))
376
+ for _ , role := range server .Roles {
377
+ roleMap = append (roleMap , map [string ]interface {}{
378
+ "name" : role .Name ,
379
+ "permissions" : role .Permissions ,
380
+ "color" : role .Color ,
381
+ "hoist" : role .Hoist ,
382
+ "mentionable" : role .Mentionable ,
383
+ "position" : role .Position ,
384
+ "managed" : role .Managed ,
385
+ "id" : role .ID ,
386
+ })
387
+ }
388
+ d .Set ("roles" , roleMap )
320
389
return diags
321
390
}
322
391
0 commit comments