From 6a09682bb5c12e9df913984a80d7145811b9d5ff Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Mon, 31 Jan 2022 12:10:55 +0000 Subject: [PATCH 1/2] schema: Introduce BuiltinReferences(modPath) --- internal/schema/refscope/scopes.go | 1 + schema/builtin_references.go | 53 ++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 schema/builtin_references.go diff --git a/internal/schema/refscope/scopes.go b/internal/schema/refscope/scopes.go index a73765ac..83b5d667 100644 --- a/internal/schema/refscope/scopes.go +++ b/internal/schema/refscope/scopes.go @@ -5,6 +5,7 @@ import ( ) var ( + BuiltinScope = lang.ScopeId("builtin") DataScope = lang.ScopeId("data") LocalScope = lang.ScopeId("local") ModuleScope = lang.ScopeId("module") diff --git a/schema/builtin_references.go b/schema/builtin_references.go new file mode 100644 index 00000000..eec7d57c --- /dev/null +++ b/schema/builtin_references.go @@ -0,0 +1,53 @@ +package schema + +import ( + "github.com/hashicorp/hcl-lang/lang" + "github.com/hashicorp/hcl-lang/reference" + "github.com/hashicorp/terraform-schema/internal/schema/refscope" + "github.com/zclconf/go-cty/cty" +) + +func BuiltinReferences(modPath string) reference.Targets { + return reference.Targets{ + { + Addr: lang.Address{ + lang.RootStep{Name: "path"}, + lang.AttrStep{Name: "module"}, + }, + ScopeId: refscope.BuiltinScope, + Type: cty.String, + Description: lang.Markdown("The filesystem path of the module where the expression is placed\n\n" + + modPath), + }, + { + Addr: lang.Address{ + lang.RootStep{Name: "path"}, + lang.AttrStep{Name: "root"}, + }, + ScopeId: refscope.BuiltinScope, + Type: cty.String, + Description: lang.Markdown("The filesystem path of the root module of the configuration"), + }, + { + Addr: lang.Address{ + lang.RootStep{Name: "path"}, + lang.AttrStep{Name: "cwd"}, + }, + ScopeId: refscope.BuiltinScope, + Type: cty.String, + Description: lang.Markdown("The filesystem path of the current working directory.\n\n" + + "In normal use of Terraform this is the same as `path.root`, " + + "but some advanced uses of Terraform run it from a directory " + + "other than the root module directory, causing these paths to be different."), + }, + { + Addr: lang.Address{ + lang.RootStep{Name: "terraform"}, + lang.AttrStep{Name: "workspace"}, + }, + ScopeId: refscope.BuiltinScope, + Type: cty.String, + Description: lang.Markdown("The name of the currently selected workspace"), + }, + } +} From 4e61187845b44c644a56689660ff9bc2fa85a7e5 Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Thu, 3 Feb 2022 09:28:00 +0000 Subject: [PATCH 2/2] add comment --- schema/builtin_references.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/schema/builtin_references.go b/schema/builtin_references.go index eec7d57c..6db7a572 100644 --- a/schema/builtin_references.go +++ b/schema/builtin_references.go @@ -7,6 +7,8 @@ import ( "github.com/zclconf/go-cty/cty" ) +// BuiltinReferences returns known "built-in" reference targets +// (range-less references available within any module) func BuiltinReferences(modPath string) reference.Targets { return reference.Targets{ {