|
| 1 | +package sysdig |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + |
| 6 | + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" |
| 7 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" |
| 8 | +) |
| 9 | + |
| 10 | +func dataSourceSysdigMonitorTeams() *schema.Resource { |
| 11 | + return &schema.Resource{ |
| 12 | + ReadContext: dataSourceSysdigMonitorTeamsRead, |
| 13 | + Schema: map[string]*schema.Schema{ |
| 14 | + "teams": { |
| 15 | + Type: schema.TypeList, |
| 16 | + Computed: true, |
| 17 | + Elem: &schema.Resource{ |
| 18 | + Schema: map[string]*schema.Schema{ |
| 19 | + "id": { |
| 20 | + Type: schema.TypeInt, |
| 21 | + Computed: true, |
| 22 | + }, |
| 23 | + "name": { |
| 24 | + Type: schema.TypeString, |
| 25 | + Computed: true, |
| 26 | + }, |
| 27 | + "theme": { |
| 28 | + Type: schema.TypeString, |
| 29 | + Computed: true, |
| 30 | + }, |
| 31 | + "description": { |
| 32 | + Type: schema.TypeString, |
| 33 | + Computed: true, |
| 34 | + }, |
| 35 | + "scope_by": { |
| 36 | + Type: schema.TypeString, |
| 37 | + Computed: true, |
| 38 | + }, |
| 39 | + "filter": { |
| 40 | + Type: schema.TypeString, |
| 41 | + Computed: true, |
| 42 | + }, |
| 43 | + "can_use_sysdig_capture": { |
| 44 | + Type: schema.TypeBool, |
| 45 | + Computed: true, |
| 46 | + }, |
| 47 | + "can_see_infrastructure_events": { |
| 48 | + Type: schema.TypeBool, |
| 49 | + Computed: true, |
| 50 | + }, |
| 51 | + "can_use_aws_data": { |
| 52 | + Type: schema.TypeBool, |
| 53 | + Computed: true, |
| 54 | + }, |
| 55 | + "default_team": { |
| 56 | + Type: schema.TypeBool, |
| 57 | + Computed: true, |
| 58 | + }, |
| 59 | + "user_roles": { |
| 60 | + Type: schema.TypeSet, |
| 61 | + Computed: true, |
| 62 | + Elem: &schema.Resource{ |
| 63 | + Schema: map[string]*schema.Schema{ |
| 64 | + "email": { |
| 65 | + Type: schema.TypeString, |
| 66 | + Computed: true, |
| 67 | + }, |
| 68 | + "role": { |
| 69 | + Type: schema.TypeString, |
| 70 | + Computed: true, |
| 71 | + }, |
| 72 | + }, |
| 73 | + }, |
| 74 | + }, |
| 75 | + "entrypoint": { |
| 76 | + Type: schema.TypeList, |
| 77 | + Computed: true, |
| 78 | + Elem: &schema.Resource{ |
| 79 | + Schema: map[string]*schema.Schema{ |
| 80 | + "type": { |
| 81 | + Type: schema.TypeString, |
| 82 | + Computed: true, |
| 83 | + }, |
| 84 | + "selection": { |
| 85 | + Type: schema.TypeString, |
| 86 | + Computed: true, |
| 87 | + }, |
| 88 | + }, |
| 89 | + }, |
| 90 | + }, |
| 91 | + "version": { |
| 92 | + Type: schema.TypeInt, |
| 93 | + Computed: true, |
| 94 | + }, |
| 95 | + }, |
| 96 | + }, |
| 97 | + }, |
| 98 | + }, |
| 99 | + } |
| 100 | +} |
| 101 | + |
| 102 | +func dataSourceSysdigMonitorTeamsRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { |
| 103 | + clients := meta.(SysdigClients) |
| 104 | + client, err := getMonitorTeamClient(clients) |
| 105 | + if err != nil { |
| 106 | + return diag.FromErr(err) |
| 107 | + } |
| 108 | + |
| 109 | + teams, err := client.ListTeams(ctx) |
| 110 | + if err != nil { |
| 111 | + return diag.FromErr(err) |
| 112 | + } |
| 113 | + |
| 114 | + var result []map[string]interface{} |
| 115 | + for _, team := range teams { |
| 116 | + result = append(result, map[string]interface{}{ |
| 117 | + "id": team.ID, |
| 118 | + "name": team.Name, |
| 119 | + }) |
| 120 | + } |
| 121 | + d.SetId("sysdig_monitor_teams") |
| 122 | + if err := d.Set("teams", result); err != nil { |
| 123 | + return diag.FromErr(err) |
| 124 | + } |
| 125 | + |
| 126 | + return nil |
| 127 | +} |
0 commit comments