@@ -24,7 +24,7 @@ func (c configureDashboardSerializedDashboard) Name() string {
24
24
return "ConfigureDashboardSerializedDashboard"
25
25
}
26
26
27
- func (c configureDashboardSerializedDashboard ) Apply (ctx context.Context , b * bundle.Bundle ) diag.Diagnostics {
27
+ func (c configureDashboardSerializedDashboard ) Apply (_ context.Context , b * bundle.Bundle ) diag.Diagnostics {
28
28
var diags diag.Diagnostics
29
29
30
30
pattern := dyn .NewPattern (
@@ -39,34 +39,35 @@ func (c configureDashboardSerializedDashboard) Apply(ctx context.Context, b *bun
39
39
// Include "serialized_dashboard" field if "file_path" is set.
40
40
// Note: the Terraform resource supports "file_path" natively, but we read the contents of the dashboard here
41
41
// to cover the use case of deployments from the workspace
42
- if path , ok := v .Get (filePathFieldName ).AsString (); ok {
42
+ path , ok := v .Get (filePathFieldName ).AsString ()
43
+ if ! ok {
44
+ return v , nil
45
+ }
43
46
44
- contents , err := b .SyncRoot .ReadFile (path )
45
- if err != nil {
46
- return dyn .InvalidValue , fmt .Errorf ("failed to read serialized dashboard from file_path %s: %w" , path , err )
47
- }
47
+ contents , err := b .SyncRoot .ReadFile (path )
48
+ if err != nil {
49
+ return dyn .InvalidValue , fmt .Errorf ("failed to read serialized dashboard from file_path %s: %w" , path , err )
50
+ }
48
51
49
- v , err : = dyn .Set (v , serializedDashboardFieldName , dyn .V (string (contents )))
50
- if err != nil {
51
- return dyn .InvalidValue , fmt .Errorf ("failed to set serialized_dashboard: %w" , err )
52
- }
52
+ v , err = dyn .Set (v , serializedDashboardFieldName , dyn .V (string (contents )))
53
+ if err != nil {
54
+ return dyn .InvalidValue , fmt .Errorf ("failed to set serialized_dashboard: %w" , err )
55
+ }
53
56
54
- // Drop the "file_path" field. It is mutually exclusive with "serialized_dashboard".
55
- return dyn .Walk (v , func (p dyn.Path , v dyn.Value ) (dyn.Value , error ) {
56
- switch len (p ) {
57
- case 0 :
58
- return v , nil
59
- case 1 :
60
- if p [0 ] == dyn .Key (filePathFieldName ) {
61
- return v , dyn .ErrDrop
62
- }
57
+ // Drop the "file_path" field. It is mutually exclusive with "serialized_dashboard".
58
+ return dyn .Walk (v , func (p dyn.Path , v dyn.Value ) (dyn.Value , error ) {
59
+ switch len (p ) {
60
+ case 0 :
61
+ return v , nil
62
+ case 1 :
63
+ if p [0 ] == dyn .Key (filePathFieldName ) {
64
+ return v , dyn .ErrDrop
63
65
}
66
+ }
64
67
65
- // Skip everything else.
66
- return v , dyn .ErrSkip
67
- })
68
- }
69
- return v , nil
68
+ // Skip everything else.
69
+ return v , dyn .ErrSkip
70
+ })
70
71
})
71
72
})
72
73
0 commit comments