/
data_akamai_botman_custom_bot_category_sequence.go
64 lines (54 loc) · 1.71 KB
/
data_akamai_botman_custom_bot_category_sequence.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
package botman
import (
"context"
"strconv"
"github.com/akamai/AkamaiOPEN-edgegrid-golang/v8/pkg/botman"
"github.com/akamai/terraform-provider-akamai/v6/pkg/common/tf"
"github.com/akamai/terraform-provider-akamai/v6/pkg/meta"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func dataSourceCustomBotCategorySequence() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceCustomBotCategorySequenceRead,
Schema: map[string]*schema.Schema{
"config_id": {
Type: schema.TypeInt,
Required: true,
},
"category_ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
},
}
}
func dataSourceCustomBotCategorySequenceRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
meta := meta.Must(m)
client := inst.Client(meta)
logger := meta.Log("botman", "dataSourceCustomBotCategorySequenceRead")
logger.Debugf("in dataSourceCustomBotCategorySequenceRead")
configID, err := tf.GetIntValue("config_id", d)
if err != nil {
return diag.FromErr(err)
}
version, err := getLatestConfigVersion(ctx, configID, m)
if err != nil {
return diag.FromErr(err)
}
request := botman.GetCustomBotCategorySequenceRequest{
ConfigID: int64(configID),
Version: int64(version),
}
response, err := client.GetCustomBotCategorySequence(ctx, request)
if err != nil {
logger.Errorf("calling 'GetCustomBotCategorySequence': %s", err.Error())
return diag.FromErr(err)
}
if err := d.Set("category_ids", response.Sequence); err != nil {
return diag.Errorf("%s: %s", tf.ErrValueSet, err.Error())
}
d.SetId(strconv.Itoa(configID))
return nil
}