Skip to content
This repository has been archived by the owner on Sep 3, 2024. It is now read-only.

Commit

Permalink
[RM-6416] Replace cty.NilVal with cty.NullVal (#279)
Browse files Browse the repository at this point in the history
  • Loading branch information
jason-fugue authored Dec 13, 2021
1 parent 8aa865e commit 04381be
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 5 deletions.
22 changes: 22 additions & 0 deletions pkg/loader/tf_test/ternary-mismatch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"content": {
"hcl_resource_view_version": "0.0.1",
"resources": {
"aws_s3_bucket.bar": {
"_filepath": "tf_test/ternary-mismatch/main.tf",
"_provider": "aws",
"_type": "aws_s3_bucket",
"bucket": null,
"id": "aws_s3_bucket.bar"
},
"aws_s3_bucket.foo": {
"_filepath": "tf_test/ternary-mismatch/main.tf",
"_provider": "aws",
"_type": "aws_s3_bucket",
"bucket": null,
"id": "aws_s3_bucket.foo"
}
}
},
"filepath": "tf_test/ternary-mismatch"
}
15 changes: 15 additions & 0 deletions pkg/loader/tf_test/ternary-mismatch/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
variable "foo" {
type = string
}

provider "aws" {
region = "us-east-1"
}

resource "aws_s3_bucket" "foo" {
bucket = var.foo ? {"foo": "bar"} : [1]
}

resource "aws_s3_bucket" "bar" {
bucket = var.foo ? {"foo": "bar"} : aws_s3_bucket.foo.bucket
}
2 changes: 1 addition & 1 deletion pkg/regulatf/moduletree.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func walkModule(v Visitor, moduleName ModuleName, module *configs.Module) {
name := EmptyFullName(moduleName)

for _, variable := range module.Variables {
if variable.Default != cty.NilVal {
if !variable.Default.IsNull() {
expr := hclsyntax.LiteralValueExpr{
Val: variable.Default,
SrcRange: variable.DeclRange,
Expand Down
2 changes: 1 addition & 1 deletion pkg/regulatf/regulatf.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ func (v *Evaluation) evaluate() error {
val, diags := expr.Value(&ctx)
if diags.HasErrors() {
logrus.Debugf("evaluate: error: %s", diags)
val = cty.NilVal
val = cty.NullVal(val.Type())
}

singleton := SingletonValTree(name.Local, val)
Expand Down
2 changes: 1 addition & 1 deletion pkg/regulatf/valtree.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func ValTreeToValue(tree ValTree) cty.Value {
if v, ok := t[i]; ok {
arr[i] = ValTreeToValue(v)
} else {
arr[i] = cty.NilVal
arr[i] = cty.NullVal(cty.DynamicPseudoType)
}
}
return cty.TupleVal(arr)
Expand Down
4 changes: 2 additions & 2 deletions pkg/regulatf/valtree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func TestValTree(t *testing.T) {
assert.Equal(t,
cty.ObjectVal(map[string]cty.Value{
"menu": cty.TupleVal([]cty.Value{
cty.NilVal,
cty.NullVal(cty.DynamicPseudoType),
cty.ObjectVal(map[string]cty.Value{
"name": cty.StringVal("pizza"),
"price": cty.NumberIntVal(10),
Expand Down Expand Up @@ -42,7 +42,7 @@ func TestValTree(t *testing.T) {
assert.Equal(t,
cty.ObjectVal(map[string]cty.Value{
"menu": cty.TupleVal([]cty.Value{
cty.NilVal,
cty.NullVal(cty.DynamicPseudoType),
cty.ObjectVal(map[string]cty.Value{
"price": cty.NumberIntVal(10),
}),
Expand Down

0 comments on commit 04381be

Please sign in to comment.