Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: hashicorp/terraform
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.0.0
Choose a base ref
...
head repository: hashicorp/terraform
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.0.1
Choose a head ref

Commits on Jun 2, 2021

  1. backport of commit 6692336

    alisdair committed Jun 2, 2021
    Copy the full SHA
    29fbaa6 View commit details
  2. backport of commit 3f0c6a2

    alisdair committed Jun 2, 2021
    Copy the full SHA
    e036c5a View commit details

Commits on Jun 8, 2021

  1. Copy the full SHA
    b21a980 View commit details
  2. Merge pull request #28897 from hashicorp/backport/alisdair/fix-remote…

    …-backend-multi-workspace-state-migration/seriously-bold-cub
    
    Backport of Fix remote backend multi workspace state migration into v1.0
    alisdair authored Jun 8, 2021
    Copy the full SHA
    ae2cad4 View commit details
  3. Update CHANGELOG.md

    alisdair authored Jun 8, 2021
    Copy the full SHA
    a0536c9 View commit details
  4. website: Fix formatting of v1 compatibility promises

    Seems like we lost a newline in some of the shuffling it took to get this
    into the live website, and so it's formatting oddly in the rendered
    website. This restores the intended formatting of this as the start of
    a bullet list, rather than as a continuation of the previous paragraph.
    apparentlymart committed Jun 8, 2021
    Copy the full SHA
    1b0e811 View commit details

Commits on Jun 9, 2021

  1. Copy the full SHA
    6e00aac View commit details
  2. Merge pull request #28907 from hashicorp/radditude/backport-refresh-e…

    …rror-message
    
    backport changes to refresh error message to v1.0
    radditude authored Jun 9, 2021
    Copy the full SHA
    8fcb116 View commit details
  3. backport of commit 838ca5c

    nfagerlund committed Jun 9, 2021
    Copy the full SHA
    1a9e38b View commit details
  4. backport of commit 09c33fa

    jbardin committed Jun 9, 2021
    Copy the full SHA
    74a472f View commit details

Commits on Jun 10, 2021

  1. Merge pull request #28923 from hashicorp/backport/jbardin/noop-depose…

    …d-change/needlessly-concrete-bluejay
    
    Backport of account for noop deposed instances in json plan into v1.0
    jbardin authored Jun 10, 2021
    Copy the full SHA
    ac563ef View commit details
  2. update CHANGELOG.md

    jbardin committed Jun 10, 2021
    Copy the full SHA
    71e3160 View commit details

Commits on Jun 11, 2021

  1. backport of commit b7f8ef4

    jbardin committed Jun 11, 2021
    Copy the full SHA
    181cb8b View commit details

Commits on Jun 14, 2021

  1. Merge pull request #28954 from hashicorp/backport/jbardin/objchange-u…

    …nknown-blocks/jointly-tough-lion
    
    Backport of handle unexpected changes to unknown block into v1.0
    jbardin authored Jun 14, 2021
    Copy the full SHA
    e500ef8 View commit details

