Skip to content

Commit 9860333

Browse files
Merge pull request #10 from pavel-elkin-klarna/LX-1689
LX-1689 Add ArrayFlattening to Terraform ChaosSearch provider
2 parents e0ba2c0 + bca2c5e commit 9860333

File tree

7 files changed

+42
-2
lines changed

7 files changed

+42
-2
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,5 @@ override.tf.json
3535
# Ignore CLI configuration files
3636
.terraformrc
3737
terraform.rc
38-
terraform
38+
terraform
39+
*.log

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ HOSTNAME=registry.terraform.io
33
NAMESPACE=benzaita
44
NAME=chaossearch
55
BINARY=terraform-provider-${NAME}
6-
VERSION=0.6.2
6+
VERSION=0.7.0
77
OS_ARCH=$(shell go env GOOS)_$(shell go env GOARCH)
88

99
default: install

chaossearch/client/model.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type ReadObjectGroupResponse struct {
2626
PartitionBy string
2727
SourceBucket string
2828
IndexRetention int
29+
ArrayFlattenDepth *int
2930
ColumnRenames map[string]string
3031
}
3132

@@ -39,6 +40,7 @@ type CreateObjectGroupRequest struct {
3940
SourceBucket string
4041
Pattern string
4142
IndexRetention int
43+
ArrayFlattenDepth *int
4244
ColumnRenames map[string]interface{}
4345
}
4446

chaossearch/client/operation_create_object_group.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ func marshalCreateObjectGroupRequest(req *CreateObjectGroupRequest) ([]byte, err
3939
"_type": req.Format,
4040
"horizontal": true,
4141
"stripPrefix": true,
42+
"arrayFlattenDepth": req.ArrayFlattenDepth,
4243
},
4344
"indexRetention": req.IndexRetention,
4445
"options": map[string]interface{}{

chaossearch/client/operation_read_object_group.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,14 @@ func mapBucketTaggingToResponse(tagging *s3.GetBucketTaggingOutput, v *ReadObjec
112112
var filterObject struct {
113113
Type string `json:"_type"`
114114
Pattern string `json:"pattern"`
115+
ArrayFlattenDepth *int `json:"arrayFlattenDepth"`
115116
}
116117
if err := readJSONTagValue(tagging, "cs3.dataset-format", &filterObject); err != nil {
117118
return err
118119
}
119120
v.Format = filterObject.Type
120121
v.Pattern = filterObject.Pattern
122+
v.ArrayFlattenDepth = filterObject.ArrayFlattenDepth
121123

122124
if err := readStringTagValue(tagging, "cs3.predicate", &v.FilterJSON); err != nil {
123125
return err

chaossearch/resource_object_group.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
101111
func 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

examples/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ resource "chaossearch_object_group" "my-object-group" {
3232
format = "JSON"
3333

3434
partition_by = "<regex>"
35+
array_flatten_depth = -1
3536
}
3637

3738
resource "chaossearch_indexing_state" "my-object-group" {

0 commit comments

Comments
 (0)