/
server_show_plan.go
50 lines (42 loc) · 1.39 KB
/
server_show_plan.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package runner
import (
"context"
"encoding/json"
"fmt"
"sigs.k8s.io/controller-runtime"
)
func (r *TerraformRunnerServer) ShowPlanFileRaw(ctx context.Context, req *ShowPlanFileRawRequest) (*ShowPlanFileRawReply, error) {
log := controllerruntime.LoggerFrom(ctx, "instance-id", r.InstanceID).WithName(loggerName)
log.Info("show the raw plan file")
if req.TfInstance != r.InstanceID {
err := fmt.Errorf("no TF instance found")
log.Error(err, "no terraform")
return nil, err
}
rawOutput, err := r.tfShowPlanFileRaw(ctx, req.Filename)
if err != nil {
log.Error(err, "unable to get the raw plan output")
return nil, err
}
return &ShowPlanFileRawReply{RawOutput: rawOutput}, nil
}
func (r *TerraformRunnerServer) ShowPlanFile(ctx context.Context, req *ShowPlanFileRequest) (*ShowPlanFileReply, error) {
log := controllerruntime.LoggerFrom(ctx, "instance-id", r.InstanceID).WithName(loggerName)
log.Info("show the raw plan file")
if req.TfInstance != r.InstanceID {
err := fmt.Errorf("no TF instance found")
log.Error(err, "no terraform")
return nil, err
}
plan, err := r.tfShowPlanFile(ctx, req.Filename)
if err != nil {
log.Error(err, "unable to get the json plan output")
return nil, err
}
jsonBytes, err := json.Marshal(plan)
if err != nil {
log.Error(err, "unable to marshal the plan to json")
return nil, err
}
return &ShowPlanFileReply{JsonOutput: jsonBytes}, nil
}