Commits on Jun 18, 2021

  1. backport of commit 6a495c8

    jbardin committed Jun 18, 2021
    Copy the full SHA
    b8bdf47 View commit details
  2. Merge pull request #28981 from hashicorp/backport/jbardin/fixup-body-…

    …context/plainly-frank-treefrog
    
    Backport of blocktoattr fixup dropping MissingItemRange into v1.0
    jbardin authored Jun 18, 2021
    Copy the full SHA
    92d23ab View commit details
  3. update CHANGELOG.md

    jbardin committed Jun 18, 2021
    Copy the full SHA
    0a3968d View commit details
  4. jsonplan and jsonstate: include sensitive_values in state representat…

    …ions (#28889)
    
    * jsonplan and jsonstate: include sensitive_values in state representations
    
    A sensitive_values field has been added to the resource in state and planned values which is a map of all sensitive attributes with the values set to true.
    
    It wasn't entirely clear to me if the values in state would suffice, or if we also need to consult the schema - I believe that this is sufficient for state files written since v0.15, and if that's incorrect or insufficient, I'll add in the provider schema check as well.
    
    I also updated the documentation, and, since we've considered this before, bumped the FormatVersions for both jsonstate and jsonplan.
    mildwonkey authored and alisdair committed Jun 18, 2021
    Copy the full SHA
    80bd093 View commit details
  5. jsonconfig: properly unwind and enumerate references (#28884)

    The "references" included in the expression representation now properly unwrap for each traversal step, to match what was documented.
    mildwonkey authored and alisdair committed Jun 18, 2021
    Copy the full SHA
    95df102 View commit details
  6. json-output: Omit unchanged resource_drift entries

    Previously, if any resources were found to have drifted, the JSON plan
    output would include a drift entry for every resource in state. This
    commit aligns the JSON plan output with the CLI UI, and only includes
    those resources where the old value does not equal the new value---i.e.
    drift has been detected.
    
    Also fixes a bug where the "address" field was missing from the drift
    output, and adds some test coverage.
    alisdair committed Jun 18, 2021
    Copy the full SHA
    ef7a4e3 View commit details
  7. Merge pull request #28982 from hashicorp/backport/alisdair/jsonplan-d…

    …rift/unlikely-hopeful-falcon
    
    Backport of recent JSON output changes
    alisdair authored Jun 18, 2021
    Copy the full SHA
    d998ab3 View commit details
  8. Update CHANGELOG.md

    alisdair authored Jun 18, 2021
    Copy the full SHA
    32f6788 View commit details

Commits on Jun 21, 2021

  1. backport of commit ed0fc8a

    alisdair committed Jun 21, 2021
    Copy the full SHA
    51d8439 View commit details
  2. Merge pull request #28995 from hashicorp/backport/alisdair/cty-1.8.4/…

    …typically-vast-drum
    
    Backport of Upgrade cty to v1.8.4 into v1.0
    alisdair authored Jun 21, 2021
    Copy the full SHA
    71517fb View commit details
  3. Update CHANGELOG.md

    alisdair authored Jun 21, 2021
    Copy the full SHA
    7901939 View commit details

Commits on Jun 22, 2021

  1. website: Explicit examples of -var escaping in various shells

    The -var command line option comes with the disadvantage that a user must
    contend both with Terraform's own parser and with the parser in whichever
    shell they've decided to use, and different shells on different platforms
    have different rules.
    
    Previously we've largely just assumed that folks know the appropriate
    syntax for the shell they chose, but it seems that command lines involving
    spaces and other special characters arise rarely enough in other commands
    that Terraform is often the first time someone needs to learn the
    appropriate syntax for their shell.
    
    We can't possibly capture all of the details of all shells in our docs,
    because that's far outside of our own scope, but hopefully this new
    section will go some way to give some real examples that will help folks
    figure out how to write suitable escape sequences, if they choose to
    set complex variable values on the command line rather than in .tfvars
    as we recommend elsewhere on this page.
    apparentlymart committed Jun 22, 2021
    Copy the full SHA
    c1c3639 View commit details

Commits on Jun 24, 2021

  1. update CHANGELOG.md

    jbardin committed Jun 24, 2021
    1
    Copy the full SHA
    8c5fcf1 View commit details
  2. Release v1.0.1

    hc-github-team-tf-core committed Jun 24, 2021
    Copy the full SHA
    5d80eb5 View commit details
Showing with 1,273 additions and 460 deletions.
  1. +17 −0 CHANGELOG.md
  2. +1 −1 go.mod
  3. +2 −2 go.sum
  4. +4 −0 internal/backend/remote/backend.go
  5. +0 −6 internal/backend/remote/backend_plan.go
  6. +0 −4 internal/backend/remote/backend_plan_test.go
  7. +33 −29 internal/command/init.go
  8. +70 −12 internal/command/jsonconfig/expression.go
  9. +57 −11 internal/command/jsonconfig/expression_test.go
  10. +12 −87 internal/command/jsonplan/plan.go
  11. +0 −213 internal/command/jsonplan/plan_test.go
  12. +6 −0 internal/command/jsonplan/resource.go
  13. +42 −2 internal/command/jsonplan/values.go
  14. +51 −4 internal/command/jsonplan/values_test.go
  15. +97 −2 internal/command/jsonstate/state.go
  16. +235 −13 internal/command/jsonstate/state_test.go
  17. +9 −7 internal/command/meta_backend_migrate.go
  18. +21 −4 internal/command/show_test.go
  19. +11 −2 internal/command/testdata/show-json-sensitive/output.json
  20. +5 −3 internal/command/testdata/show-json-state/basic/output.json
  21. +1 −1 internal/command/testdata/show-json-state/empty/output.json
  22. +5 −3 internal/command/testdata/show-json-state/modules/output.json
  23. +4 −1 internal/command/testdata/show-json-state/sensitive-variables/output.json
  24. +8 −5 internal/command/testdata/show-json/basic-create/output.json
  25. +8 −5 internal/command/testdata/show-json/basic-delete/output.json
  26. +6 −4 internal/command/testdata/show-json/basic-update/output.json
  27. +13 −0 internal/command/testdata/show-json/drift/main.tf
  28. +174 −0 internal/command/testdata/show-json/drift/output.json
  29. +38 −0 internal/command/testdata/show-json/drift/terraform.tfstate
  30. +3 −2 internal/command/testdata/show-json/module-depends-on/output.json
  31. +12 −7 internal/command/testdata/show-json/modules/output.json
  32. +29 −5 internal/command/testdata/show-json/multi-resource-update/output.json
  33. +3 −2 internal/command/testdata/show-json/nested-modules/output.json
  34. +8 −5 internal/command/testdata/show-json/provider-version-no-config/output.json
  35. +8 −5 internal/command/testdata/show-json/provider-version/output.json
  36. +6 −4 internal/command/testdata/show-json/requires-replace/output.json
  37. +6 −2 internal/command/testdata/show-json/sensitive-values/output.json
  38. +2 −0 internal/lang/blocktoattr/fixup.go
  39. +48 −0 internal/lang/blocktoattr/fixup_test.go
  40. +14 −0 internal/plans/objchange/plan_valid.go
  41. +104 −0 internal/plans/objchange/plan_valid_test.go
  42. +1 −1 version/version.go
  43. +76 −1 website/docs/cli/commands/plan.html.md
  44. +9 −2 website/docs/internals/json-format.html.md
  45. +1 −0 website/docs/language/v1-compatibility-promises.html.md
  46. +13 −3 website/docs/language/values/variables.html.md
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
## 1.0.1 (June 24, 2021)

ENHANCEMENTS:

* json-output: The JSON plan output now indicates which state values are sensitive. ([#28889](https://github.com/hashicorp/terraform/issues/28889))
* cli: The darwin builds can now make use of the host DNS resolver, which will fix many network related issues on MacOS.

BUG FIXES:

* backend/remote: Fix faulty Terraform Cloud version check when migrating state to the remote backend with multiple local workspaces ([#28864](https://github.com/hashicorp/terraform/issues/28864))
* cli: Fix crash with deposed instances in json plan output ([#28922](https://github.com/hashicorp/terraform/issues/28922))
* core: Fix crash when provider modifies and unknown block during plan ([#28941](https://github.com/hashicorp/terraform/issues/28941))
* core: Diagnostic context was missing for some errors when validating blocks ([#28979](https://github.com/hashicorp/terraform/issues/28979))
* core: Fix crash when calling `setproduct` with unknown values ([#28984](https://github.com/hashicorp/terraform/issues/28984))
* json-output: Fix an issue where the JSON configuration representation was missing fully-unwrapped references. ([#8884](https://github.com/hashicorp/terraform/issues/8884))
* json-output: Fix JSON plan resource drift to remove unchanged resources. ([#28975](https://github.com/hashicorp/terraform/issues/28975))

## 1.0.0 (June 08, 2021)

Terraform v1.0 is an unusual release in that its primary focus is on stability, and it represents the culmination of several years of work in previous major releases to make sure that the Terraform language and internal architecture will be a suitable foundation for forthcoming additions that will remain backward compatible.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -114,7 +114,7 @@ require (
github.com/xanzy/ssh-agent v0.2.1
github.com/xiang90/probing v0.0.0-20160813154853-07dd2e8dfe18 // indirect
github.com/xlab/treeprint v0.0.0-20161029104018-1d6e34225557
github.com/zclconf/go-cty v1.8.3
github.com/zclconf/go-cty v1.8.4
github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b
github.com/zclconf/go-cty-yaml v1.0.2
go.uber.org/atomic v1.3.2 // indirect
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -612,8 +612,8 @@ github.com/zclconf/go-cty v1.0.0/go.mod h1:xnAOWiHeOqg2nWS62VtQ7pbOu17FtxJNW8RLE
github.com/zclconf/go-cty v1.1.0/go.mod h1:xnAOWiHeOqg2nWS62VtQ7pbOu17FtxJNW8RLEih+O3s=
github.com/zclconf/go-cty v1.2.0/go.mod h1:hOPWgoHbaTUnI5k4D2ld+GRpFJSCe6bCM7m1q/N4PQ8=
github.com/zclconf/go-cty v1.8.0/go.mod h1:vVKLxnk3puL4qRAv72AO+W99LUD4da90g3uUAzyuvAk=
github.com/zclconf/go-cty v1.8.3 h1:48gwZXrdSADU2UW9eZKHprxAI7APZGW9XmExpJpSjT0=
github.com/zclconf/go-cty v1.8.3/go.mod h1:vVKLxnk3puL4qRAv72AO+W99LUD4da90g3uUAzyuvAk=
github.com/zclconf/go-cty v1.8.4 h1:pwhhz5P+Fjxse7S7UriBrMu6AUJSZM5pKqGem1PjGAs=
github.com/zclconf/go-cty v1.8.4/go.mod h1:vVKLxnk3puL4qRAv72AO+W99LUD4da90g3uUAzyuvAk=
github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b h1:FosyBZYxY34Wul7O/MSKey3txpPYyCqVO5ZyceuQJEI=
github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b/go.mod h1:ZRKQfBXbGkpdV6QMzT3rU1kSTAnfu1dO8dPKjYprgj8=
github.com/zclconf/go-cty-yaml v1.0.2 h1:dNyg4QLTrv2IfJpm7Wtxi55ed5gLGOlPrZ6kMd51hY0=
4 changes: 4 additions & 0 deletions internal/backend/remote/backend.go
Original file line number Diff line number Diff line change
@@ -721,6 +721,10 @@ func (b *Remote) Operation(ctx context.Context, op *backend.Operation) (*backend
f = b.opPlan
case backend.OperationTypeApply:
f = b.opApply
case backend.OperationTypeRefresh:
return nil, fmt.Errorf(
"\n\nThe \"refresh\" operation is not supported when using the \"remote\" backend. " +
"Use \"terraform apply -refresh-only\" instead.")
default:
return nil, fmt.Errorf(
"\n\nThe \"remote\" backend does not support the %q operation.", op.Type)
6 changes: 0 additions & 6 deletions internal/backend/remote/backend_plan.go
Original file line number Diff line number Diff line change
@@ -273,14 +273,8 @@ in order to capture the filesystem context the remote workspace expects:
"Failed to upload configuration files", errors.New("operation timed out"))
}

queueMessage := "Queued manually using Terraform"
if op.Targets != nil {
queueMessage = "Queued manually via Terraform using -target"
}

runOptions := tfe.RunCreateOptions{
ConfigurationVersion: cv,
Message: tfe.String(queueMessage),
Refresh: tfe.Bool(op.PlanRefresh),
Workspace: w,
}
4 changes: 0 additions & 4 deletions internal/backend/remote/backend_plan_test.go
Original file line number Diff line number Diff line change
@@ -482,10 +482,6 @@ func TestRemote_planWithTarget(t *testing.T) {
if diff := cmp.Diff([]string{"null_resource.foo"}, run.TargetAddrs); diff != "" {
t.Errorf("wrong TargetAddrs in the created run\n%s", diff)
}

if !strings.Contains(run.Message, "using -target") {
t.Errorf("incorrect Message on the created run: %s", run.Message)
}
}
}

62 changes: 33 additions & 29 deletions internal/command/init.go
Original file line number Diff line number Diff line change
@@ -49,6 +49,7 @@ func (c *InitCommand) Run(args []string) int {
cmdFlags.BoolVar(&flagUpgrade, "upgrade", false, "")
cmdFlags.Var(&flagPluginPath, "plugin-dir", "plugin directory")
cmdFlags.StringVar(&flagLockfile, "lockfile", "", "Set a dependency lockfile mode")
cmdFlags.BoolVar(&c.Meta.ignoreRemoteVersion, "ignore-remote-version", false, "continue even if remote and local Terraform versions are incompatible")
cmdFlags.Usage = func() { c.Ui.Error(c.Help()) }
if err := cmdFlags.Parse(args); err != nil {
return 1
@@ -962,46 +963,49 @@ Usage: terraform [global options] init [options]
Options:
-backend=true Configure the backend for this configuration.
-backend=true Configure the backend for this configuration.
-backend-config=path This can be either a path to an HCL file with key/value
assignments (same format as terraform.tfvars) or a
'key=value' format. This is merged with what is in the
configuration file. This can be specified multiple
times. The backend type must be in the configuration
itself.
-backend-config=path This can be either a path to an HCL file with key/value
assignments (same format as terraform.tfvars) or a
'key=value' format. This is merged with what is in the
configuration file. This can be specified multiple
times. The backend type must be in the configuration
itself.
-force-copy Suppress prompts about copying state data. This is
equivalent to providing a "yes" to all confirmation
prompts.
-force-copy Suppress prompts about copying state data. This is
equivalent to providing a "yes" to all confirmation
prompts.
-from-module=SOURCE Copy the contents of the given module into the target
directory before initialization.
-from-module=SOURCE Copy the contents of the given module into the target
directory before initialization.
-get=true Download any modules for this configuration.
-get=true Download any modules for this configuration.
-input=true Ask for input if necessary. If false, will error if
input was required.
-input=true Ask for input if necessary. If false, will error if
input was required.
-no-color If specified, output won't contain any color.
-no-color If specified, output won't contain any color.
-plugin-dir Directory containing plugin binaries. This overrides all
default search paths for plugins, and prevents the
automatic installation of plugins. This flag can be used
multiple times.
-plugin-dir Directory containing plugin binaries. This overrides all
default search paths for plugins, and prevents the
automatic installation of plugins. This flag can be used
multiple times.
-reconfigure Reconfigure the backend, ignoring any saved
configuration.
-reconfigure Reconfigure the backend, ignoring any saved
configuration.
-migrate-state Reconfigure the backend, and attempt to migrate any
existing state.
-migrate-state Reconfigure the backend, and attempt to migrate any
existing state.
-upgrade=false If installing modules (-get) or plugins, ignore
previously-downloaded objects and install the
latest version allowed within configured constraints.
-upgrade=false If installing modules (-get) or plugins, ignore
previously-downloaded objects and install the
latest version allowed within configured constraints.
-lockfile=MODE Set a dependency lockfile mode.
Currently only "readonly" is valid.
-lockfile=MODE Set a dependency lockfile mode.
Currently only "readonly" is valid.
-ignore-remote-version A rare option used for the remote backend only. See
the remote backend documentation for more information.
`
return strings.TrimSpace(helpText)
82 changes: 70 additions & 12 deletions internal/command/jsonconfig/expression.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package jsonconfig

import (
"bytes"
"encoding/json"
"fmt"

"github.com/hashicorp/hcl/v2"
"github.com/hashicorp/hcl/v2/hcldec"
"github.com/hashicorp/terraform/internal/addrs"
"github.com/hashicorp/terraform/internal/configs/configschema"
"github.com/hashicorp/terraform/internal/lang"
"github.com/zclconf/go-cty/cty"
@@ -30,22 +33,49 @@ type expression struct {

func marshalExpression(ex hcl.Expression) expression {
var ret expression
if ex != nil {
val, _ := ex.Value(nil)
if val != cty.NilVal {
valJSON, _ := ctyjson.Marshal(val, val.Type())
ret.ConstantValue = valJSON
}
vars, _ := lang.ReferencesInExpr(ex)
if ex == nil {
return ret
}

val, _ := ex.Value(nil)
if val != cty.NilVal {
valJSON, _ := ctyjson.Marshal(val, val.Type())
ret.ConstantValue = valJSON
}

refs, _ := lang.ReferencesInExpr(ex)
if len(refs) > 0 {
var varString []string
if len(vars) > 0 {
for _, v := range vars {
varString = append(varString, v.Subject.String())
for _, ref := range refs {
// We work backwards here, starting with the full reference +
// reamining traversal, and then unwrapping the remaining traversals
// into parts until we end up at the smallest referencable address.
remains := ref.Remaining
for len(remains) > 0 {
varString = append(varString, fmt.Sprintf("%s%s", ref.Subject, traversalStr(remains)))
remains = remains[:(len(remains) - 1)]
}
varString = append(varString, ref.Subject.String())

switch ref.Subject.(type) {
case addrs.ModuleCallInstance:
if ref.Subject.(addrs.ModuleCallInstance).Key != addrs.NoKey {
// Include the module call, without the key
varString = append(varString, ref.Subject.(addrs.ModuleCallInstance).Call.String())
}
case addrs.ResourceInstance:
if ref.Subject.(addrs.ResourceInstance).Key != addrs.NoKey {
// Include the resource, without the key
varString = append(varString, ref.Subject.(addrs.ResourceInstance).Resource.String())
}
case addrs.AbsModuleCallOutput:
// Include the module name, without the output name
varString = append(varString, ref.Subject.(addrs.AbsModuleCallOutput).Call.String())
}
ret.References = varString
}
return ret
ret.References = varString
}

return ret
}

@@ -117,3 +147,31 @@ func marshalExpressions(body hcl.Body, schema *configschema.Block) expressions {

return ret
}

// traversalStr produces a representation of an HCL traversal that is compact,
// resembles HCL native syntax, and is suitable for display in the UI.
//
// This was copied (and simplified) from internal/command/views/json/diagnostic.go.
func traversalStr(traversal hcl.Traversal) string {
var buf bytes.Buffer
for _, step := range traversal {
switch tStep := step.(type) {
case hcl.TraverseRoot:
buf.WriteString(tStep.Name)
case hcl.TraverseAttr:
buf.WriteByte('.')
buf.WriteString(tStep.Name)
case hcl.TraverseIndex:
buf.WriteByte('[')
switch tStep.Key.Type() {
case cty.String:
buf.WriteString(fmt.Sprintf("%q", tStep.Key.AsString()))
case cty.Number:
bf := tStep.Key.AsBigFloat()
buf.WriteString(bf.Text('g', 10))
}
buf.WriteByte(']')
}
}
return buf.String()
}
68 changes: 57 additions & 11 deletions internal/command/jsonconfig/expression_test.go
Original file line number Diff line number Diff line change
@@ -9,14 +9,14 @@ import (

"github.com/hashicorp/hcl/v2"
"github.com/hashicorp/hcl/v2/hclsyntax"
"github.com/hashicorp/hcl/v2/hcltest"
"github.com/hashicorp/terraform/internal/configs/configschema"
)

func TestMarshalExpressions(t *testing.T) {
tests := []struct {
Input hcl.Body
Schema *configschema.Block
Want expressions
Input hcl.Body
Want expressions
}{
{
&hclsyntax.Body{
@@ -28,27 +28,73 @@ func TestMarshalExpressions(t *testing.T) {
},
},
},
&configschema.Block{
Attributes: map[string]*configschema.Attribute{
expressions{
"foo": expression{
ConstantValue: json.RawMessage([]byte(`"bar"`)),
References: []string(nil),
},
},
},
{
hcltest.MockBody(&hcl.BodyContent{
Attributes: hcl.Attributes{
"foo": {
Name: "foo",
Expr: hcltest.MockExprTraversalSrc(`var.list[1]`),
},
},
}),
expressions{
"foo": expression{
References: []string{"var.list[1]", "var.list"},
},
},
},
{
hcltest.MockBody(&hcl.BodyContent{
Attributes: hcl.Attributes{
"foo": {
Type: cty.String,
Optional: true,
Name: "foo",
Expr: hcltest.MockExprTraversalSrc(`data.template_file.foo[1].vars["baz"]`),
},
},
}),
expressions{
"foo": expression{
References: []string{"data.template_file.foo[1].vars[\"baz\"]", "data.template_file.foo[1].vars", "data.template_file.foo[1]", "data.template_file.foo"},
},
},
},
{
hcltest.MockBody(&hcl.BodyContent{
Attributes: hcl.Attributes{
"foo": {
Name: "foo",
Expr: hcltest.MockExprTraversalSrc(`module.foo.bar`),
},
},
}),
expressions{
"foo": expression{
ConstantValue: json.RawMessage([]byte(`"bar"`)),
References: []string(nil),
References: []string{"module.foo.bar", "module.foo"},
},
},
},
}

for _, test := range tests {
got := marshalExpressions(test.Input, test.Schema)
schema := &configschema.Block{
Attributes: map[string]*configschema.Attribute{
"foo": {
Type: cty.String,
Optional: true,
},
},
}

got := marshalExpressions(test.Input, schema)
if !reflect.DeepEqual(got, test.Want) {
t.Fatalf("wrong result:\nGot: %#v\nWant: %#v\n", got, test.Want)
t.Errorf("wrong result:\nGot: %#v\nWant: %#v\n", got, test.Want)
}
}
}
Loading