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