Skip to content

Commit

Permalink
Move github.com/hashicorp/terraform-config-inspect to internal/tfconfig
Browse files Browse the repository at this point in the history
Internally we depend on terraform-config-inspect, but at the moment
they state that they consider the project is feature-complete and
they do not accept any enhancement pull requests, as such we've
decided to bring over the project as internal package here rather than
being a vendor dependency and apply the fix from @jstewmon from
hashicorp/terraform-config-inspect#24 directly
here.

Since the terraform-config-inspect is considered to be feature-complete
we don't expect to have any more changes on the package, and if there
was a change on upstream we're going to bring it down in the
corresponding package.
  • Loading branch information
khos2ow committed Mar 22, 2020
1 parent ee97e8a commit aad2264
Show file tree
Hide file tree
Showing 130 changed files with 5,848 additions and 680 deletions.
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ run:
deadline: 5m
tests: true
modules-download-mode: vendor
skip-dirs:
- internal/tfconfig

linters:
disable-all: true
Expand Down
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ module github.com/segmentio/terraform-docs
go 1.14

require (
github.com/hashicorp/terraform-config-inspect v0.0.0-20200210163047-f7d8399e1194
github.com/go-test/deep v1.0.5
github.com/hashicorp/hcl v1.0.0
github.com/hashicorp/hcl/v2 v2.3.0
github.com/imdario/mergo v0.3.8
github.com/spf13/cobra v0.0.6
github.com/stretchr/testify v1.5.1
github.com/zclconf/go-cty v1.3.1
gopkg.in/yaml.v2 v2.2.8
mvdan.cc/xurls/v2 v2.1.0
)
29 changes: 12 additions & 17 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/agext/levenshtein v1.2.1 h1:QmvMAjj2aEICytGiWzmxoE0x2KZvE0fvmqMOfy2tjT8=
github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
github.com/agext/levenshtein v1.2.2 h1:0S/Yg6LYmFJ5stwQeRp6EeOcCbj7xiqQSdNelsXvaqE=
github.com/agext/levenshtein v1.2.2/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/apparentlymart/go-dump v0.0.0-20180507223929-23540a00eaa3/go.mod h1:oL81AME2rN47vu18xqj1S1jPIPuN7afo62yKTNn3XMM=
Expand Down Expand Up @@ -33,6 +32,8 @@ github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68=
github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
github.com/go-test/deep v1.0.5 h1:AKODKU3pDH1RzZzm6YZu77YWtEAq6uh1rLIAQlay2qc=
github.com/go-test/deep v1.0.5/go.mod h1:QV8Hv/iy04NyLBxAdO9njL0iVPN1S4d/A3NVv1V36o8=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
Expand All @@ -43,19 +44,16 @@ github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/hashicorp/hcl v0.0.0-20170504190234-a4b07c25de5f/go.mod h1:oZtUIOe8dh44I2q6ScRibXws4Ajl+d+nod3AaR9vL5w=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/hashicorp/hcl/v2 v2.0.0 h1:efQznTz+ydmQXq3BOnRa3AXzvCeTq1P4dKj/z5GLlY8=
github.com/hashicorp/hcl/v2 v2.0.0/go.mod h1:oVVDG71tEinNGYCxinCYadcmKU9bglqW9pV3txagJ90=
github.com/hashicorp/terraform-config-inspect v0.0.0-20200210163047-f7d8399e1194 h1:Zn54YFKlZ0tVcR4HCfmVUP9kTTIK1c7G5mW7JKMsaak=
github.com/hashicorp/terraform-config-inspect v0.0.0-20200210163047-f7d8399e1194/go.mod h1:p+ivJws3dpqbp1iP84+npOyAmTTOLMgCzrXd3GSdn/A=
github.com/hashicorp/hcl/v2 v2.3.0 h1:iRly8YaMwTBAKhn1Ybk7VSdzbnopghktCD031P8ggUE=
github.com/hashicorp/hcl/v2 v2.3.0/go.mod h1:d+FwDBbOLvpAM3Z6J7gPj/VoAGkNe/gm352ZhjJ/Zv8=
github.com/imdario/mergo v0.3.8 h1:CGgOkSJeqMRmt0D9XLWExdT4m4F1vd3FV3VPt+0VxkQ=
github.com/imdario/mergo v0.3.8/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
Expand All @@ -71,15 +69,13 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348 h1:MtvEpTB6LX3vkb4ax0b5D2DHbNAUsen0Gx5wZoq3lV4=
github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 h1:DpOJ2HYzCv8LZP15IdmG+YdwD2luVPHITV96TkirNBM=
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo=
github.com/mitchellh/go-wordwrap v1.0.0 h1:6GlHJ/LTGMrIJbwgdqdl2eEH8o+Exx/0m8ir9Gns0u4=
github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
Expand Down Expand Up @@ -118,17 +114,16 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=
github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
github.com/zclconf/go-cty v1.1.0 h1:uJwc9HiBOCpoKIObTQaLR+tsEXx1HBHnOsOOpcdhZgw=
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.3.1 h1:QIOZl+CKKdkv4l2w3lG23nNzXgLoxsWLSEdg1MlX4p0=
github.com/zclconf/go-cty v1.3.1/go.mod h1:YO23e2L18AG+ZYQfSobnY4G65nvwvprPCxBHkufUH1k=
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ func loadModule(dir string) (*Module, Diagnostics) {
}
v.Default = def
}
} else {
v.Required = true
}

