From 8c7d60d4535fe2c2ce9dd4f848b5ce72a339867d Mon Sep 17 00:00:00 2001 From: James Pogran Date: Thu, 22 Aug 2024 03:52:40 -0400 Subject: [PATCH] Support locals in stack and deploy config (#395) This change adds support for locals in stack and deployment configuration. This also adds minimal reference support for locals, allowing go to definition and find references to work for locals. --- internal/schema/stacks/1.9/locals_block.go | 34 ++++++++++++++++++++++ internal/schema/stacks/1.9/root.go | 2 ++ 2 files changed, 36 insertions(+) create mode 100644 internal/schema/stacks/1.9/locals_block.go diff --git a/internal/schema/stacks/1.9/locals_block.go b/internal/schema/stacks/1.9/locals_block.go new file mode 100644 index 00000000..eed2ee1e --- /dev/null +++ b/internal/schema/stacks/1.9/locals_block.go @@ -0,0 +1,34 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package schema + +import ( + "github.com/hashicorp/hcl-lang/lang" + "github.com/hashicorp/hcl-lang/schema" + "github.com/hashicorp/terraform-schema/internal/schema/refscope" + "github.com/hashicorp/terraform-schema/internal/schema/tokmod" + "github.com/zclconf/go-cty/cty" +) + +func localsBlockSchema() *schema.BlockSchema { + return &schema.BlockSchema{ + SemanticTokenModifiers: lang.SemanticTokenModifiers{tokmod.Locals}, + Description: lang.Markdown("Local values assigning names to expressions, so you can use these multiple times without repetition\n" + + "e.g. `service_name = \"forum\"`"), + Body: &schema.BodySchema{ + AnyAttribute: &schema.AttributeSchema{ + Address: &schema.AttributeAddrSchema{ + Steps: []schema.AddrStep{ + schema.StaticStep{Name: "local"}, + schema.AttrNameStep{}, + }, + ScopeId: refscope.LocalScope, + AsExprType: true, + AsReference: true, + }, + Constraint: schema.AnyExpression{OfType: cty.DynamicPseudoType}, + }, + }, + } +} diff --git a/internal/schema/stacks/1.9/root.go b/internal/schema/stacks/1.9/root.go index 3d723710..bb6fa085 100644 --- a/internal/schema/stacks/1.9/root.go +++ b/internal/schema/stacks/1.9/root.go @@ -18,6 +18,7 @@ func StackSchema(_ *version.Version) *schema.BodySchema { "required_providers": requiredProvidersBlockSchema(), "variable": variableBlockSchema(), "output": outputBlockSchema(), + "locals": localsBlockSchema(), }, } } @@ -31,6 +32,7 @@ func DeploymentSchema(_ *version.Version) *schema.BodySchema { "identity_token": identityTokenBlockSchema(), "orchestrate": orchestrateBlockSchema(), "store": storeBlockSchema(), + "locals": localsBlockSchema(), }, } }