@@ -38,6 +38,9 @@ var dataSourceConfigTypes = map[string]attr.Type{
3838 "optimizer" : types.ObjectType {
3939 AttrTypes : optimizerTypes , // Shared from resource.go
4040 },
41+ "redirects" : types.ObjectType {
42+ AttrTypes : redirectsTypes , // Shared from resource.go
43+ },
4144}
4245
4346type distributionDataSource struct {
@@ -199,6 +202,57 @@ func (r *distributionDataSource) Schema(_ context.Context, _ datasource.SchemaRe
199202 },
200203 },
201204 },
205+ "redirects" : schema.SingleNestedAttribute {
206+ Computed : true ,
207+ Description : schemaDescriptions ["config_redirects" ],
208+ Attributes : map [string ]schema.Attribute {
209+ "rules" : schema.ListNestedAttribute {
210+ Description : schemaDescriptions ["config_redirects_rules" ],
211+ Computed : true ,
212+ NestedObject : schema.NestedAttributeObject {
213+ Attributes : map [string ]schema.Attribute {
214+ "description" : schema.StringAttribute {
215+ Description : schemaDescriptions ["config_redirects_rule_description" ],
216+ Computed : true ,
217+ },
218+ "enabled" : schema.BoolAttribute {
219+ Computed : true ,
220+ Description : schemaDescriptions ["config_redirects_rule_enabled" ],
221+ },
222+ "target_url" : schema.StringAttribute {
223+ Computed : true ,
224+ Description : schemaDescriptions ["config_redirects_rule_target_url" ],
225+ },
226+ "status_code" : schema.Int32Attribute {
227+ Computed : true ,
228+ Description : schemaDescriptions ["config_redirects_rule_status_code" ],
229+ },
230+ "rule_match_condition" : schema.StringAttribute {
231+ Computed : true ,
232+ Description : schemaDescriptions ["config_redirects_rule_match_condition" ],
233+ },
234+ "matchers" : schema.ListNestedAttribute {
235+ Description : schemaDescriptions ["config_redirects_rule_matchers" ],
236+ Computed : true ,
237+ NestedObject : schema.NestedAttributeObject {
238+ Attributes : map [string ]schema.Attribute {
239+ "values" : schema.ListAttribute {
240+ Description : schemaDescriptions ["config_redirects_rule_matcher_values" ],
241+ Computed : true ,
242+ ElementType : types .StringType ,
243+ },
244+ "value_match_condition" : schema.StringAttribute {
245+ Description : schemaDescriptions ["config_redirects_rule_match_condition" ],
246+ Computed : true ,
247+ },
248+ },
249+ },
250+ },
251+ },
252+ },
253+ },
254+ },
255+ },
202256 },
203257 },
204258 },
@@ -300,6 +354,99 @@ func mapDataSourceFields(ctx context.Context, distribution *cdn.Distribution, mo
300354 return core .DiagsToError (diags )
301355 }
302356
357+ // redirects
358+ redirectsVal := types .ObjectNull (redirectsTypes )
359+ if distribution .Config != nil && distribution .Config .Redirects != nil && distribution .Config .Redirects .Rules != nil {
360+ var tfRules []attr.Value
361+ for _ , r := range * distribution .Config .Redirects .Rules {
362+ var tfMatchers []attr.Value
363+ if r .Matchers != nil {
364+ for _ , m := range * r .Matchers {
365+ var tfValues []attr.Value
366+ if m .Values != nil {
367+ for _ , v := range * m .Values {
368+ tfValues = append (tfValues , types .StringValue (v ))
369+ }
370+ }
371+ tfValuesList , diags := types .ListValue (types .StringType , tfValues )
372+ if diags .HasError () {
373+ return core .DiagsToError (diags )
374+ }
375+
376+ tfValMatchCond := types .StringNull ()
377+ if m .ValueMatchCondition != nil {
378+ tfValMatchCond = types .StringValue (string (* m .ValueMatchCondition ))
379+ }
380+
381+ tfMatcherObj , diags := types .ObjectValue (matcherTypes , map [string ]attr.Value {
382+ "values" : tfValuesList ,
383+ "value_match_condition" : tfValMatchCond ,
384+ })
385+ if diags .HasError () {
386+ return core .DiagsToError (diags )
387+ }
388+ tfMatchers = append (tfMatchers , tfMatcherObj )
389+ }
390+ }
391+
392+ tfMatchersList , diags := types .ListValue (types.ObjectType {AttrTypes : matcherTypes }, tfMatchers )
393+ if diags .HasError () {
394+ return core .DiagsToError (diags )
395+ }
396+
397+ tfDesc := types .StringNull ()
398+ if r .Description != nil {
399+ tfDesc = types .StringValue (* r .Description )
400+ }
401+
402+ tfEnabled := types .BoolNull ()
403+ if r .Enabled != nil {
404+ tfEnabled = types .BoolValue (* r .Enabled )
405+ }
406+
407+ tfTargetUrl := types .StringNull ()
408+ if r .TargetUrl != nil {
409+ tfTargetUrl = types .StringValue (* r .TargetUrl )
410+ }
411+
412+ tfStatusCode := types .Int32Null ()
413+ if r .StatusCode != nil {
414+ tfStatusCode = types .Int32Value (int32 (* r .StatusCode ))
415+ }
416+
417+ tfRuleMatchCond := types .StringNull ()
418+ if r .RuleMatchCondition != nil {
419+ tfRuleMatchCond = types .StringValue (string (* r .RuleMatchCondition ))
420+ }
421+
422+ tfRuleObj , diags := types .ObjectValue (redirectRuleTypes , map [string ]attr.Value {
423+ "description" : tfDesc ,
424+ "enabled" : tfEnabled ,
425+ "target_url" : tfTargetUrl ,
426+ "status_code" : tfStatusCode ,
427+ "rule_match_condition" : tfRuleMatchCond ,
428+ "matchers" : tfMatchersList ,
429+ })
430+ if diags .HasError () {
431+ return core .DiagsToError (diags )
432+ }
433+ tfRules = append (tfRules , tfRuleObj )
434+ }
435+
436+ tfRulesList , diags := types .ListValue (types.ObjectType {AttrTypes : redirectRuleTypes }, tfRules )
437+ if diags .HasError () {
438+ return core .DiagsToError (diags )
439+ }
440+
441+ var objDiags diag.Diagnostics
442+ redirectsVal , objDiags = types .ObjectValue (redirectsTypes , map [string ]attr.Value {
443+ "rules" : tfRulesList ,
444+ })
445+ if objDiags .HasError () {
446+ return core .DiagsToError (objDiags )
447+ }
448+ }
449+
303450 // Prepare Backend Values
304451 var backendValues map [string ]attr.Value
305452 originRequestHeaders := types .MapNull (types .StringType )
@@ -383,6 +530,7 @@ func mapDataSourceFields(ctx context.Context, distribution *cdn.Distribution, mo
383530 "regions" : modelRegions ,
384531 "blocked_countries" : modelBlockedCountries ,
385532 "optimizer" : optimizerVal ,
533+ "redirects" : redirectsVal ,
386534 })
387535 if diags .HasError () {
388536 return core .DiagsToError (diags )
0 commit comments