@@ -249,33 +249,35 @@ func (d *DnsCommand) getLambdaDnsValueFromTfc(ctx context.Context, workspaceName
249
249
if d .failback {
250
250
outputName = "primary_region_domain_name"
251
251
}
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
253
258
}
254
259
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 ) {
256
261
workspaceID , client , err := d .findTfcWorkspace (ctx , workspaceName )
257
262
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 )
260
264
}
261
265
262
266
outputs , err := client .StateVersionOutputs .ReadCurrent (ctx , workspaceID )
263
267
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 )
266
269
}
267
270
268
271
for _ , item := range outputs .Items {
269
272
if item .Name == outputName {
270
273
if itemValue , ok := item .Value .(string ); ok {
271
- return itemValue
274
+ return itemValue , nil
272
275
}
273
276
break
274
277
}
275
278
}
276
279
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 )
279
281
}
280
282
281
283
// findTfcWorkspace looks for a workspace by name in two different Terraform Cloud accounts and returns
0 commit comments