Skip to content

Commit

Permalink
Support locals in stack and deploy config
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jpogran committed Aug 21, 2024
1 parent 0518779 commit 4cb5d85
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
34 changes: 34 additions & 0 deletions internal/schema/stacks/1.9/locals_block.go
Original file line number Diff line number Diff line change
@@ -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},
},
},
}
}
2 changes: 2 additions & 0 deletions internal/schema/stacks/1.9/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func StackSchema(_ *version.Version) *schema.BodySchema {
"required_providers": requiredProvidersBlockSchema(),
"variable": variableBlockSchema(),
"output": outputBlockSchema(),
"locals": localsBlockSchema(),
},
}
}
Expand All @@ -31,6 +32,7 @@ func DeploymentSchema(_ *version.Version) *schema.BodySchema {
"identity_token": identityTokenBlockSchema(),
"orchestrate": orchestrateBlockSchema(),
"store": storeBlockSchema(),
"locals": localsBlockSchema(),
},
}
}

0 comments on commit 4cb5d85

Please sign in to comment.