@@ -77,6 +77,14 @@ func resourceObjectGroup() *schema.Resource {
7777 Optional : true ,
7878 ForceNew : false ,
7979 },
80+ "array_flatten_depth" : {
81+ Type : schema .TypeInt ,
82+ Default : 0 ,
83+ Description : "Array flattening level. 0 - disabled, -1 - unlimited, >1 - the respective flattening level" ,
84+ Optional : true ,
85+ ForceNew : true ,
86+ ValidateFunc : validation .IntAtLeast (- 1 ),
87+ },
8088 "column_renames" : {
8189 Type : schema .TypeMap ,
8290 Elem : & schema.Schema {
@@ -98,9 +106,24 @@ func resourceObjectGroup() *schema.Resource {
98106 }
99107}
100108
109+
110+
101111func resourceObjectGroupCreate (ctx context.Context , data * schema.ResourceData , meta interface {}) diag.Diagnostics {
102112 c := meta .(* ProviderMeta ).Client
103113
114+ // "unlimited" flattening represented as "null" in the api, and as -1 in the terraform module
115+ // because the terraform sdk doesn't support nil values in configs https://github.com/hashicorp/terraform-plugin-sdk/issues/261
116+ // We represent "null" as an int pointer to nil in the code.
117+ array_flatten_tf := data .Get ("array_flatten_depth" ).(int )
118+ var array_flatten_cs * int
119+ if (array_flatten_tf == - 1 ) {
120+ // -1 in terraform represents "null" in the ChaosSearch API call
121+ array_flatten_cs = nil
122+ } else {
123+ // any other value is passed as is
124+ array_flatten_cs = & array_flatten_tf
125+ }
126+
104127 createObjectGroupRequest := & client.CreateObjectGroupRequest {
105128 Name : data .Get ("name" ).(string ),
106129 SourceBucket : data .Get ("source_bucket" ).(string ),
@@ -111,6 +134,7 @@ func resourceObjectGroupCreate(ctx context.Context, data *schema.ResourceData, m
111134 PartitionBy : data .Get ("partition_by" ).(string ),
112135 Pattern : data .Get ("pattern" ).(string ),
113136 IndexRetention : data .Get ("index_retention" ).(int ),
137+ ArrayFlattenDepth : array_flatten_cs ,
114138 ColumnRenames : data .Get ("column_renames" ).(map [string ]interface {}),
115139 }
116140
@@ -156,6 +180,15 @@ func resourceObjectGroupRead(ctx context.Context, data *schema.ResourceData, met
156180 data .Set ("pattern" , resp .Pattern )
157181 data .Set ("source_bucket" , resp .SourceBucket )
158182
183+ // "unlimited" flattening represented as "null" in the api, and as -1 in the terraform module
184+ // because the terraform sdk doesn't support nil values in configs https://github.com/hashicorp/terraform-plugin-sdk/issues/261
185+ // We represent "null" as an int pointer to nil in the code.
186+ if (resp .ArrayFlattenDepth == nil ) {
187+ data .Set ("array_flatten_depth" , - 1 )
188+ } else {
189+ data .Set ("array_flatten_depth" , resp .ArrayFlattenDepth )
190+ }
191+
159192 return diags
160193}
161194
0 commit comments