/
data_akamai_datastream_activation_history.go
115 lines (99 loc) · 3.03 KB
/
data_akamai_datastream_activation_history.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
package datastream
import (
"context"
"fmt"
"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"
"github.com/akamai/AkamaiOPEN-edgegrid-golang/v8/pkg/datastream"
)
func dataAkamaiDatastreamActivationHistory() *schema.Resource {
return &schema.Resource{
ReadContext: dataAkamaiDatastreamActivationHistoryRead,
Schema: map[string]*schema.Schema{
"stream_id": {
Type: schema.TypeInt,
Required: true,
Description: "Identifies the stream",
},
"activations": {
Type: schema.TypeList,
Computed: true,
Description: "Provides detailed information about an activation history for a version of a stream",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"stream_id": {
Type: schema.TypeInt,
Required: true,
Description: "Identifies the stream",
},
"modified_by": {
Type: schema.TypeString,
Computed: true,
Description: "The username who activated or deactivated the stream",
},
"modified_date": {
Type: schema.TypeString,
Computed: true,
Description: "The date and time when activation status was modified",
},
"stream_version": {
Type: schema.TypeInt,
Computed: true,
Description: "Identifies the version of the stream",
},
"status": {
Type: schema.TypeString,
Computed: true,
Description: "Stream Status",
},
},
},
},
},
}
}
func populateSchemaFieldsWithActivationHistory(ac []datastream.ActivationHistoryEntry, d *schema.ResourceData) error {
var activations []map[string]interface{}
for _, a := range ac {
v := map[string]interface{}{
"stream_id": a.StreamID,
"stream_version": a.StreamVersion,
"modified_by": a.ModifiedBy,
"modified_date": a.ModifiedDate,
"status": a.Status,
}
activations = append(activations, v)
}
fields := map[string]interface{}{
"activations": activations,
}
err := tf.SetAttrs(d, fields)
if err != nil {
return fmt.Errorf("could not set schema attributes: %s", err)
}
return nil
}
func dataAkamaiDatastreamActivationHistoryRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
meta := meta.Must(m)
log := meta.Log("DataStream", "dataAkamaiDatastreamActivationHistoryRead")
client := inst.Client(meta)
streamID, err := tf.GetIntValue("stream_id", d)
if err != nil {
return diag.FromErr(err)
}
log.Debug("Getting activation history")
activationHistory, err := client.GetActivationHistory(ctx, datastream.GetActivationHistoryRequest{
StreamID: int64(streamID),
})
if err != nil {
return diag.FromErr(err)
}
err = populateSchemaFieldsWithActivationHistory(activationHistory, d)
if err != nil {
return diag.FromErr(err)
}
d.SetId(fmt.Sprintf("%d", streamID))
return nil
}