@@ -50,13 +50,34 @@ func dataSourceSysdigSecureZone() *schema.Resource {
5050 Type : schema .TypeString ,
5151 Computed : true ,
5252 },
53+ // Not marked Deprecated: rules with v2-compatible syntax are fully supported.
54+ // Only v1 syntax (labels, labelValues, agentTags) is deprecated, but since
55+ // this is a Computed field, SDK v2 has no mechanism for conditional deprecation.
56+ // The resource-side ValidateDiagFunc handles the v1-only warning.
5357 SchemaRulesKey : {
5458 Type : schema .TypeString ,
5559 Computed : true ,
5660 },
61+ SchemaExpressionKey : {
62+ Type : schema .TypeList ,
63+ Computed : true ,
64+ Elem : & schema.Resource {
65+ Schema : map [string ]* schema.Schema {
66+ SchemaFieldKey : {Type : schema .TypeString , Computed : true },
67+ SchemaOperatorKey : {Type : schema .TypeString , Computed : true },
68+ SchemaValueKey : {Type : schema .TypeString , Computed : true },
69+ SchemaValuesKey : {
70+ Type : schema .TypeList ,
71+ Computed : true ,
72+ Elem : & schema.Schema {Type : schema .TypeString },
73+ },
74+ },
75+ },
76+ },
5777 },
5878 },
5979 },
80+
6081 "id" : {
6182 Type : schema .TypeString ,
6283 Optional : true ,
@@ -74,52 +95,80 @@ func dataSourceSysdigSecureZone() *schema.Resource {
7495}
7596
7697func dataSourceSysdigSecureZoneRead (ctx context.Context , d * schema.ResourceData , m any ) diag.Diagnostics {
77- client , err := getZoneClient (m .(SysdigClients ))
98+ clientV2 , err := getZoneV2Client (m .(SysdigClients ))
7899 if err != nil {
79100 return diag .FromErr (err )
80101 }
81-
82- var zone * v2.Zone
102+ var zoneV2 * v2.ZoneV2
83103 zoneIDRaw , hasZoneID := d .GetOk ("id" )
84104 if hasZoneID {
85105 zoneID , err := strconv .Atoi (zoneIDRaw .(string ))
86106 if err != nil {
87- return diag .FromErr (fmt .Errorf ("invalid zone id : %s" , err ))
107+ return diag .FromErr (fmt .Errorf ("error fetching zone by ID : %s" , err ))
88108 }
89- zone , err = client . GetZoneByID (ctx , zoneID )
109+ zoneV2 , err = clientV2 . GetZoneV2 (ctx , zoneID )
90110 if err != nil {
91- return diag .FromErr (fmt .Errorf ("error fetching zone by ID: %s" , err ))
111+ return diag .FromErr (fmt .Errorf ("error fetching zone v2 by ID: %s" , err ))
92112 }
93113 } else if nameRaw , hasName := d .GetOk ("name" ); hasName {
94114 name := nameRaw .(string )
95- zones , err := client . GetZones (ctx , name )
115+ zones , err := clientV2 . GetZonesV2 (ctx , name )
96116 if err != nil {
97117 return diag .FromErr (fmt .Errorf ("error fetching zones: %s" , err ))
98118 }
99119 for _ , z := range zones {
100120 if z .Name == name {
101- zone = & z
121+ zoneV2 = & z
102122 break
103123 }
104124 }
105- if zone == nil {
125+ if zoneV2 == nil {
106126 return diag .FromErr (fmt .Errorf ("zone with name '%s' not found" , name ))
107127 }
128+ zoneV2 , err = clientV2 .GetZoneV2 (ctx , zoneV2 .ID )
129+ if err != nil {
130+ return diag .FromErr (fmt .Errorf ("error fetching zones: %s" , err ))
131+ }
108132 } else {
109133 return diag .FromErr (fmt .Errorf ("either id or name must be specified" ))
110134 }
111135
112- d .SetId (fmt .Sprintf ("%d" , zone .ID ))
113- _ = d .Set (SchemaNameKey , zone .Name )
114- _ = d .Set (SchemaDescriptionKey , zone .Description )
115- _ = d .Set (SchemaIsSystemKey , zone .IsSystem )
116- _ = d .Set (SchemaAuthorKey , zone .Author )
117- _ = d .Set (SchemaLastModifiedBy , zone .LastModifiedBy )
118- _ = d .Set (SchemaLastUpdated , time .UnixMilli (zone .LastUpdated ).Format (time .RFC3339 ))
136+ d .SetId (fmt .Sprintf ("%d" , zoneV2 .ID ))
137+ _ = d .Set (SchemaNameKey , zoneV2 .Name )
138+ _ = d .Set (SchemaDescriptionKey , zoneV2 .Description )
139+ _ = d .Set (SchemaIsSystemKey , zoneV2 .IsSystem )
140+ _ = d .Set (SchemaAuthorKey , zoneV2 .Author )
141+ _ = d .Set (SchemaLastModifiedBy , zoneV2 .LastModifiedBy )
142+ _ = d .Set (SchemaLastUpdated , time .UnixMilli (zoneV2 .LastUpdated ).Format (time .RFC3339 ))
119143
120- if err := d .Set (SchemaScopeKey , fromZoneScopesResponse ( zone . Scopes )); err != nil {
144+ if err := d .Set (SchemaScopeKey , getZoneScopes ( zoneV2 )); err != nil {
121145 return diag .FromErr (fmt .Errorf ("error setting scope: %s" , err ))
122146 }
123147
124148 return nil
125149}
150+
151+ func getZoneScopes (zoneV2 * v2.ZoneV2 ) []any {
152+ // Build expression lookup by filter ID from the v2 response.
153+ out := make ([]any , 0 )
154+ if zoneV2 != nil {
155+ for _ , s := range zoneV2 .Scopes {
156+ for _ , f := range s .Filters {
157+ if f .ID != 0 && len (f .Expressions ) > 0 {
158+ var exprs []any
159+ for _ , e := range f .Expressions {
160+ exprs = append (exprs , flattenExpressionV2 (e ))
161+ }
162+ m := map [string ]any {
163+ SchemaIDKey : f .ID ,
164+ SchemaTargetTypeKey : f .ResourceType ,
165+ SchemaRulesKey : f .Rules ,
166+ }
167+ m [SchemaExpressionKey ] = exprs
168+ out = append (out , m )
169+ }
170+ }
171+ }
172+ }
173+ return out
174+ }
0 commit comments