Skip to content

Commit 9b5dae8

Browse files
committed
Remove diags
1 parent afe7735 commit 9b5dae8

1 file changed

Lines changed: 20 additions & 19 deletions

File tree

bundle/statemgmt/upload_state_for_yaml_sync.go

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,23 @@ func (m *uploadStateForYamlSync) Apply(ctx context.Context, b *bundle.Bundle) di
5656

5757
_, snapshotPath := b.StateFilenameConfigSnapshot(ctx)
5858

59-
created, diags := m.convertState(ctx, b, snapshotPath)
60-
if diags.HasError() {
61-
return diag.Warningf("Failed to create config snapshot: %v", diags.Error())
59+
created, err := m.convertState(ctx, b, snapshotPath)
60+
if err != nil {
61+
log.Warnf(ctx, "Failed to create config snapshot: %v", err)
62+
return nil
6263
}
6364
if !created {
6465
return nil
6566
}
6667

67-
err := uploadState(ctx, b)
68+
err = uploadState(ctx, b)
6869
if err != nil {
69-
return diag.Warningf("Failed to upload config snapshot to workspace: %v", err)
70+
log.Warnf(ctx, "Failed to upload config snapshot: %v", err)
71+
return nil
7072
}
7173

7274
log.Infof(ctx, "Config snapshot created at %s", snapshotPath)
73-
return diags
75+
return nil
7476
}
7577

7678
func uploadState(ctx context.Context, b *bundle.Bundle) error {
@@ -97,10 +99,10 @@ func uploadState(ctx context.Context, b *bundle.Bundle) error {
9799
return nil
98100
}
99101

100-
func (m *uploadStateForYamlSync) convertState(ctx context.Context, b *bundle.Bundle, snapshotPath string) (bool, diag.Diagnostics) {
102+
func (m *uploadStateForYamlSync) convertState(ctx context.Context, b *bundle.Bundle, snapshotPath string) (bool, error) {
101103
terraformResources, err := terraform.ParseResourcesState(ctx, b)
102104
if err != nil {
103-
return false, diag.FromErr(fmt.Errorf("failed to parse terraform state for config snapshot: %w", err))
105+
return false, fmt.Errorf("failed to parse terraform state: %w", err)
104106
}
105107

106108
// ParseResourcesState returns nil when the terraform state file doesn't exist
@@ -112,7 +114,7 @@ func (m *uploadStateForYamlSync) convertState(ctx context.Context, b *bundle.Bun
112114
_, localTerraformPath := b.StateFilenameTerraform(ctx)
113115
data, err := os.ReadFile(localTerraformPath)
114116
if err != nil {
115-
return false, diag.FromErr(fmt.Errorf("failed to read terraform state for config snapshot: %w", err))
117+
return false, fmt.Errorf("failed to read terraform state: %w", err)
116118
}
117119

118120
state := make(map[string]dstate.ResourceEntry)
@@ -133,7 +135,7 @@ func (m *uploadStateForYamlSync) convertState(ctx context.Context, b *bundle.Bun
133135
Serial int `json:"serial"`
134136
}
135137
if err := json.Unmarshal(data, &tfState); err != nil {
136-
return false, diag.FromErr(err)
138+
return false, err
137139
}
138140

139141
migratedDB := dstate.NewDatabase(tfState.Lineage, tfState.Serial+1)
@@ -151,36 +153,35 @@ func (m *uploadStateForYamlSync) convertState(ctx context.Context, b *bundle.Bun
151153
// the migrated state and config agree on .permissions entries.
152154
bundle.ApplyContext(ctx, b, resourcemutator.SecretScopeFixups(engine.EngineDirect))
153155
if logdiag.HasError(ctx) {
154-
return diag.Errorf("failed to apply secret scope fixups")
156+
return false, fmt.Errorf("failed to apply secret scope fixups")
155157
}
156158

157-
// Get the dynamic value from b.Config and reverse the interpolation
159+
// Get the dynamic value from b.Config and reverse the interpolation.
158160
// b.Config has been modified by terraform.Interpolate which converts bundle-style
159-
// references (${resources.pipelines.x.id}) to terraform-style (${databricks_pipeline.x.id})
161+
// references (${resources.pipelines.x.id}) to terraform-style (${databricks_pipeline.x.id}).
160162
interpolatedRoot := b.Config.Value()
161163
uninterpolatedRoot, err := reverseInterpolate(interpolatedRoot)
162164
if err != nil {
163-
return false, diag.FromErr(fmt.Errorf("failed to reverse interpolation: %w", err))
165+
return false, fmt.Errorf("failed to reverse interpolation: %w", err)
164166
}
165167

166168
var uninterpolatedConfig config.Root
167169
err = uninterpolatedConfig.Mutate(func(_ dyn.Value) (dyn.Value, error) {
168170
return uninterpolatedRoot, nil
169171
})
170172
if err != nil {
171-
return false, diag.FromErr(fmt.Errorf("failed to create uninterpolated config: %w", err))
173+
return false, fmt.Errorf("failed to create uninterpolated config: %w", err)
172174
}
173175

174176
plan, err := deploymentBundle.CalculatePlan(ctx, b.WorkspaceClient(), &uninterpolatedConfig, snapshotPath)
175177
if err != nil {
176-
return false, diag.FromErr(err)
178+
return false, err
177179
}
178180

179181
for _, entry := range plan.Plan {
180182
entry.Action = deployplan.Update
181183
}
182184

183-
var diags diag.Diagnostics
184185
for key := range plan.Plan {
185186
etag := etags[key]
186187
if etag == "" {
@@ -192,13 +193,13 @@ func (m *uploadStateForYamlSync) convertState(ctx context.Context, b *bundle.Bun
192193
}
193194
err := structaccess.Set(sv.Value, structpath.NewStringKey(nil, "etag"), etag)
194195
if err != nil {
195-
diags = diags.Extend(diag.Warningf("Failed to set etag on %q: %v", key, err))
196+
log.Warnf(ctx, "Failed to set etag on %q: %v", key, err)
196197
}
197198
}
198199

199200
deploymentBundle.Apply(ctx, b.WorkspaceClient(), plan, direct.MigrateMode(true))
200201

201-
return true, diags
202+
return true, nil
202203
}
203204

204205
// reverseInterpolate reverses the terraform.Interpolate transformation.

0 commit comments

Comments
 (0)