Skip to content

Commit 8d63ee9

Browse files
committed
Make terraform configuration compatible with v0.13
1 parent e4034ac commit 8d63ee9

File tree

7 files changed

+57
-39
lines changed

7 files changed

+57
-39
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ require (
88
github.com/hashicorp/go-plugin v1.3.0
99
github.com/hashicorp/go-version v1.2.1
1010
github.com/hashicorp/hcl/v2 v2.6.0
11+
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734
1112
github.com/zclconf/go-cty v1.5.1
1213
)

go.sum

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
2+
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
23
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
34
github.com/agext/levenshtein v1.2.1 h1:QmvMAjj2aEICytGiWzmxoE0x2KZvE0fvmqMOfy2tjT8=
45
github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
@@ -34,15 +35,19 @@ github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg=
3435
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
3536
github.com/google/go-cmp v0.5.1 h1:JFrFEBb2xKufg6XkJsJr+WbKb4FQlURi5RUcBveYu9k=
3637
github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
38+
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
3739
github.com/hashicorp/go-hclog v0.0.0-20180709165350-ff2cf002a8dd/go.mod h1:9bjs9uLqI8l75knNv3lV1kA55veR+WUPSiKIWcQHudI=
3840
github.com/hashicorp/go-hclog v0.14.1 h1:nQcJDQwIAGnmoUWp8ubocEX40cCml/17YkF6csQLReU=
3941
github.com/hashicorp/go-hclog v0.14.1/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ=
4042
github.com/hashicorp/go-plugin v1.3.0 h1:4d/wJojzvHV1I4i/rrjVaeuyxWrLzDE1mDCyDy8fXS8=
4143
github.com/hashicorp/go-plugin v1.3.0/go.mod h1:F9eH4LrE/ZsRdbwhfjs9k9HoDUwAHnYtXdgmf1AVNs0=
44+
github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
4245
github.com/hashicorp/go-version v1.2.1 h1:zEfKbn2+PDgroKdiOzqiE8rsmLqU2uwi5PB5pBJ3TkI=
4346
github.com/hashicorp/go-version v1.2.1/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
4447
github.com/hashicorp/hcl/v2 v2.6.0 h1:3krZOfGY6SziUXa6H9PJU6TyohHn7I+ARYnhbeNBz+o=
4548
github.com/hashicorp/hcl/v2 v2.6.0/go.mod h1:bQTN5mpo+jewjJgh8jr0JUguIi7qPHUF6yIfAEN3jqY=
49+
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 h1:HKLsbzeOsfXmKNpr3GiT18XAblV0BjCbzL8KQAMZGa0=
50+
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734/go.mod h1:kNDNcF7sN4DocDLBkQYz73HGKwN1ANB1blq4lIYLYvg=
4651
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb h1:b5rjCoWHc7eqmAS4/qyk21ZsHyb6Mxv/jykxvNTkU4M=
4752
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
4853
github.com/jhump/protoreflect v1.6.0 h1:h5jfMVslIg6l29nsMs0D8Wj17RDVdNYti0vDN/PZZoE=
@@ -76,6 +81,7 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
7681
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
7782
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
7883
github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
84+
github.com/zclconf/go-cty v1.1.0/go.mod h1:xnAOWiHeOqg2nWS62VtQ7pbOu17FtxJNW8RLEih+O3s=
7985
github.com/zclconf/go-cty v1.2.0/go.mod h1:hOPWgoHbaTUnI5k4D2ld+GRpFJSCe6bCM7m1q/N4PQ8=
8086
github.com/zclconf/go-cty v1.5.1 h1:oALUZX+aJeEBUe2a1+uD2+UTaYfEjnKFDEMRydkGvWE=
8187
github.com/zclconf/go-cty v1.5.1/go.mod h1:nHzOclRkoj++EU9ZjSrZvRG0BXIWt8c7loYc0qXAFGQ=
@@ -89,13 +95,18 @@ golang.org/x/net v0.0.0-20180530234432-1e491301e022/go.mod h1:mL1N/T3taQHkDXs73r
8995
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
9096
golang.org/x/net v0.0.0-20180811021610-c39426892332/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
9197
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
98+
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
9299
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
93100
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
94101
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ=
95102
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
103+
golang.org/x/net v0.0.0-20191009170851-d66e71096ffb h1:TR699M2v0qoKTOHxeLgp6zPqaQNs74f01a/ob9W0qko=
104+
golang.org/x/net v0.0.0-20191009170851-d66e71096ffb/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
96105
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
106+
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
97107
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
98108
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
109+
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
99110
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
100111
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
101112
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=

