From 2a457115a3530412e2a6d5816ac1f4c93cc95c3b Mon Sep 17 00:00:00 2001 From: Kristin Laemmert Date: Fri, 21 Jun 2019 14:30:17 -0400 Subject: [PATCH] configs: fix panic when the value is missing from version attribute in a provider block --- configs/test-fixtures/invalid-files/provider-syntax.tf | 3 +++ configs/version_constraint.go | 7 +++++++ 2 files changed, 10 insertions(+) create mode 100644 configs/test-fixtures/invalid-files/provider-syntax.tf diff --git a/configs/test-fixtures/invalid-files/provider-syntax.tf b/configs/test-fixtures/invalid-files/provider-syntax.tf new file mode 100644 index 000000000..7cf680fee --- /dev/null +++ b/configs/test-fixtures/invalid-files/provider-syntax.tf @@ -0,0 +1,3 @@ +provider "template" { + version = +} diff --git a/configs/version_constraint.go b/configs/version_constraint.go index 7aa19efc6..e40ce1639 100644 --- a/configs/version_constraint.go +++ b/configs/version_constraint.go @@ -45,6 +45,13 @@ func decodeVersionConstraint(attr *hcl.Attribute) (VersionConstraint, hcl.Diagno return ret, diags } + if !val.IsWhollyKnown() { + // If there is a syntax error, HCL sets the value of the given attribute + // to cty.DynamicVal. A diagnostic for the syntax error will already + // bubble up, so we will move forward gracefully here. + return ret, diags + } + constraintStr := val.AsString() constraints, err := version.NewConstraint(constraintStr) if err != nil {