Skip to content

Commit 53afb31

Browse files
authored
Merge pull request #391 from hashicorp/more-cty-prune
Use hashicorp/go-cty fork and prune
2 parents a99f507 + cc4696e commit 53afb31

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+221
-2828
lines changed

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/hashicorp/terraform-plugin-sdk/v2
33
go 1.14
44

55
require (
6-
github.com/agext/levenshtein v1.2.2
6+
github.com/agext/levenshtein v1.2.2 // indirect
77
github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412 // indirect
88
github.com/apparentlymart/go-cidr v1.0.1
99
github.com/apparentlymart/go-dump v0.0.0-20190214190832-042adf3cf4a0
@@ -15,6 +15,7 @@ require (
1515
github.com/google/go-cmp v0.3.1
1616
github.com/hashicorp/errwrap v1.0.0
1717
github.com/hashicorp/go-cleanhttp v0.5.1
18+
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
1819
github.com/hashicorp/go-hclog v0.9.2 // indirect
1920
github.com/hashicorp/go-multierror v1.0.0
2021
github.com/hashicorp/go-plugin v1.2.0

go.sum

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ github.com/apparentlymart/go-dump v0.0.0-20190214190832-042adf3cf4a0 h1:MzVXffFU
2222
github.com/apparentlymart/go-dump v0.0.0-20190214190832-042adf3cf4a0/go.mod h1:oL81AME2rN47vu18xqj1S1jPIPuN7afo62yKTNn3XMM=
2323
github.com/apparentlymart/go-textseg v1.0.0 h1:rRmlIsPEEhUTIKQb7T++Nz/A5Q6C9IuX2wFoYVvnCs0=
2424
github.com/apparentlymart/go-textseg v1.0.0/go.mod h1:z96Txxhf3xSFMPmb5X/1W05FF/Nj9VFpLOpjS5yuumk=
25+
github.com/apparentlymart/go-textseg/v12 v12.0.0/go.mod h1:S/4uRK2UtaQttw1GenVJEynmyUenKwP++x/+DdGV/Ec=
2526
github.com/aws/aws-sdk-go v1.15.78 h1:LaXy6lWR0YK7LKyuU0QWy2ws/LWTPfYV/UgfiBu4tvY=
2627
github.com/aws/aws-sdk-go v1.15.78/go.mod h1:E3/ieXAlvM0XWO57iftYVDLLvQ824smPP3ATZkfNZeM=
2728
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d h1:xDfNPAt8lFiC1UJrqV3uuy861HCTo708pDMbjHHdCas=
@@ -71,6 +72,8 @@ github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brv
7172
github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
7273
github.com/hashicorp/go-cleanhttp v0.5.1 h1:dH3aiDG9Jvb5r5+bYHsikaOUIpcM0xvgMXVoDkXMzJM=
7374
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
75+
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 h1:1/D3zfFHttUKaCaGKZ/dR2roBXv0vKbSCnssIldfQdI=
76+
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320/go.mod h1:EiZBMaudVLy8fmjf9Npq1dq9RalhveqZG5w/yz3mHWs=
7477
github.com/hashicorp/go-getter v1.4.0 h1:ENHNi8494porjD0ZhIrjlAHnveSFhY7hvOJrV/fsKkw=
7578
github.com/hashicorp/go-getter v1.4.0/go.mod h1:7qxyCd8rBfcShwsvxgIguu4KbS3l8bUCwg2Umn7RjeY=
7679
github.com/hashicorp/go-hclog v0.0.0-20180709165350-ff2cf002a8dd/go.mod h1:9bjs9uLqI8l75knNv3lV1kA55veR+WUPSiKIWcQHudI=

helper/schema/core_schema.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package schema
33
import (
44
"fmt"
55

6-
"github.com/zclconf/go-cty/cty"
6+
"github.com/hashicorp/go-cty/cty"
77

88
"github.com/hashicorp/terraform-plugin-sdk/v2/internal/configs/configschema"
99
)

helper/schema/core_schema_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"testing"
66

77
"github.com/google/go-cmp/cmp"
8-
"github.com/zclconf/go-cty/cty"
8+
"github.com/hashicorp/go-cty/cty"
99

1010
"github.com/hashicorp/terraform-plugin-sdk/v2/internal/configs/configschema"
1111
)

helper/schema/provider_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"time"
1010

1111
"github.com/google/go-cmp/cmp"
12-
"github.com/zclconf/go-cty/cty"
12+
"github.com/hashicorp/go-cty/cty"
1313

1414
"github.com/hashicorp/terraform-plugin-sdk/v2/internal/configs/configschema"
1515
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"

helper/schema/resource.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"log"
88
"strconv"
99

10-
"github.com/zclconf/go-cty/cty"
10+
"github.com/hashicorp/go-cty/cty"
1111

1212
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
1313
)

