Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plantimestamp can be unknown during validation #35902

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions internal/lang/funcs/datetime.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ func MakeStaticTimestampFunc(static time.Time) function.Function {
Params: []function.Parameter{},
Type: function.StaticReturnType(cty.String),
Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) {
if static.IsZero() {
return cty.UnknownVal(cty.String), nil
}
return cty.StringVal(static.Format(time.RFC3339)), nil
},
})
Expand Down
20 changes: 20 additions & 0 deletions internal/lang/functions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1377,6 +1377,26 @@ func TestFunctions(t *testing.T) {
}
}

func TestPlanTimeStampUnknown(t *testing.T) {
// plantimestamp should return an unknown if there is no timestamp, which
// happens during validation
expr, parseDiags := hclsyntax.ParseExpression([]byte("plantimestamp()"), "test.hcl", hcl.Pos{Line: 1, Column: 1})
if parseDiags.HasErrors() {
t.Fatal(parseDiags)
}

scope := &Scope{}
got, diags := scope.EvalExpr(expr, cty.DynamicPseudoType)
if diags.HasErrors() {
t.Fatal(diags.Err())

}

if got.IsKnown() {
t.Fatalf("plantimestamp() should be unknown, got %#v\n", got)
}
}

const (
CipherBase64 = "eczGaDhXDbOFRZGhjx2etVzWbRqWDlmq0bvNt284JHVbwCgObiuyX9uV0LSAMY707IEgMkExJqXmsB4OWKxvB7epRB9G/3+F+pcrQpODlDuL9oDUAsa65zEpYF0Wbn7Oh7nrMQncyUPpyr9WUlALl0gRWytOA23S+y5joa4M34KFpawFgoqTu/2EEH4Xl1zo+0fy73fEto+nfkUY+meuyGZ1nUx/+DljP7ZqxHBFSlLODmtuTMdswUbHbXbWneW51D7Jm7xB8nSdiA2JQNK5+Sg5x8aNfgvFTt/m2w2+qpsyFa5Wjeu6fZmXSl840CA07aXbk9vN4I81WmJyblD/ZA=="
PrivateKey = `
Expand Down
Loading