From 9f545c28feacb6760542b8aaaa636dadbee53b32 Mon Sep 17 00:00:00 2001 From: Adrien Delorme Date: Mon, 15 Feb 2021 11:47:44 +0100 Subject: [PATCH] required_plugins: prevent using `plugin = "version"`, and show an example --- hcl2template/types.required_plugins.go | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/hcl2template/types.required_plugins.go b/hcl2template/types.required_plugins.go index 072966021..b39558e1d 100644 --- a/hcl2template/types.required_plugins.go +++ b/hcl2template/types.required_plugins.go @@ -96,18 +96,23 @@ func decodeRequiredPluginsBlock(block *hcl.Block) (*RequiredPlugins, hcl.Diagnos switch { case expr.Type().IsPrimitiveType(): - vc, reqDiags := decodeVersionConstraint(attr) - diags = append(diags, reqDiags...) - rp.Requirement = vc - rp.Type, err = addrs.ParsePluginSourceString(name) - if err != nil { - diags = diags.Append(&hcl.Diagnostic{ - Severity: hcl.DiagError, - Summary: "Invalid plugin type", - Detail: fmt.Sprintf(`Invalid plugin type %q: %s"`, name, err), - }) + c := "version" + if cs, _ := decodeVersionConstraint(attr); len(cs.Required) > 0 { + c = cs.Required.String() } + diags = diags.Append(&hcl.Diagnostic{ + Severity: hcl.DiagError, + Summary: "Invalid plugin requirement", + Detail: fmt.Sprintf(`'%s = "%s"' plugin requirement calls are not possible.`+ + ` You must define a whole block. For example:`+"\n"+ + `%[1]s = {`+"\n"+ + ` source = github.com/hashicorp/%[1]s`+"\n"+ + ` version = %[2]s`+"\n"+`}`, + name, c), + Subject: attr.Range.Ptr(), + }) + case expr.Type().IsObjectType(): if !expr.Type().HasAttribute("version") { diags = append(diags, &hcl.Diagnostic{