helper/schema/resource_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
"testing"
99
"time"
1010

11-
"github.com/zclconf/go-cty/cty"
12-
ctyjson "github.com/zclconf/go-cty/cty/json"
11+
"github.com/hashicorp/go-cty/cty"
12+
ctyjson "github.com/hashicorp/go-cty/cty/json"
1313

1414
"github.com/hashicorp/terraform-plugin-sdk/v2/internal/configs/hcl2shim"
1515
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"

helper/schema/shims.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import (
44
"context"
55
"encoding/json"
66

7-
"github.com/zclconf/go-cty/cty"
8-
ctyjson "github.com/zclconf/go-cty/cty/json"
7+
"github.com/hashicorp/go-cty/cty"
8+
ctyjson "github.com/hashicorp/go-cty/cty/json"
99

1010
"github.com/hashicorp/terraform-plugin-sdk/v2/internal/configs/configschema"
1111
"github.com/hashicorp/terraform-plugin-sdk/v2/internal/configs/hcl2shim"

helper/schema/shims_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
"github.com/google/go-cmp/cmp"
1414
"github.com/google/go-cmp/cmp/cmpopts"
15-
"github.com/zclconf/go-cty/cty"
15+
"github.com/hashicorp/go-cty/cty"
1616

1717
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/hashcode"
1818
"github.com/hashicorp/terraform-plugin-sdk/v2/internal/configs/configschema"

internal/addrs/module_instance.go

Lines changed: 40 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,17 @@ func parseModuleInstance(traversal hcl.Traversal) (ModuleInstance, tfdiags.Diagn
3030
mi, remain, diags := parseModuleInstancePrefix(traversal)
3131
if len(remain) != 0 {
3232
if len(remain) == len(traversal) {
33-
diags = diags.Append(&hcl.Diagnostic{
34-
Severity: hcl.DiagError,
35-
Summary: "Invalid module instance address",
36-
Detail: "A module instance address must begin with \"module.\".",
37-
Subject: remain.SourceRange().Ptr(),
38-
})
33+
diags = append(diags, tfdiags.Diag(
34+
tfdiags.Error,
35+
"Invalid module instance address",
36+
"A module instance address must begin with \"module.\".",
37+
))
3938
} else {
40-
diags = diags.Append(&hcl.Diagnostic{
41-
Severity: hcl.DiagError,
42-
Summary: "Invalid module instance address",
43-
Detail: "The module instance address is followed by additional invalid content.",
44-
Subject: remain.SourceRange().Ptr(),
45-
})
39+
diags = append(diags, tfdiags.Diag(
40+
tfdiags.Error,
41+
"Invalid module instance address",
42+
"The module instance address is followed by additional invalid content.",
43+
))
4644
}
4745
}
4846
return mi, diags
@@ -67,13 +65,16 @@ func ParseModuleInstanceStr(str string) (ModuleInstance, tfdiags.Diagnostics) {
6765
var diags tfdiags.Diagnostics
6866

6967
traversal, parseDiags := hclsyntax.ParseTraversalAbs([]byte(str), "", hcl.Pos{Line: 1, Column: 1})
70-
diags = diags.Append(parseDiags)
68+
for _, err := range parseDiags.Errs() {
69+
// ignore warnings, they don't matter in this case
70+
diags = append(diags, tfdiags.FromError(err))
71+
}
7172
if parseDiags.HasErrors() {
7273
return nil, diags
7374
}
7475

7576
addr, addrDiags := parseModuleInstance(traversal)
76-
diags = diags.Append(addrDiags)
77+
diags = append(diags, addrDiags...)
7778
return addr, diags
7879
}
7980

@@ -90,31 +91,28 @@ func parseModuleInstancePrefix(traversal hcl.Traversal) (ModuleInstance, hcl.Tra
9091
case hcl.TraverseAttr:
9192
next = tt.Name
9293
default:
93-
diags = diags.Append(&hcl.Diagnostic{
94-
Severity: hcl.DiagError,
95-
Summary: "Invalid address operator",
96-
Detail: "Module address prefix must be followed by dot and then a name.",
97-
Subject: remain[0].SourceRange().Ptr(),
98-
})
94+
diags = append(diags, tfdiags.Diag(
95+
tfdiags.Error,
96+
"Invalid address operator",
97+
"Module address prefix must be followed by dot and then a name.",
98+
))
9999
break
100100
}
101101

102102
if next != "module" {
103103
break
104104
}
105105

106-
kwRange := remain[0].SourceRange()
107106
remain = remain[1:]
108107
// If we have the prefix "module" then we should be followed by an
109108
// module call name, as an attribute, and then optionally an index step
110109
// giving the instance key.
111110
if len(remain) == 0 {
112-
diags = diags.Append(&hcl.Diagnostic{
113-
Severity: hcl.DiagError,
114-
Summary: "Invalid address operator",
115-
Detail: "Prefix \"module.\" must be followed by a module name.",
116-
Subject: &kwRange,
117-
})
111+
diags = append(diags, tfdiags.Diag(
112+
tfdiags.Error,
113+
"Invalid address operator",
114+
"Prefix \"module.\" must be followed by a module name.",
115+
))
118116
break
119117
}
120118

@@ -123,12 +121,11 @@ func parseModuleInstancePrefix(traversal hcl.Traversal) (ModuleInstance, hcl.Tra
123121
case hcl.TraverseAttr:
124122
moduleName = tt.Name
125123
default:
126-
diags = diags.Append(&hcl.Diagnostic{
127-
Severity: hcl.DiagError,
128-
Summary: "Invalid address operator",
129-
Detail: "Prefix \"module.\" must be followed by a module name.",
130-
Subject: remain[0].SourceRange().Ptr(),
131-
})
124+
diags = append(diags, tfdiags.Diag(
125+
tfdiags.Error,
126+
"Invalid address operator",
127+
"Prefix \"module.\" must be followed by a module name.",
128+
))
132129
break
133130
}
134131
remain = remain[1:]
@@ -149,21 +146,19 @@ func parseModuleInstancePrefix(traversal hcl.Traversal) (ModuleInstance, hcl.Tra
149146
if err == nil {
150147
step.InstanceKey = intKey(idxInt)
151148
} else {
152-
diags = diags.Append(&hcl.Diagnostic{
153-
Severity: hcl.DiagError,
154-
Summary: "Invalid address operator",
155-
Detail: fmt.Sprintf("Invalid module index: %s.", err),
156-
Subject: idx.SourceRange().Ptr(),
157-
})
149+
diags = append(diags, tfdiags.Diag(
150+
tfdiags.Error,
151+
"Invalid address operator",
152+
fmt.Sprintf("Invalid module index: %s.", err),
153+
))
158154
}
159155
default:
160156
// Should never happen, because no other types are allowed in traversal indices.
161-
diags = diags.Append(&hcl.Diagnostic{
162-
Severity: hcl.DiagError,
163-
Summary: "Invalid address operator",
164-
Detail: "Invalid module key: must be either a string or an integer.",
165-
Subject: idx.SourceRange().Ptr(),
166-
})
157+
diags = append(diags, tfdiags.Diag(
158+
tfdiags.Error,
159+
"Invalid address operator",
160+
"Invalid module key: must be either a string or an integer.",
161+
))
167162
}
168163
}
169164
}

0 commit comments

Comments
 (0)