Skip to content

Commit

Permalink
Add environment variable for disabling YAML type checking (#634)
Browse files Browse the repository at this point in the history
This adds an option to the YAML runtime to disable the type checking.
This is controlled by the `PULUMI_YAML_DISABLE_TYPE_CHECKING`
environment variable.

This is useful for tests where we need to test type mismatches which
could happen in other languages, like Python or Typescript.

Can use some guidance on how to add tests here.

Required for
pulumi/pulumi-terraform-bridge#2418
  • Loading branch information
VenelinMartinov authored Sep 19, 2024
1 parent 51830eb commit e8720a7
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pkg/pulumiyaml/analyser.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ package pulumiyaml

import (
"fmt"
"os"
"reflect"
"strconv"
"strings"

"github.com/hashicorp/hcl/v2"
"github.com/pulumi/pulumi/pkg/v3/codegen"
"github.com/pulumi/pulumi/pkg/v3/codegen/schema"
"github.com/pulumi/pulumi/sdk/v3/go/common/util/cmdutil"

"github.com/pulumi/pulumi-yaml/pkg/pulumiyaml/ast"
ctypes "github.com/pulumi/pulumi-yaml/pkg/pulumiyaml/config"
Expand Down Expand Up @@ -532,9 +534,20 @@ func hasValidEnumValue(from ast.Expr, to []*schema.Enum) *notAssignable {
}
}

var disableTypeChecking = cmdutil.IsTruthy(os.Getenv("PULUMI_DEBUG_YAML_DISABLE_TYPE_CHECKING"))

// Provides an appropriate diagnostic message if it is illegal to assign `from`
// to `to`.
func (tc *typeCache) assertTypeAssignable(ctx *evalContext, from ast.Expr, to schema.Type) {
if disableTypeChecking {
ctx.addWarnDiag(
from.Syntax().Syntax().Range(),
"Running with type checking disabled. This is not recommended for production use.",
"This is a test feature and should not be used in production. Unexpected behavior may occur.",
)
return
}

if to == nil {
return
}
Expand Down

0 comments on commit e8720a7

Please sign in to comment.