Unable to pass param values to function

Hello, for below code

import "tfplan/v2" as tfplan
import "strings"

param allowed_list default [ "abc", "xyz", ]

test_function(allowed_list) {
    print(allowed_list)
}

main = rule {
    test_function(allowed_list),
}

For the above code, i get error as below -

Error parsing policy: test_param1.sentinel:10:1: expected statement, found ‘param’

However, for the below code I get no error -

import "tfplan/v2" as tfplan
import "strings"

param allowed_list default [ "abc", "xyz" ]

main = rule {
    allowed_list
}

What is the reason ?

Hi @ashwinkupatkar,

I think it is a syntax issue at various lines in the policy. Here is a working example: Sentinel Playground

  1. The function was not assigned correctly and did not terminate with a return. As an example: add1 = func(x) { return x + 1 }
  2. The expression in the main rule ended with , which was also causing issues.

Hope this helps.

Ryan

sorry that was a bad code snippet i posted… thanks for the comment…

the actual code was the same that you posted … but for some reason a similar code from the actual environment throws error as below -

Error parsing policy: test_param.sentinel:21:1: expected statement, found ‘param’ (and 5 more errors)

I could figure out the issue
The issue was in sentinel code

there was a variable that was assigned some value and “param” variable was below that , causing weird issue.

Placing param variable at the top fixed the issue.

Sample code for problem and fix :

Problem:

import "tfplan/v2" as tfplan
import "strings"

variable_a = filter tfplan.resource_changes ..... {}

param allowed_list default [ "abc", "xyz", ]

test_function = func (allowed_list) {
      print(allowed_list)    
}
main = rule {
      test_function(allowed_list)
}

Fix:

import "tfplan/v2" as tfplan
import "strings"

param allowed_list default [ "abc", "xyz", ]

variable_a = filter tfplan.resource_changes ..... {}

test_function = func (allowed_list) {
      print(allowed_list)    
}
main = rule {
      test_function(allowed_list)
}

Its strange that this is not mentioned in any document

It’s mentioned in the spec documentation for parameters.

I’ll raise a PR to add notes to the language docs. Thanks for raising this :pray:

1 Like

Yeah… I was looking into the langauge docs. Thanks for acknowledgement.