Skip to content

Commit

Permalink
patch - tco_policy - support iterations over fields (#161)
Browse files Browse the repository at this point in the history
* patch - tco_policy - support iterations over fields
  • Loading branch information
OrNovo authored Oct 18, 2023
1 parent a52bd60 commit 4d031c6
Show file tree
Hide file tree
Showing 5 changed files with 313 additions and 152 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (d *TCOPolicyDataSource) Schema(_ context.Context, _ datasource.SchemaReque
}

func (d *TCOPolicyDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var data TCOPolicyResourceModel
var data *TCOPolicyResourceModel
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
if resp.Diagnostics.HasError() {
return
Expand Down Expand Up @@ -84,8 +84,11 @@ func (d *TCOPolicyDataSource) Read(ctx context.Context, req datasource.ReadReque
}
log.Printf("[INFO] Received tco-policy: %#v", getPolicyResp)

data = flattenTCOPolicy(getPolicyResp.GetPolicy())

data, diags := flattenTCOPolicy(ctx, getPolicyResp.GetPolicy())
if diags.HasError() {
resp.Diagnostics = diags
return
}
// Save data into Terraform state
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
resp.Diagnostics.Append(resp.State.Set(ctx, data)...)
}
9 changes: 6 additions & 3 deletions coralogix/data_source_coralogix_tco_policy_traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (d *TCOPolicyTracesDataSource) Schema(_ context.Context, _ datasource.Schem
}

func (d *TCOPolicyTracesDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var data TCOPolicyTracesResourceModel
var data *TCOPolicyTracesResourceModel
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
if resp.Diagnostics.HasError() {
return
Expand Down Expand Up @@ -84,8 +84,11 @@ func (d *TCOPolicyTracesDataSource) Read(ctx context.Context, req datasource.Rea
}
log.Printf("[INFO] Received tco-policy: %#v", getPolicyResp)

data = flattenTCOPolicyTraces(ctx, getPolicyResp.GetPolicy())

data, diags := flattenTCOPolicyTraces(ctx, getPolicyResp.GetPolicy())
if diags.HasError() {
resp.Diagnostics = diags
return
}
// Save data into Terraform state
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
}
Loading

0 comments on commit 4d031c6

Please sign in to comment.