helper/runner.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,8 +473,7 @@ func simpleDecodeModuleCallBlock(block *hcl.Block) (*terraform.ModuleCall, hcl.D
473473
SourceAddrRange: sourceAddrRange,
474474
SourceSet: !sourceAddrRange.Empty(),
475475

476-
Config: remain,
477-
ConfigRange: block.DefRange,
476+
Config: remain,
478477

479478
Version: terraform.VersionConstraint{
480479
Required: versionRequired,

terraform/addrs.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
package terraform
22

3+
import svchost "github.com/hashicorp/terraform-svchost"
4+
5+
// Provider is an alternative representation of addrs.Provider.
6+
// https://github.com/hashicorp/terraform/blob/v0.13.1/addrs/provider.go#L16-L20
7+
type Provider struct {
8+
Type string
9+
Namespace string
10+
Hostname svchost.Hostname
11+
}
12+
313
// ResourceMode is an alternative representation of addrs.ResourceMode.
4-
// https://github.com/hashicorp/terraform/blob/v0.12.26/addrs/resource.go#L253-L271
14+
// https://github.com/hashicorp/terraform/blob/v0.13.1/addrs/resource.go#L326-L344
515
type ResourceMode rune
616

717
const (

terraform/configs.go

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
)
77

88
// Resource is an alternative representation of configs.Resource.
9-
// https://github.com/hashicorp/terraform/blob/v0.12.26/configs/resource.go#L13-L33
9+
// https://github.com/hashicorp/terraform/blob/v0.13.1/configs/resource.go#L14-L34
1010
// DependsOn is not supported due to the difficulty of intermediate representation.
1111
type Resource struct {
1212
Mode ResourceMode
@@ -17,6 +17,7 @@ type Resource struct {
1717
ForEach hcl.Expression
1818

1919
ProviderConfigRef *ProviderConfigRef
20+
Provider Provider
2021

2122
// DependsOn []hcl.Traversal
2223

@@ -27,7 +28,7 @@ type Resource struct {
2728
}
2829

2930
// ManagedResource is an alternative representation of configs.ManagedResource.
30-
// https://github.com/hashicorp/terraform/blob/v0.12.26/configs/resource.go#L35-L47
31+
// https://github.com/hashicorp/terraform/blob/v0.13.1/configs/resource.go#L37-L48
3132
// IgnoreChanges is not supported due to the difficulty of intermediate representation.
3233
type ManagedResource struct {
3334
Connection *Connection
@@ -43,14 +44,14 @@ type ManagedResource struct {
4344
}
4445

4546
// PassedProviderConfig is an alternative representation of configs.PassedProviderConfig.
46-
// https://github.com/hashicorp/terraform/blob/v0.12.26/configs/module_call.go#L155-L158
47+
// https://github.com/hashicorp/terraform/blob/v0.13.1/configs/module_call.go#L140-L143
4748
type PassedProviderConfig struct {
4849
InChild *ProviderConfigRef
4950
InParent *ProviderConfigRef
5051
}
5152

5253
// ProviderConfigRef is an alternative representation of configs.ProviderConfigRef.
53-
// https://github.com/hashicorp/terraform/blob/v0.12.26/configs/resource.go#L371-L376
54+
// https://github.com/hashicorp/terraform/blob/v0.13.1/configs/resource.go#L373-L378
5455
type ProviderConfigRef struct {
5556
Name string
5657
NameRange hcl.Range
@@ -59,7 +60,7 @@ type ProviderConfigRef struct {
5960
}
6061

6162
// Provisioner is an alternative representation of configs.Provisioner.
62-
// https://github.com/hashicorp/terraform/blob/v0.12.26/configs/provisioner.go#L9-L20
63+
// https://github.com/hashicorp/terraform/blob/v0.13.1/configs/provisioner.go#L11-L20
6364
type Provisioner struct {
6465
Type string
6566
Config hcl.Body
@@ -72,25 +73,25 @@ type Provisioner struct {
7273
}
7374

7475
// Connection is an alternative representation of configs.Connection.
75-
// https://github.com/hashicorp/terraform/blob/v0.12.26/configs/provisioner.go#L164-L170
76+
// https://github.com/hashicorp/terraform/blob/v0.13.1/configs/provisioner.go#L166-L170
7677
type Connection struct {
7778
Config hcl.Body
7879

7980
DeclRange hcl.Range
8081
}
8182

8283
// Backend is an alternative representation of configs.Backend.
83-
// https://github.com/hashicorp/terraform/blob/v0.12.26/configs/backend.go#L12-L18
84+
// https://github.com/hashicorp/terraform/blob/v0.13.1/configs/backend.go#L12-L18
8485
type Backend struct {
85-
Type string
86-
Config hcl.Body
87-
ConfigRange hcl.Range
88-
TypeRange hcl.Range
89-
DeclRange hcl.Range
86+
Type string
87+
Config hcl.Body
88+
89+
TypeRange hcl.Range
90+
DeclRange hcl.Range
9091
}
9192

9293
// ModuleCall is an alternative representation of configs.ModuleCall.
93-
// https://github.com/hashicorp/terraform/blob/v0.12.26/configs/module_call.go#L11-L31
94+
// https://github.com/hashicorp/terraform/blob/v0.13.1/configs/module_call.go#L12-L31
9495
// DependsOn is not supported due to the difficulty of intermediate representation.
9596
type ModuleCall struct {
9697
Name string
@@ -99,15 +100,12 @@ type ModuleCall struct {
99100
SourceAddrRange hcl.Range
100101
SourceSet bool
101102

102-
Config hcl.Body
103-
ConfigRange hcl.Range
103+
Config hcl.Body
104104

105105
Version VersionConstraint
106106

107-
Count hcl.Expression
108-
CountRange hcl.Range
109-
ForEach hcl.Expression
110-
ForEachRange hcl.Range
107+
Count hcl.Expression
108+
ForEach hcl.Expression
111109

112110
Providers []PassedProviderConfig
113111

@@ -117,14 +115,14 @@ type ModuleCall struct {
117115
}
118116

119117
// VersionConstraint is an alternative representation of configs.VersionConstraint.
120-
// https://github.com/hashicorp/terraform/blob/v0.12.26/configs/version_constraint.go#L16-L19
118+
// https://github.com/hashicorp/terraform/blob/v0.13.1/configs/version_constraint.go#L16-L19
121119
type VersionConstraint struct {
122120
Required version.Constraints
123121
DeclRange hcl.Range
124122
}
125123

126124
// ProvisionerWhen is an alternative representation of configs.ProvisionerWhen.
127-
// https://github.com/hashicorp/terraform/blob/v0.12.26/configs/provisioner.go#L172-L181
125+
// https://github.com/hashicorp/terraform/blob/v0.13.1/configs/provisioner.go#L172-L181
128126
type ProvisionerWhen int
129127

130128
const (
@@ -137,7 +135,7 @@ const (
137135
)
138136

139137
// ProvisionerOnFailure is an alternative representation of configs.ProvisionerOnFailure.
140-
// https://github.com/hashicorp/terraform/blob/v0.12.26/configs/provisioner.go#L183-L193
138+
// https://github.com/hashicorp/terraform/blob/v0.13.1/configs/provisioner.go#L183-L193
141139
type ProvisionerOnFailure int
142140

143141
const (

tflint/client/client_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ func (*mockServer) Resources(req *ResourcesRequest, resp *ResourcesResponse) err
6969
Count: nil,
7070
ForEach: nil,
7171
ProviderConfigRef: nil,
72+
Provider: terraform.Provider{Type: "aws", Namespace: "hashicorp", Hostname: "registry.terraform.io"},
7273
Managed: &ManagedResource{
7374
Connection: nil,
7475
Provisioners: []*Provisioner{},
@@ -188,9 +189,8 @@ func Test_Backend(t *testing.T) {
188189
SrcRange: hcl.Range{Filename: "example.tf", Start: hcl.Pos{Line: 3, Column: 5}, End: hcl.Pos{Line: 3, Column: 22}},
189190
EndRange: hcl.Range{Filename: "example.tf", Start: hcl.Pos{Line: 3, Column: 22}, End: hcl.Pos{Line: 3, Column: 22}},
190191
},
191-
ConfigRange: hcl.Range{Filename: "example.tf", Start: hcl.Pos{Line: 3, Column: 5}, End: hcl.Pos{Line: 3, Column: 22}},
192-
DeclRange: hcl.Range{Filename: "example.tf", Start: hcl.Pos{Line: 2, Column: 3}, End: hcl.Pos{Line: 2, Column: 22}},
193-
TypeRange: hcl.Range{Filename: "example.tf", Start: hcl.Pos{Line: 2, Column: 11}, End: hcl.Pos{Line: 2, Column: 19}},
192+
DeclRange: hcl.Range{Filename: "example.tf", Start: hcl.Pos{Line: 2, Column: 3}, End: hcl.Pos{Line: 2, Column: 22}},
193+
TypeRange: hcl.Range{Filename: "example.tf", Start: hcl.Pos{Line: 2, Column: 11}, End: hcl.Pos{Line: 2, Column: 19}},
194194
}
195195

196196
backend, err := client.Backend()
@@ -309,6 +309,7 @@ func Test_WalkResources(t *testing.T) {
309309
Count: nil,
310310
ForEach: nil,
311311
ProviderConfigRef: nil,
312+
Provider: terraform.Provider{Type: "aws", Namespace: "hashicorp", Hostname: "registry.terraform.io"},
312313
Managed: &terraform.ManagedResource{
313314
Connection: nil,
314315
Provisioners: []*terraform.Provisioner{},

tflint/client/decode.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ type Resource struct {
7474
ForEachRange hcl.Range
7575

7676
ProviderConfigRef *terraform.ProviderConfigRef
77+
Provider terraform.Provider
7778

7879
Managed *ManagedResource
7980

@@ -117,6 +118,7 @@ func decodeResource(resource *Resource) (*terraform.Resource, hcl.Diagnostics) {
117118
ForEach: forEach,
118119

119120
ProviderConfigRef: resource.ProviderConfigRef,
121+
Provider: resource.Provider,
120122

121123
Managed: managed,
122124

@@ -258,15 +260,12 @@ func decodeModuleCall(call *ModuleCall) (*terraform.ModuleCall, hcl.Diagnostics)
258260
SourceAddrRange: call.SourceAddrRange,
259261
SourceSet: call.SourceSet,
260262

261-
Config: file.Body,
262-
ConfigRange: call.ConfigRange,
263+
Config: file.Body,
263264

264265
Version: versionConstraint,
265266

266-
Count: count,
267-
CountRange: call.CountRange,
268-
ForEach: forEach,
269-
ForEachRange: call.ForEachRange,
267+
Count: count,
268+
ForEach: forEach,
270269

271270
Providers: providers,
272271
DeclRange: call.DeclRange,
@@ -293,11 +292,10 @@ func decodeBackend(backend *Backend) (*terraform.Backend, hcl.Diagnostics) {
293292
}
294293

295294
return &terraform.Backend{
296-
Type: backend.Type,
297-
Config: file.Body,
298-
TypeRange: backend.TypeRange,
299-
DeclRange: backend.DeclRange,
300-
ConfigRange: backend.ConfigRange,
295+
Type: backend.Type,
296+
Config: file.Body,
297+
TypeRange: backend.TypeRange,
298+
DeclRange: backend.DeclRange,
301299
}, nil
302300
}
303301

0 commit comments

Comments
 (0)