Skip to content

Commit 810f497

Browse files
authored
fix(cloud): cloud backend rendering query warning diags (#38040)
1 parent 0b9a20c commit 810f497

File tree

6 files changed

+62
-0
lines changed

6 files changed

+62
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
kind: BUG FIXES
2+
body: Fixes an issue where any warning diagnostics generated during terraform query execution failed to render in the cloud backend session
3+
time: 2026-01-08T11:45:27.489784-08:00
4+
custom:
5+
Issue: "38040"

internal/cloud/backend_query.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,11 @@ func (b *Cloud) renderQueryRunLogs(ctx context.Context, op *backendrun.Operation
169169
if result.Len() > 0 {
170170
b.renderer.Streams.Println(result.String())
171171
}
172+
default:
173+
err := b.renderer.RenderLog(log)
174+
if err != nil {
175+
return err
176+
}
172177
}
173178
}
174179
}

internal/cloud/backend_query_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,42 @@ list.concept_pet.pets id=legal-lamprey,legs=2 This is a legal-lamprey
139139
t.Fatalf("unexpected error locking state after successful plan: %s", err.Error())
140140
}
141141
}
142+
143+
func TestCloud_queryJSONWithDiags(t *testing.T) {
144+
b, bCleanup := testBackendWithName(t)
145+
defer bCleanup()
146+
147+
stream, close := terminal.StreamsForTesting(t)
148+
149+
b.renderer = &jsonformat.Renderer{
150+
Streams: stream,
151+
Colorize: mockColorize(),
152+
}
153+
154+
op, configCleanup, done := testOperationQuery(t, "./testdata/query-json-diag")
155+
defer configCleanup()
156+
defer done(t)
157+
158+
op.Workspace = testBackendSingleWorkspaceName
159+
160+
mockSROWorkspace(t, b, op.Workspace)
161+
162+
run, err := b.Operation(context.Background(), op)
163+
if err != nil {
164+
t.Fatalf("error starting operation: %v", err)
165+
}
166+
167+
<-run.Done()
168+
if run.Result != backendrun.OperationSuccess {
169+
t.Fatalf("operation failed: %s", b.CLI.(*cli.MockUi).ErrorWriter.String())
170+
}
171+
172+
testOut := close(t)
173+
output := testOut.Stdout()
174+
175+
// Warning diagnostic message
176+
testString := "Warning: Something went wrong"
177+
if !strings.Contains(output, testString) {
178+
t.Fatalf("Expected %q to contain %q but it did not", output, testString)
179+
}
180+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
resource "null_resource" "foo" {}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
list "concept_pet" "pets" {
2+
provider = concept
3+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{"@level":"info","@message":"Terraform 1.14.0-dev","@module":"terraform.ui","@timestamp":"2025-08-29T14:07:26.859531+02:00","terraform":"1.14.0-dev","type":"version","ui":"1.2"}
2+
{"@level":"info","@message":"list.concept_pet.pets: Starting query...","@module":"terraform.ui","@timestamp":"2025-08-29T14:07:26.954999+02:00","list_start":{"address":"list.concept_pet.pets","resource_type":"concept_pet"},"type":"list_start"}
3+
{"@level":"info","@message":"list.concept_pet.pets: Result found","@module":"terraform.ui","@timestamp":"2025-08-29T14:07:26.955489+02:00","list_resource_found":{"address":"list.concept_pet.pets","display_name":"This is a large-roughy","identity":{"id":"large-roughy","legs":2},"resource_type":"concept_pet"},"type":"list_resource_found"}
4+
{"@level":"info","@message":"list.concept_pet.pets: Result found","@module":"terraform.ui","@timestamp":"2025-08-29T14:07:26.955516+02:00","list_resource_found":{"address":"list.concept_pet.pets","display_name":"This is a able-werewolf","identity":{"id":"able-werewolf","legs":5},"resource_type":"concept_pet"},"type":"list_resource_found"}
5+
{"@level":"info","@message":"list.concept_pet.pets: Result found","@module":"terraform.ui","@timestamp":"2025-08-29T14:07:26.955523+02:00","list_resource_found":{"address":"list.concept_pet.pets","display_name":"This is a complete-gannet","identity":{"id":"complete-gannet","legs":6},"resource_type":"concept_pet"},"type":"list_resource_found"}
6+
{"@level":"info","@message":"list.concept_pet.pets: Result found","@module":"terraform.ui","@timestamp":"2025-08-29T14:07:26.955529+02:00","list_resource_found":{"address":"list.concept_pet.pets","display_name":"This is a charming-beagle","identity":{"id":"charming-beagle","legs":3},"resource_type":"concept_pet"},"type":"list_resource_found"}
7+
{"@level":"info","@message":"list.concept_pet.pets: Result found","@module":"terraform.ui","@timestamp":"2025-08-29T14:07:26.955535+02:00","list_resource_found":{"address":"list.concept_pet.pets","display_name":"This is a legal-lamprey","identity":{"id":"legal-lamprey","legs":2},"resource_type":"concept_pet"},"type":"list_resource_found"}
8+
{"@level":"info","@message":"list.concept_pet.pets: List complete","@module":"terraform.ui","@timestamp":"2025-08-29T14:07:26.955538+02:00","list_complete":{"address":"list.concept_pet.pets","resource_type":"concept_pet","total":5},"type":"list_complete"}
9+
{"@level":"warn","@message":"Warning: Something went wrong","@module":"terraform.ui","@timestamp":"2025-08-29T14:07:26.955540+02:00","diagnostic":{"severity":"warning","summary":"Warning: Something went wrong","detail":"detail"},"type":"diagnostic"}

0 commit comments

Comments
 (0)