@@ -2,6 +2,7 @@ package sysdig
22
33import (
44 "context"
5+ "fmt"
56 v2 "github.com/draios/terraform-provider-sysdig/sysdig/internal/client/v2"
67 "strconv"
78 "time"
@@ -22,7 +23,22 @@ func resourceSysdigSecureTeam() *schema.Resource {
2223 Importer : & schema.ResourceImporter {
2324 StateContext : schema .ImportStatePassthroughContext ,
2425 },
26+ CustomizeDiff : func (ctx context.Context , diff * schema.ResourceDiff , i interface {}) error {
27+ plan := diff .GetRawPlan ().AsValueMap ()
28+ zoneIDsPlan := plan [SchemaZonesIDsKey ]
29+ allZonesPlan := plan [SchemaAllZones ]
2530
31+ var nonEmptyZoneIDs bool
32+ if ! zoneIDsPlan .IsNull () && len (zoneIDsPlan .AsValueSlice ()) > 0 {
33+ nonEmptyZoneIDs = true
34+ }
35+
36+ if nonEmptyZoneIDs && allZonesPlan .True () {
37+ return fmt .Errorf ("if %s is enabled, %s must be omitted" , SchemaAllZones , SchemaZonesIDsKey )
38+ }
39+
40+ return nil
41+ },
2642 Timeouts : & schema.ResourceTimeout {
2743 Create : schema .DefaultTimeout (timeout ),
2844 Update : schema .DefaultTimeout (timeout ),
@@ -94,6 +110,18 @@ func resourceSysdigSecureTeam() *schema.Resource {
94110 Type : schema .TypeInt ,
95111 Computed : true ,
96112 },
113+ SchemaZonesIDsKey : {
114+ Optional : true ,
115+ Type : schema .TypeList ,
116+ Elem : & schema.Schema {
117+ Type : schema .TypeInt ,
118+ },
119+ },
120+ SchemaAllZones : {
121+ Optional : true ,
122+ Type : schema .TypeBool ,
123+ Default : false ,
124+ },
97125 },
98126 }
99127}
@@ -164,6 +192,16 @@ func resourceSysdigSecureTeamRead(ctx context.Context, d *schema.ResourceData, m
164192 _ = d .Set ("default_team" , t .DefaultTeam )
165193 _ = d .Set ("user_roles" , userSecureRolesToSet (t .UserRoles ))
166194
195+ err = d .Set (SchemaZonesIDsKey , t .ZoneIDs )
196+ if err != nil {
197+ return diag .FromErr (err )
198+ }
199+
200+ err = d .Set (SchemaAllZones , t .AllZones )
201+ if err != nil {
202+ return diag .FromErr (err )
203+ }
204+
167205 if clients .GetClientType () == IBMSecure {
168206 resourceSysdigTeamReadIBM (d , & t )
169207 }
@@ -225,6 +263,7 @@ func resourceSysdigSecureTeamDelete(ctx context.Context, d *schema.ResourceData,
225263func secureTeamFromResourceData (d * schema.ResourceData , clientType ClientType ) v2.Team {
226264 canUseSysdigCapture := d .Get ("use_sysdig_capture" ).(bool )
227265 canUseAwsMetrics := new (bool )
266+ allZones := d .Get (SchemaAllZones ).(bool )
228267 t := v2.Team {
229268 Theme : d .Get ("theme" ).(string ),
230269 Name : d .Get ("name" ).(string ),
@@ -234,6 +273,7 @@ func secureTeamFromResourceData(d *schema.ResourceData, clientType ClientType) v
234273 CanUseSysdigCapture : & canUseSysdigCapture ,
235274 CanUseAwsMetrics : canUseAwsMetrics ,
236275 DefaultTeam : d .Get ("default_team" ).(bool ),
276+ AllZones : allZones ,
237277 }
238278
239279 userRoles := make ([]v2.UserRoles , 0 )
@@ -246,6 +286,12 @@ func secureTeamFromResourceData(d *schema.ResourceData, clientType ClientType) v
246286 }
247287 t .UserRoles = userRoles
248288
289+ zonesData := d .Get ("zone_ids" ).([]interface {})
290+ t .ZoneIDs = make ([]int , len (zonesData ))
291+ for i , z := range zonesData {
292+ t .ZoneIDs [i ] = z .(int )
293+ }
294+
249295 if clientType == IBMSecure {
250296 teamFromResourceDataIBM (d , & t )
251297 }
0 commit comments