Skip to content

Commit dd1a76b

Browse files
committed
Print the "Will use config value" message for all three error conditions
1 parent aaf5941 commit dd1a76b

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

cmd/cli/multiregion/dns.go

+11-9
Original file line numberDiff line numberDiff line change
@@ -249,33 +249,35 @@ func (d *DnsCommand) getLambdaDnsValueFromTfc(ctx context.Context, workspaceName
249249
if d.failback {
250250
outputName = "primary_region_domain_name"
251251
}
252-
return d.getTfcOutputFromWorkspace(ctx, workspaceName, outputName)
252+
val, err := d.getTfcOutputFromWorkspace(ctx, workspaceName, outputName)
253+
if err != nil {
254+
fmt.Printf("Error: %s\n Will use config value if provided.\n", err)
255+
return ""
256+
}
257+
return val
253258
}
254259

255-
func (d *DnsCommand) getTfcOutputFromWorkspace(ctx context.Context, workspaceName, outputName string) string {
260+
func (d *DnsCommand) getTfcOutputFromWorkspace(ctx context.Context, workspaceName, outputName string) (string, error) {
256261
workspaceID, client, err := d.findTfcWorkspace(ctx, workspaceName)
257262
if err != nil {
258-
fmt.Printf("Failed to get DNS value from %s: %s\n Will use config value if provided.\n", workspaceName, err)
259-
return ""
263+
return "", fmt.Errorf("failed to get DNS value from %s: %w", workspaceName, err)
260264
}
261265

262266
outputs, err := client.StateVersionOutputs.ReadCurrent(ctx, workspaceID)
263267
if err != nil {
264-
fmt.Printf("Error reading Terraform state outputs on workspace %s: %s", workspaceName, err)
265-
return ""
268+
return "", fmt.Errorf("error reading Terraform state outputs on workspace %s: %w", workspaceName, err)
266269
}
267270

268271
for _, item := range outputs.Items {
269272
if item.Name == outputName {
270273
if itemValue, ok := item.Value.(string); ok {
271-
return itemValue
274+
return itemValue, nil
272275
}
273276
break
274277
}
275278
}
276279

277-
fmt.Printf("Value for %s not found in %s\n", outputName, workspaceName)
278-
return ""
280+
return "", fmt.Errorf("value for %s not found in %s\n", outputName, workspaceName)
279281
}
280282

281283
// findTfcWorkspace looks for a workspace by name in two different Terraform Cloud accounts and returns

0 commit comments

Comments
 (0)