Skip to content

Commit 036b876

Browse files
authored
fix(provider): always write known api_version after apply (#2)
api_version is Optional+Computed. For every non-Azure provider (Vertex Gemini/Anthropic) it is unset in config, so its planned value is unknown. apply() only assigned it when the gateway echoed a non-empty value, leaving the attribute unknown after apply for Vertex providers and triggering "Provider returned invalid result object after apply ... still indicated an unknown value for ...api_version". This broke the 4 Vertex aigateway_provider resources on the innfactory26 rollout (and, by cascade, the dependent azure models received an empty provider_id). Resolve to types.StringNull() when the gateway returns no api_version; Azure still round-trips its echoed value. Adds unit tests covering both paths.
1 parent 6531a4f commit 036b876

2 files changed

Lines changed: 67 additions & 0 deletions

File tree

internal/provider/provider_resource.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,13 @@ func (r *providerResource) apply(m *providerResourceModel, a *providerAPI) {
251251
if a.ProjectID != "" {
252252
m.ProjectID = types.StringValue(a.ProjectID)
253253
}
254+
// api_version is Optional+Computed: when unset in config (every non-Azure
255+
// provider) its planned value is unknown, so we MUST write a known value
256+
// here or Terraform rejects the result ("unknown value ... after apply").
257+
// Azure sets it and the gateway echoes it; everyone else gets null.
254258
if a.APIVersion != "" {
255259
m.APIVersion = types.StringValue(a.APIVersion)
260+
} else {
261+
m.APIVersion = types.StringNull()
256262
}
257263
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package provider
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-framework/types"
7+
)
8+
9+
// api_version is Optional+Computed: when it is unset in config (every non-Azure
10+
// provider, e.g. Vertex) its planned value is UNKNOWN. apply() MUST resolve it
11+
// to a known value, otherwise Terraform rejects the result with
12+
// "Provider returned invalid result object after apply ... still indicated an
13+
// unknown value for ...api_version". This is the bug that broke the 4 Vertex
14+
// providers on the innfactory26 rollout.
15+
func TestProviderApplyResolvesUnknownAPIVersion(t *testing.T) {
16+
r := &providerResource{}
17+
m := &providerResourceModel{
18+
APIVersion: types.StringUnknown(), // Vertex: unset in config => unknown plan value
19+
Region: types.StringValue("eu"),
20+
ProjectID: types.StringValue("proj-123"),
21+
}
22+
// The gateway omits apiVersion for non-Azure providers, so the decoded
23+
// response carries the empty string.
24+
a := &providerAPI{
25+
ID: "provider_abc",
26+
Type: "gemini",
27+
Name: "Vertex AI Gemini",
28+
Endpoint: "https://aiplatform.eu.rep.googleapis.com",
29+
AuthType: "serviceAccount",
30+
Region: "eu",
31+
ProjectID: "proj-123",
32+
APIVersion: "",
33+
Enabled: true,
34+
}
35+
36+
r.apply(m, a)
37+
38+
if m.APIVersion.IsUnknown() {
39+
t.Fatal("api_version is Computed and must be KNOWN after apply, got unknown")
40+
}
41+
if !m.APIVersion.IsNull() {
42+
t.Errorf("api_version should be null when the gateway returns none, got %q", m.APIVersion.ValueString())
43+
}
44+
if m.ID.ValueString() != "provider_abc" {
45+
t.Errorf("id mismatch: got %q", m.ID.ValueString())
46+
}
47+
}
48+
49+
// Azure sets api_version in config; the gateway echoes it back. apply() must
50+
// preserve the value exactly (Optional+Computed round-trip).
51+
func TestProviderApplyPreservesAzureAPIVersion(t *testing.T) {
52+
r := &providerResource{}
53+
m := &providerResourceModel{APIVersion: types.StringValue("2024-10-21")}
54+
a := &providerAPI{ID: "provider_x", APIVersion: "2024-10-21", Enabled: true}
55+
56+
r.apply(m, a)
57+
58+
if m.APIVersion.ValueString() != "2024-10-21" {
59+
t.Errorf("azure api_version must round-trip, got %q", m.APIVersion.ValueString())
60+
}
61+
}

0 commit comments

Comments
 (0)