-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathdata_source_agent_access_keys.go
More file actions
91 lines (82 loc) · 2.11 KB
/
data_source_agent_access_keys.go
File metadata and controls
91 lines (82 loc) · 2.11 KB
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
package sysdig
import (
"context"
"net/http"
"strconv"
"time"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func dataSourceSysdigAgentAccessKey() *schema.Resource {
timeout := 5 * time.Minute
return &schema.Resource{
ReadContext: dataSourceSysdigAgentAccessKeyRead,
Timeouts: &schema.ResourceTimeout{
Read: schema.DefaultTimeout(timeout),
},
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeInt,
Required: true,
},
"reservation": {
Type: schema.TypeInt,
Computed: true,
},
"limit": {
Type: schema.TypeInt,
Computed: true,
},
"team_id": {
Type: schema.TypeInt,
Computed: true,
},
"metadata": {
Type: schema.TypeMap,
Computed: true,
},
"enabled": {
Type: schema.TypeBool,
Computed: true,
},
"date_disabled": {
Type: schema.TypeString,
Computed: true,
},
"date_created": {
Type: schema.TypeString,
Computed: true,
},
"access_key": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
// Retrieves the information of a resource form the file and loads it in Terraform
func dataSourceSysdigAgentAccessKeyRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
client, err := meta.(SysdigClients).commonClientV2()
if err != nil {
return diag.FromErr(err)
}
agentKeyID := d.Get("id").(int)
agentAccessKey, statusCode, err := client.GetAgentAccessKeyByID(ctx, strconv.Itoa(agentKeyID))
if err != nil {
if statusCode == http.StatusNotFound {
d.SetId("")
return nil
}
return diag.FromErr(err)
}
d.SetId(strconv.Itoa(agentAccessKey.ID))
_ = d.Set("reservation", agentAccessKey.Reservation)
_ = d.Set("limit", agentAccessKey.Limit)
_ = d.Set("team_id", agentAccessKey.TeamID)
_ = d.Set("metadata", agentAccessKey.Metadata)
_ = d.Set("enabled", agentAccessKey.Enabled)
_ = d.Set("date_disabled", agentAccessKey.DateDisabled)
_ = d.Set("date_created", agentAccessKey.DateCreated)
_ = d.Set("access_key", agentAccessKey.AgentAccessKey)
return nil
}