Skip to content

Commit 3b7b63d

Browse files
Fix alert threshold double_value with terraform engine (#4615)
## Summary - The TF schema codegen maps `cty.Number` to Go `int` by default. The alert `double_value` field was not in the `float64` allowlist, so fractional values like `1.3` were dropped during normalization, causing terraform to fail with `"evaluation.threshold is provided but doesn't contain any value"`. - Add alert `double_value` paths to the float64 allowlist and update the generated schema types from `int` to `float64`. ## Test plan - [x] Unit test `TestConvertAlertWithThresholdDoubleValue` verifies fractional `double_value` survives normalization - [x] Updated existing `acceptance/bundle/resources/alerts/basic` acceptance test to use fractional `double_value: 1.3` instead of integer `2` 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 299af6c commit 3b7b63d

File tree

5 files changed

+46
-5
lines changed

5 files changed

+46
-5
lines changed

acceptance/bundle/resources/alerts/basic/databricks.yml.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ resources:
2121
name: "1"
2222
threshold:
2323
value:
24-
double_value: 2
24+
double_value: 1.3
2525
query_text: "select 2"
2626
schedule:
2727
pause_status: "UNPAUSED"

acceptance/bundle/resources/alerts/basic/output.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Deployment complete!
2323
},
2424
"threshold": {
2525
"value": {
26-
"double_value": 2
26+
"double_value": 1.3
2727
}
2828
}
2929
},

bundle/deploy/terraform/tfdyn/convert_alert_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,41 @@ func TestConvertAlert(t *testing.T) {
6868
},
6969
}, out.Permissions["alert_test_alert"])
7070
}
71+
72+
func TestConvertAlertWithThresholdDoubleValue(t *testing.T) {
73+
src := resources.Alert{
74+
AlertV2: sql.AlertV2{
75+
DisplayName: "test_alert",
76+
QueryText: "SELECT 1",
77+
WarehouseId: "test_warehouse_id",
78+
Evaluation: sql.AlertV2Evaluation{
79+
ComparisonOperator: "EQUAL",
80+
Source: sql.AlertV2OperandColumn{
81+
Name: "1",
82+
},
83+
Threshold: &sql.AlertV2Operand{
84+
Value: &sql.AlertV2OperandValue{
85+
DoubleValue: 1.3,
86+
},
87+
},
88+
},
89+
},
90+
}
91+
92+
vin, err := convert.FromTyped(src, dyn.NilValue)
93+
require.NoError(t, err)
94+
95+
ctx := context.Background()
96+
out := schema.NewResources()
97+
err = alertConverter{}.Convert(ctx, "test_alert", vin, out)
98+
require.NoError(t, err)
99+
100+
alert := out.AlertV2["test_alert"]
101+
alertMap := alert.(map[string]any)
102+
evaluation := alertMap["evaluation"].(map[string]any)
103+
threshold := evaluation["threshold"].(map[string]any)
104+
value := threshold["value"].(map[string]any)
105+
106+
// Assert the fractional double_value is preserved after normalization.
107+
assert.InDelta(t, 1.3, value["double_value"], 0.0001)
108+
}

bundle/internal/tf/codegen/generator/walker.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ type walker struct {
3333
// that should be mapped to float64 instead of int for cty.Number types.
3434
// Generated from Terraform provider schema based on databricks-sdk-go types.
3535
var floatAttributePaths = map[string]bool{
36+
// Alert thresholds - double_value fields hold fractional values (e.g., 1.3)
37+
"databricks_alert_v2.evaluation.threshold.value.double_value": true,
38+
3639
// Postgres Service - autoscaling compute units support fractional values (e.g., 0.5 CU)
3740
"databricks_postgres_endpoint.spec.autoscaling_limit_max_cu": true,
3841
"databricks_postgres_endpoint.spec.autoscaling_limit_min_cu": true,

bundle/internal/tf/schema/resource_alert_v2.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)