case "output":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func loadModuleLegacyHCL(dir string) (*Module, Diagnostics) {
Type: block.Type,
Description: block.Description,
Default: block.Default,
Required: block.Default == nil,
Pos: sourcePosLegacyHCL(item.Pos(), filename),
}
if _, exists := mod.Variables[name]; exists {
Expand Down
59 changes: 59 additions & 0 deletions internal/tfconfig/load_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package tfconfig

import (
"encoding/json"
"io/ioutil"
"path/filepath"
"testing"

"github.com/go-test/deep"
)

func TestLoadModule(t *testing.T) {
fixturesDir := "testdata"
testDirs, err := ioutil.ReadDir(fixturesDir)
if err != nil {
t.Fatal(err)
}

for _, info := range testDirs {
if !info.IsDir() {
continue
}
t.Run(info.Name(), func(t *testing.T) {
name := info.Name()
path := filepath.Join(fixturesDir, name)

wantSrc, err := ioutil.ReadFile(filepath.Join(path, name+".out.json"))
if err != nil {
t.Fatalf("failed to read result file: %s", err)
}
var want map[string]interface{}
err = json.Unmarshal(wantSrc, &want)
if err != nil {
t.Fatalf("failed to parse result file: %s", err)
}

gotObj, _ := LoadModule(path)
if gotObj == nil {
t.Fatalf("result object is nil; want a real object")
}

gotSrc, err := json.Marshal(gotObj)
if err != nil {
t.Fatalf("result is not JSON-able: %s", err)
}
var got map[string]interface{}
err = json.Unmarshal(gotSrc, &got)
if err != nil {
t.Fatalf("failed to parse the actual result (!?): %s", err)
}

if diff := deep.Equal(got, want); diff != nil {
for _, problem := range diff {
t.Errorf("%s", problem)
}
}
})
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
72 changes: 72 additions & 0 deletions internal/tfconfig/testdata/basics-json/basics-json.out.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"path": "testdata/basics-json",
"required_providers": {
"null": {}
},
"variables": {
"A": {
"name": "A",
"default": "A default",
"required": false,
"pos": {
"filename": "testdata/basics-json/basics.tf.json",
"line": 3
}
},
"B": {
"name": "B",
"description": "The B variable",
"default": null,
"required": true,
"pos": {
"filename": "testdata/basics-json/basics.tf.json",
"line": 6
}
}
},
"outputs": {
"A": {
"name": "A",
"pos": {
"filename": "testdata/basics-json/basics.tf.json",
"line": 11
}
},
"B": {
"name": "B",
"description": "I am B",
"pos": {
"filename": "testdata/basics-json/basics.tf.json",
"line": 14
}
}
},
"managed_resources": {
"null_resource.A": {
"mode": "managed",
"type": "null_resource",
"name": "A",
"provider": {
"name": "null"
},
"pos": {
"filename": "testdata/basics-json/basics.tf.json",
"line": 21
}
},
"null_resource.B": {
"mode": "managed",
"type": "null_resource",
"name": "B",
"provider": {
"name": "null"
},
"pos": {
"filename": "testdata/basics-json/basics.tf.json",
"line": 22
}
}
},
"data_resources": {},
"module_calls": {}
}
25 changes: 25 additions & 0 deletions internal/tfconfig/testdata/basics-json/basics.tf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"variable": {
"A": {
"default": "A default"
},
"B": {
"description": "The B variable"
}
},
"output": {
"A": {
"value": "${var.A}"
},
"B": {
"description": "I am B",
"value": "${var.A}"
}
},
"resource": {
"null_resource": {
"A": {},
"B": {}
}
}
}
72 changes: 72 additions & 0 deletions internal/tfconfig/testdata/basics/basics.out.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"path": "testdata/basics",
"required_providers": {
"null": {}
},
"variables": {
"A": {
"name": "A",
"default": "A default",
"required": false,
"pos": {
"filename": "testdata/basics/basics.tf",
"line": 1
}
},
"B": {
"name": "B",
"description": "The B variable",
"default": null,
"required": true,
"pos": {
"filename": "testdata/basics/basics.tf",
"line": 5
}
}
},
"outputs": {
"A": {
"name": "A",
"pos": {
"filename": "testdata/basics/basics.tf",
"line": 9
}
},
"B": {
"name": "B",
"description": "I am B",
"pos": {
"filename": "testdata/basics/basics.tf",
"line": 13
}
}
},
"managed_resources": {
"null_resource.A": {
"mode": "managed",
"type": "null_resource",
"name": "A",
"provider": {
"name": "null"
},
"pos": {
"filename": "testdata/basics/basics.tf",
"line": 18
}
},
"null_resource.B": {
"mode": "managed",
"type": "null_resource",
"name": "B",
"provider": {
"name": "null"
},
"pos": {
"filename": "testdata/basics/basics.tf",
"line": 19
}
}
},
"data_resources": {},
"module_calls": {}
}
18 changes: 18 additions & 0 deletions internal/tfconfig/testdata/basics/basics.out.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

# Module `testdata/basics`

Provider Requirements:
* **null:** (any version)

## Input Variables
* `A` (default `"A default"`)
* `B` (required): The B variable

## Output Values
* `A`
* `B`: I am B

## Managed Resources
* `null_resource.A` from `null`
* `null_resource.B` from `null`

19 changes: 19 additions & 0 deletions internal/tfconfig/testdata/basics/basics.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
variable "A" {
default = "A default"
}

variable "B" {
description = "The B variable"
}

output "A" {
value = "${var.A}"
}

output "B" {
description = "I am B"
value = "${var.A}"
}

resource "null_resource" "A" {}
resource "null_resource" "B" {}
Loading

0 comments on commit aad2264

Please sign in to comment.