-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(TF-18671) Enable references for variables in deployment inputs (Depl…
…oy) (#389) * feat: Do early decoding for deployments in deploy files * add OriginForTarget for stack variable references in deployment files
- Loading branch information
Showing
8 changed files
with
128 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package earlydecoder | ||
|
||
import ( | ||
"github.com/hashicorp/hcl/v2" | ||
"github.com/hashicorp/hcl/v2/gohcl" | ||
"github.com/hashicorp/terraform-schema/stack" | ||
"github.com/zclconf/go-cty/cty" | ||
) | ||
|
||
// loadDeployFromFile reads given file, interprets it and stores in given stack | ||
// This is useful for any caller which does tokenization/parsing on its own | ||
// e.g. because it will reuse these parsed files later for more detailed | ||
// interpretation. | ||
func loadDeployFromFile(file *hcl.File, ds *decodedStack) hcl.Diagnostics { | ||
var diags hcl.Diagnostics | ||
|
||
content, _, contentDiags := file.Body.PartialContent(deploymentRootSchema) | ||
diags = append(diags, contentDiags...) | ||
for _, block := range content.Blocks { | ||
switch block.Type { | ||
case "deployment": | ||
content, _, contentDiags := block.Body.PartialContent(deploymentSchema) | ||
diags = append(diags, contentDiags...) | ||
|
||
if len(block.Labels) != 1 || block.Labels[0] == "" { | ||
continue | ||
} | ||
|
||
name := block.Labels[0] | ||
|
||
inputs := make(map[string]cty.Value) | ||
if attr, defined := content.Attributes["inputs"]; defined { | ||
valDiags := gohcl.DecodeExpression(attr.Expr, nil, &inputs) | ||
diags = append(diags, valDiags...) | ||
} | ||
|
||
ds.Deployments[name] = &stack.Deployment{ | ||
Inputs: inputs, | ||
} | ||
} | ||
} | ||
|
||
return diags | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package stack | ||
|
||
import "github.com/zclconf/go-cty/cty" | ||
|
||
type Deployment struct { | ||
Inputs map[string]cty.Value | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters