@@ -53,6 +53,14 @@ func resourceSysdigMonitorTeam() *schema.Resource {
5353 Type : schema .TypeString ,
5454 Optional : true ,
5555 },
56+ "enable_ibm_platform_metrics" : {
57+ Type : schema .TypeBool ,
58+ Optional : true ,
59+ },
60+ "ibm_platform_metrics" : {
61+ Type : schema .TypeString ,
62+ Optional : true ,
63+ },
5664 "can_use_sysdig_capture" : {
5765 Type : schema .TypeBool ,
5866 Optional : true ,
@@ -136,12 +144,13 @@ func getMonitorTeamClient(c SysdigClients) (v2.TeamInterface, error) {
136144}
137145
138146func resourceSysdigMonitorTeamCreate (ctx context.Context , d * schema.ResourceData , meta interface {}) diag.Diagnostics {
139- client , err := getMonitorTeamClient (meta .(SysdigClients ))
147+ clients := meta .(SysdigClients )
148+ client , err := getMonitorTeamClient (clients )
140149 if err != nil {
141150 return diag .FromErr (err )
142151 }
143152
144- team := teamFromResourceData (d )
153+ team := teamFromResourceData (d , clients . GetClientType () )
145154 team .Products = []string {"SDC" }
146155
147156 team , err = client .CreateTeam (ctx , team )
@@ -150,14 +159,15 @@ func resourceSysdigMonitorTeamCreate(ctx context.Context, d *schema.ResourceData
150159 }
151160
152161 d .SetId (strconv .Itoa (team .ID ))
153- _ = d . Set ( "version" , team . Version )
162+ resourceSysdigMonitorTeamRead ( ctx , d , meta )
154163
155164 return nil
156165}
157166
158167// Retrieves the information of a resource form the file and loads it in Terraform
159168func resourceSysdigMonitorTeamRead (ctx context.Context , d * schema.ResourceData , meta interface {}) diag.Diagnostics {
160- client , err := getMonitorTeamClient (meta .(SysdigClients ))
169+ clients := meta .(SysdigClients )
170+ client , err := getMonitorTeamClient (clients )
161171 if err != nil {
162172 return diag .FromErr (err )
163173 }
@@ -183,9 +193,22 @@ func resourceSysdigMonitorTeamRead(ctx context.Context, d *schema.ResourceData,
183193 _ = d .Set ("user_roles" , userMonitorRolesToSet (t .UserRoles ))
184194 _ = d .Set ("entrypoint" , entrypointToSet (t .EntryPoint ))
185195
196+ if clients .GetClientType () == IBMMonitor {
197+ resourceSysdigMonitorTeamReadIBM (d , & t )
198+ }
199+
186200 return nil
187201}
188202
203+ func resourceSysdigMonitorTeamReadIBM (d * schema.ResourceData , t * v2.Team ) {
204+ var ibmPlatformMetrics * string
205+ if t .NamespaceFilters != nil {
206+ ibmPlatformMetrics = t .NamespaceFilters .IBMPlatformMetrics
207+ }
208+ _ = d .Set ("enable_ibm_platform_metrics" , t .CanUseBeaconMetrics )
209+ _ = d .Set ("ibm_platform_metrics" , ibmPlatformMetrics )
210+ }
211+
189212func userMonitorRolesToSet (userRoles []v2.UserRoles ) (res []map [string ]interface {}) {
190213 for _ , role := range userRoles {
191214 if role .Admin { // Admins are added by default, so skip them
@@ -214,12 +237,13 @@ func entrypointToSet(entrypoint *v2.EntryPoint) (res []map[string]interface{}) {
214237}
215238
216239func resourceSysdigMonitorTeamUpdate (ctx context.Context , d * schema.ResourceData , meta interface {}) diag.Diagnostics {
217- client , err := getMonitorTeamClient (meta .(SysdigClients ))
240+ clients := meta .(SysdigClients )
241+ client , err := getMonitorTeamClient (clients )
218242 if err != nil {
219243 return diag .FromErr (err )
220244 }
221245
222- t := teamFromResourceData (d )
246+ t := teamFromResourceData (d , clients . GetClientType () )
223247 t .Products = []string {"SDC" }
224248
225249 t .Version = d .Get ("version" ).(int )
@@ -230,6 +254,7 @@ func resourceSysdigMonitorTeamUpdate(ctx context.Context, d *schema.ResourceData
230254 return diag .FromErr (err )
231255 }
232256
257+ resourceSysdigMonitorTeamRead (ctx , d , meta )
233258 return nil
234259}
235260
@@ -248,7 +273,19 @@ func resourceSysdigMonitorTeamDelete(ctx context.Context, d *schema.ResourceData
248273 return nil
249274}
250275
251- func teamFromResourceData (d * schema.ResourceData ) v2.Team {
276+ func updateNamespaceFilters (filters * v2.NamespaceFilters , update v2.NamespaceFilters ) * v2.NamespaceFilters {
277+ if filters == nil {
278+ filters = & v2.NamespaceFilters {}
279+ }
280+
281+ if update .IBMPlatformMetrics != nil {
282+ filters .IBMPlatformMetrics = update .IBMPlatformMetrics
283+ }
284+
285+ return filters
286+ }
287+
288+ func teamFromResourceData (d * schema.ResourceData , clientType ClientType ) v2.Team {
252289 canUseSysdigCapture := d .Get ("can_use_sysdig_capture" ).(bool )
253290 canUseCustomEvents := d .Get ("can_see_infrastructure_events" ).(bool )
254291 canUseAwsMetrics := d .Get ("can_use_aws_data" ).(bool )
@@ -282,5 +319,21 @@ func teamFromResourceData(d *schema.ResourceData) v2.Team {
282319 t .EntryPoint .Selection = val .(string )
283320 }
284321
322+ if clientType == IBMMonitor {
323+ teamFromResourceDataIBM (d , & t )
324+ }
325+
285326 return t
286327}
328+
329+ func teamFromResourceDataIBM (d * schema.ResourceData , t * v2.Team ) {
330+ canUseBeaconMetrics := d .Get ("enable_ibm_platform_metrics" ).(bool )
331+ t .CanUseBeaconMetrics = & canUseBeaconMetrics
332+
333+ if v , ok := d .GetOk ("ibm_platform_metrics" ); ok {
334+ metrics := v .(string )
335+ t .NamespaceFilters = updateNamespaceFilters (t .NamespaceFilters , v2.NamespaceFilters {
336+ IBMPlatformMetrics : & metrics ,
337+ })
338+ }
339+ }
0 commit comments