Skip to content

Commit 9c5b798

Browse files
committed
Remove diags
1 parent af91585 commit 9c5b798

1 file changed

Lines changed: 19 additions & 18 deletions

File tree

bundle/statemgmt/upload_state_for_yaml_sync.go

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

5555
_, snapshotPath := b.StateFilenameConfigSnapshot(ctx)
5656

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

65-
err := uploadState(ctx, b)
66+
err = uploadState(ctx, b)
6667
if err != nil {
67-
return diag.Warningf("Failed to upload config snapshot to workspace: %v", err)
68+
log.Warnf(ctx, "Failed to upload config snapshot: %v", err)
69+
return nil
6870
}
6971

7072
log.Infof(ctx, "Config snapshot created at %s", snapshotPath)
71-
return diags
73+
return nil
7274
}
7375

7476
func uploadState(ctx context.Context, b *bundle.Bundle) error {
@@ -95,10 +97,10 @@ func uploadState(ctx context.Context, b *bundle.Bundle) error {
9597
return nil
9698
}
9799

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

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

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

137139
migratedDB := dstate.NewDatabase(tfState.Lineage, tfState.Serial+1)
@@ -144,33 +146,32 @@ func (m *uploadStateForYamlSync) convertState(ctx context.Context, b *bundle.Bun
144146
},
145147
}
146148

147-
// Get the dynamic value from b.Config and reverse the interpolation
149+
// Get the dynamic value from b.Config and reverse the interpolation.
148150
// b.Config has been modified by terraform.Interpolate which converts bundle-style
149-
// references (${resources.pipelines.x.id}) to terraform-style (${databricks_pipeline.x.id})
151+
// references (${resources.pipelines.x.id}) to terraform-style (${databricks_pipeline.x.id}).
150152
interpolatedRoot := b.Config.Value()
151153
uninterpolatedRoot, err := reverseInterpolate(interpolatedRoot)
152154
if err != nil {
153-
return false, diag.FromErr(fmt.Errorf("failed to reverse interpolation: %w", err))
155+
return false, fmt.Errorf("failed to reverse interpolation: %w", err)
154156
}
155157

156158
var uninterpolatedConfig config.Root
157159
err = uninterpolatedConfig.Mutate(func(_ dyn.Value) (dyn.Value, error) {
158160
return uninterpolatedRoot, nil
159161
})
160162
if err != nil {
161-
return false, diag.FromErr(fmt.Errorf("failed to create uninterpolated config: %w", err))
163+
return false, fmt.Errorf("failed to create uninterpolated config: %w", err)
162164
}
163165

164166
plan, err := deploymentBundle.CalculatePlan(ctx, b.WorkspaceClient(), &uninterpolatedConfig, snapshotPath)
165167
if err != nil {
166-
return false, diag.FromErr(err)
168+
return false, err
167169
}
168170

169171
for _, entry := range plan.Plan {
170172
entry.Action = deployplan.Update
171173
}
172174

173-
var diags diag.Diagnostics
174175
for key := range plan.Plan {
175176
etag := etags[key]
176177
if etag == "" {
@@ -182,13 +183,13 @@ func (m *uploadStateForYamlSync) convertState(ctx context.Context, b *bundle.Bun
182183
}
183184
err := structaccess.Set(sv.Value, structpath.NewStringKey(nil, "etag"), etag)
184185
if err != nil {
185-
diags = diags.Extend(diag.Warningf("Failed to set etag on %q: %v", key, err))
186+
log.Warnf(ctx, "Failed to set etag on %q: %v", key, err)
186187
}
187188
}
188189

189190
deploymentBundle.Apply(ctx, b.WorkspaceClient(), plan, direct.MigrateMode(true))
190191

191-
return true, diags
192+
return true, nil
192193
}
193194

194195
// reverseInterpolate reverses the terraform.Interpolate transformation.

0 commit comments

Comments
 (0)