From db43867df7beb48c3fbedce0a17c52d2be614669 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Fri, 14 May 2021 16:58:02 -0700 Subject: [PATCH] addrs: Reserve "template" and similar prefixes for future expansion At the time of this commit we have a proposal #28700 which would, if accepted, need to reserve a new reference prefix to represent template arguments. It seems unlikely that the proposal would be accepted and implemented before Terraform v1.0 creates additional compatibility constraints, and so this pre-emptively reserves a few candidate symbol names to allow something like that proposal to potentially move forward later without requiring a new opt-in language edition. If we do move forward with the proposal then we'll select one of these three reserved names depending on which form of the proposal we decide to move forward with, and then un-reserve the other two. If we decide to not pursue this proposal at all then we'll un-reserve all three once that decision is finalized. It's unlikely that there is any existing provider which has a resource type named either "template", "lazy", or "arg", but in that unlikely event users of that provider can keep using it by adding the "resource." escaping prefix, such as changing "lazy.foo.bar" into "resource.lazy.foo.bar". --- addrs/parse_ref.go | 12 ++++++++++++ addrs/parse_ref_test.go | 19 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/addrs/parse_ref.go b/addrs/parse_ref.go index bad463ba8da4..62f244e1a629 100644 --- a/addrs/parse_ref.go +++ b/addrs/parse_ref.go @@ -239,6 +239,18 @@ func parseRef(traversal hcl.Traversal) (*Reference, tfdiags.Diagnostics) { Remaining: remain, }, diags + case "template", "lazy", "arg": + // These names are all pre-emptively reserved in the hope of landing + // some version of "template values" or "lazy expressions" feature + // before the next opt-in language edition, but don't yet do anything. + diags = diags.Append(&hcl.Diagnostic{ + Severity: hcl.DiagError, + Summary: "Reserved symbol name", + Detail: fmt.Sprintf("The symbol name %q is reserved for use in a future Terraform version. If you are using a provider that already uses this as a resource type name, add the prefix \"resource.\" to force interpretation as a resource type name.", root), + Subject: rootRange.Ptr(), + }) + return nil, diags + default: return parseResourceRef(ManagedResourceMode, rootRange, traversal) } diff --git a/addrs/parse_ref_test.go b/addrs/parse_ref_test.go index 660725e534fc..f7f1949ae5d4 100644 --- a/addrs/parse_ref_test.go +++ b/addrs/parse_ref_test.go @@ -605,6 +605,25 @@ func TestParseRef(t *testing.T) { ``, }, + // We have some names reserved which might be used by a + // still-under-discussion proposal for template values or lazy + // expressions. + { + `template.foo`, + nil, + `The symbol name "template" is reserved for use in a future Terraform version. If you are using a provider that already uses this as a resource type name, add the prefix "resource." to force interpretation as a resource type name.`, + }, + { + `lazy.foo`, + nil, + `The symbol name "lazy" is reserved for use in a future Terraform version. If you are using a provider that already uses this as a resource type name, add the prefix "resource." to force interpretation as a resource type name.`, + }, + { + `arg.foo`, + nil, + `The symbol name "arg" is reserved for use in a future Terraform version. If you are using a provider that already uses this as a resource type name, add the prefix "resource." to force interpretation as a resource type name.`, + }, + // anything else, interpreted as a managed resource reference { `boop_instance.foo`,