This repository has been archived by the owner on Mar 5, 2024. It is now read-only.
generated from hashicorp/terraform-provider-scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 1
/
data_source_challenges.go
93 lines (85 loc) · 2.2 KB
/
data_source_challenges.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
package provider
import (
"context"
"github.com/PsypherPunk/terraform-provider-ctfd/internal/api"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func dataSourceChallengesRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(*api.Client)
var diags diag.Diagnostics
challenges, err := client.GetChallenges()
if err != nil {
return diag.FromErr(err)
}
if err := d.Set("challenges", challenges); err != nil {
return diag.FromErr(err)
}
// TODO: determine based on contents of `challenges`?
d.SetId("challenges")
return diags
}
func dataSourceChallenges() *schema.Resource {
return &schema.Resource{
Description: "Get a list of the current challenges.",
ReadContext: dataSourceChallengesRead,
Schema: map[string]*schema.Schema{
"challenges": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": &schema.Schema{
Type: schema.TypeInt,
Computed: true,
},
"type": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
"name": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
"value": &schema.Schema{
Type: schema.TypeInt,
Computed: true,
},
"solves": &schema.Schema{
Type: schema.TypeInt,
Computed: true,
},
"solved_by_me": &schema.Schema{
Type: schema.TypeBool,
Computed: true,
},
"category": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
"tags": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"value": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
},
},
},
"template": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
"script": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
},
},
},
},
}
}