Skip to content

Commit

Permalink
Include context when variable default has nested problem
Browse files Browse the repository at this point in the history
  • Loading branch information
wata727 committed Jan 2, 2025
1 parent 1cc7802 commit d99b387
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions terraform/variable.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1

package terraform

import (
Expand All @@ -8,6 +11,7 @@ import (
"github.com/hashicorp/hcl/v2/gohcl"
"github.com/hashicorp/hcl/v2/hclsyntax"
"github.com/terraform-linters/tflint-plugin-sdk/hclext"
"github.com/terraform-linters/tflint/terraform/tfdiags"
"github.com/zclconf/go-cty/cty"
"github.com/zclconf/go-cty/cty/convert"
)
Expand Down Expand Up @@ -84,8 +88,11 @@ func decodeVariableBlock(block *hclext.Block) (*Variable, hcl.Diagnostics) {
diags = append(diags, &hcl.Diagnostic{
Severity: hcl.DiagError,
Summary: "Invalid default value for variable",
Detail: fmt.Sprintf("This default value is not compatible with the variable's type constraint: %s.", err),
Subject: attr.Expr.Range().Ptr(),
Detail: fmt.Sprintf(
"This default value is not compatible with the variable's type constraint: %s.",
tfdiags.FormatError(err),
),
Subject: attr.Expr.Range().Ptr(),
})
val = cty.DynamicVal
}
Expand Down

0 comments on commit d99b387

Please sign in to comment.