diff --git a/go.mod b/go.mod index 6b68812..189edb9 100644 --- a/go.mod +++ b/go.mod @@ -4,16 +4,12 @@ go 1.15 require ( github.com/BurntSushi/toml v0.3.1 - github.com/go-test/deep v1.0.7 - github.com/hashicorp/hcl v1.0.0 - github.com/hashicorp/hcl/v2 v2.8.1 github.com/iancoleman/orderedmap v0.1.0 github.com/imdario/mergo v0.3.11 github.com/spf13/cobra v1.1.1 github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.6.1 github.com/terraform-docs/terraform-config-inspect v0.0.0-20210126151735-6ef25af8884f - github.com/zclconf/go-cty v1.7.1 gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 mvdan.cc/xurls/v2 v2.2.0 ) diff --git a/go.sum b/go.sum index b00db68..73d2dbb 100644 --- a/go.sum +++ b/go.sum @@ -24,8 +24,6 @@ github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRF github.com/apparentlymart/go-dump v0.0.0-20180507223929-23540a00eaa3/go.mod h1:oL81AME2rN47vu18xqj1S1jPIPuN7afo62yKTNn3XMM= github.com/apparentlymart/go-textseg v1.0.0 h1:rRmlIsPEEhUTIKQb7T++Nz/A5Q6C9IuX2wFoYVvnCs0= github.com/apparentlymart/go-textseg v1.0.0/go.mod h1:z96Txxhf3xSFMPmb5X/1W05FF/Nj9VFpLOpjS5yuumk= -github.com/apparentlymart/go-textseg/v12 v12.0.0 h1:bNEQyAGak9tojivJNkoqWErVCQbjdL7GzRt3F8NvfJ0= -github.com/apparentlymart/go-textseg/v12 v12.0.0/go.mod h1:S/4uRK2UtaQttw1GenVJEynmyUenKwP++x/+DdGV/Ec= github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= @@ -56,8 +54,6 @@ 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.7 h1:/VSMRlnY/JSyqxQUzQLKVMAskpY/NZKFA5j2P+0pP2M= -github.com/go-test/deep v1.0.7/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= @@ -69,13 +65,11 @@ github.com/golang/protobuf v1.1.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= 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/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= @@ -105,9 +99,8 @@ github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ 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/hcl/v2 v2.8.1 h1:FJ60CIYaMyJOKzPndhMyjiz353Fd+2jr6PodF5Xzb08= -github.com/hashicorp/hcl/v2 v2.8.1/go.mod h1:bQTN5mpo+jewjJgh8jr0JUguIi7qPHUF6yIfAEN3jqY= github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ= github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I= @@ -212,13 +205,9 @@ github.com/terraform-docs/terraform-config-inspect v0.0.0-20210126151735-6ef25af github.com/terraform-docs/terraform-config-inspect v0.0.0-20210126151735-6ef25af8884f/go.mod h1:GtanFwTsRRXScYHOMb5h4K18XQBFeS2tXat9/LrPtPc= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= -github.com/vmihailenco/msgpack/v4 v4.3.12/go.mod h1:gborTTJjAo/GWTqqRjrLCn9pgNN+NXzzngzBKDPIqw4= -github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= +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.7.1 h1:AvsC01GMhMLFL8CgEYdHGM+yLnnDOwhPAYcgTkeF0Gw= -github.com/zclconf/go-cty v1.7.1/go.mod h1:VDR4+I79ubFBGm1uJac1226K5yANQFHeauxPBoP54+o= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= @@ -264,7 +253,6 @@ golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -310,6 +298,7 @@ golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgw golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc h1:NCy3Ohtk6Iny5V/reW2Ktypo4zIpWBdRJ1uFMjBxdg8= golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= @@ -321,7 +310,6 @@ google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9Ywl google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= -google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= @@ -356,6 +344,7 @@ honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099 h1:XJP7lxbSxWLOMNdBE4B/STa honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.1-2019.2.3 h1:3JgtbtFHMiCmsznwGVTUWbgGov+pVqnlf1dEJTNAXeM= honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= mvdan.cc/xurls/v2 v2.2.0 h1:NSZPykBXJFCetGZykLAxaL6SIpvbVy/UFEniIfHAa8A= mvdan.cc/xurls/v2 v2.2.0/go.mod h1:EV1RMtya9D6G5DMYPGD8zTQzaHet6Jh8gFlRgGRJeO8= diff --git a/internal/cli/config.go b/internal/cli/config.go index 729ac72..2cbbe87 100644 --- a/internal/cli/config.go +++ b/internal/cli/config.go @@ -3,7 +3,7 @@ package cli import ( "fmt" - "github.com/terraform-docs/terraform-docs/internal/module" + "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/pkg/print" ) @@ -311,10 +311,10 @@ func (c *Config) validate() error { return nil } -// extract and build print.Settings and module.Options out of Config -func (c *Config) extract() (*print.Settings, *module.Options) { +// extract and build print.Settings and terraform.Options out of Config +func (c *Config) extract() (*print.Settings, *terraform.Options) { settings := print.NewSettings() - options := module.NewOptions() + options := terraform.NewOptions() // header-from options.HeaderFromFile = c.HeaderFrom diff --git a/internal/cli/run.go b/internal/cli/run.go index 440e457..eb2ddbf 100644 --- a/internal/cli/run.go +++ b/internal/cli/run.go @@ -9,7 +9,7 @@ import ( "github.com/spf13/pflag" "github.com/terraform-docs/terraform-docs/internal/format" - "github.com/terraform-docs/terraform-docs/internal/module" + "github.com/terraform-docs/terraform-docs/internal/terraform" ) // list of flagset items which are explicitly changed from CLI @@ -80,26 +80,27 @@ func PreRunEFunc(config *Config) func(*cobra.Command, []string) error { // RunEFunc returns actual 'cobra.Command#RunE' function for // 'formatter' commands. This functions extract print.Settings -// and module.Options from generated and normalized Config and +// and terraform.Options from generated and normalized Config and // initializes required print.Format instance and executes it. func RunEFunc(config *Config) func(*cobra.Command, []string) error { return func(cmd *cobra.Command, args []string) error { settings, options := config.extract() + options.Path = args[0] + + var output string + var err error + + module, err := terraform.LoadWithOptions(options) + if err != nil { + return err + } printer, err := format.Factory(config.Formatter, settings) if err != nil { return err } - options.Path = args[0] - - tfmodule, err := module.LoadWithOptions(options) - if err != nil { - return err - - } - - output, err := printer.Print(tfmodule, settings) + output, err = printer.Print(module, settings) if err != nil { return err } diff --git a/internal/format/asciidoc_document.go b/internal/format/asciidoc_document.go index 1353d73..6e8aca0 100644 --- a/internal/format/asciidoc_document.go +++ b/internal/format/asciidoc_document.go @@ -3,8 +3,8 @@ package format import ( "text/template" + "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/pkg/print" - "github.com/terraform-docs/terraform-docs/pkg/tfconf" "github.com/terraform-docs/terraform-docs/pkg/tmpl" ) @@ -190,7 +190,7 @@ func NewAsciidocDocument(settings *print.Settings) *AsciidocDocument { } // Print prints a Terraform module as AsciiDoc document. -func (d *AsciidocDocument) Print(module *tfconf.Module, settings *print.Settings) (string, error) { +func (d *AsciidocDocument) Print(module *terraform.Module, settings *print.Settings) (string, error) { rendered, err := d.template.Render(module) if err != nil { return "", err diff --git a/internal/format/asciidoc_document_test.go b/internal/format/asciidoc_document_test.go index 0927f96..3dddd3c 100644 --- a/internal/format/asciidoc_document_test.go +++ b/internal/format/asciidoc_document_test.go @@ -5,7 +5,7 @@ import ( "github.com/stretchr/testify/assert" - "github.com/terraform-docs/terraform-docs/internal/module" + "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/internal/testutil" "github.com/terraform-docs/terraform-docs/pkg/print" ) @@ -17,7 +17,7 @@ func TestAsciidocDocument(t *testing.T) { expected, err := testutil.GetExpected("asciidoc", "document") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -37,7 +37,7 @@ func TestAsciidocDocumentWithRequired(t *testing.T) { expected, err := testutil.GetExpected("asciidoc", "document-WithRequired") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -57,8 +57,8 @@ func TestAsciidocDocumentSortByName(t *testing.T) { expected, err := testutil.GetExpected("asciidoc", "document-SortByName") assert.Nil(err) - options, err := module.NewOptions().With(&module.Options{ - SortBy: &module.SortBy{ + options, err := terraform.NewOptions().With(&terraform.Options{ + SortBy: &terraform.SortBy{ Name: true, }, }) @@ -84,8 +84,8 @@ func TestAsciidocDocumentSortByRequired(t *testing.T) { expected, err := testutil.GetExpected("asciidoc", "document-SortByRequired") assert.Nil(err) - options, err := module.NewOptions().With(&module.Options{ - SortBy: &module.SortBy{ + options, err := terraform.NewOptions().With(&terraform.Options{ + SortBy: &terraform.SortBy{ Name: true, Required: true, }, @@ -111,8 +111,8 @@ func TestAsciidocDocumentSortByType(t *testing.T) { expected, err := testutil.GetExpected("asciidoc", "document-SortByType") assert.Nil(err) - options, err := module.NewOptions().With(&module.Options{ - SortBy: &module.SortBy{ + options, err := terraform.NewOptions().With(&terraform.Options{ + SortBy: &terraform.SortBy{ Type: true, }, }) @@ -141,7 +141,7 @@ func TestAsciidocDocumentNoHeader(t *testing.T) { expected, err := testutil.GetExpected("asciidoc", "document-NoHeader") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -165,7 +165,7 @@ func TestAsciidocDocumentNoInputs(t *testing.T) { expected, err := testutil.GetExpected("asciidoc", "document-NoInputs") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -189,7 +189,7 @@ func TestAsciidocDocumentNoOutputs(t *testing.T) { expected, err := testutil.GetExpected("asciidoc", "document-NoOutputs") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -213,7 +213,7 @@ func TestAsciidocDocumentNoProviders(t *testing.T) { expected, err := testutil.GetExpected("asciidoc", "document-NoProviders") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -237,7 +237,7 @@ func TestAsciidocDocumentNoRequirements(t *testing.T) { expected, err := testutil.GetExpected("asciidoc", "document-NoRequirements") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -261,7 +261,7 @@ func TestAsciidocDocumentOnlyHeader(t *testing.T) { expected, err := testutil.GetExpected("asciidoc", "document-OnlyHeader") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -285,7 +285,7 @@ func TestAsciidocDocumentOnlyInputs(t *testing.T) { expected, err := testutil.GetExpected("asciidoc", "document-OnlyInputs") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -309,7 +309,7 @@ func TestAsciidocDocumentOnlyOutputs(t *testing.T) { expected, err := testutil.GetExpected("asciidoc", "document-OnlyOutputs") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -333,7 +333,7 @@ func TestAsciidocDocumentOnlyProviders(t *testing.T) { expected, err := testutil.GetExpected("asciidoc", "document-OnlyProviders") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -357,7 +357,7 @@ func TestAsciidocDocumentOnlyRequirements(t *testing.T) { expected, err := testutil.GetExpected("asciidoc", "document-OnlyRequirements") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -377,7 +377,7 @@ func TestAsciidocDocumentIndentationBelowAllowed(t *testing.T) { expected, err := testutil.GetExpected("asciidoc", "document-IndentationBelowAllowed") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -397,7 +397,7 @@ func TestAsciidocDocumentIndentationAboveAllowed(t *testing.T) { expected, err := testutil.GetExpected("asciidoc", "document-IndentationAboveAllowed") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -417,7 +417,7 @@ func TestAsciidocDocumentIndentationOfFour(t *testing.T) { expected, err := testutil.GetExpected("asciidoc", "document-IndentationOfFour") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -438,7 +438,7 @@ func TestAsciidocDocumentOutputValues(t *testing.T) { expected, err := testutil.GetExpected("asciidoc", "document-OutputValues") assert.Nil(err) - options, err := module.NewOptions().With(&module.Options{ + options, err := terraform.NewOptions().With(&terraform.Options{ OutputValues: true, OutputValuesPath: "output_values.json", }) @@ -489,7 +489,7 @@ func TestAsciidocDocumentHeaderFromFile(t *testing.T) { expected, err := testutil.GetExpected("asciidoc", tt.golden) assert.Nil(err) - options, err := module.NewOptions().WithOverwrite(&module.Options{ + options, err := terraform.NewOptions().WithOverwrite(&terraform.Options{ HeaderFromFile: tt.file, }) assert.Nil(err) @@ -516,7 +516,7 @@ func TestAsciidocDocumentOutputValuesNoSensitivity(t *testing.T) { expected, err := testutil.GetExpected("asciidoc", "document-OutputValuesNoSensitivity") assert.Nil(err) - options, err := module.NewOptions().With(&module.Options{ + options, err := terraform.NewOptions().With(&terraform.Options{ OutputValues: true, OutputValuesPath: "output_values.json", }) @@ -541,7 +541,7 @@ func TestAsciidocDocumentEmpty(t *testing.T) { ShowOutputs: false, }).Build() - options, err := module.NewOptions().WithOverwrite(&module.Options{ + options, err := terraform.NewOptions().WithOverwrite(&terraform.Options{ HeaderFromFile: "bad.tf", }) options.ShowHeader = false // Since we don't show the header, the file won't be loaded at all diff --git a/internal/format/asciidoc_table.go b/internal/format/asciidoc_table.go index cd2fd29..e650bbe 100644 --- a/internal/format/asciidoc_table.go +++ b/internal/format/asciidoc_table.go @@ -3,8 +3,8 @@ package format import ( "text/template" + "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/pkg/print" - "github.com/terraform-docs/terraform-docs/pkg/tfconf" "github.com/terraform-docs/terraform-docs/pkg/tmpl" ) @@ -153,7 +153,7 @@ func NewAsciidocTable(settings *print.Settings) *AsciidocTable { } // Print prints a Terraform module as AsciiDoc tables. -func (t *AsciidocTable) Print(module *tfconf.Module, settings *print.Settings) (string, error) { +func (t *AsciidocTable) Print(module *terraform.Module, settings *print.Settings) (string, error) { rendered, err := t.template.Render(module) if err != nil { return "", err diff --git a/internal/format/asciidoc_table_test.go b/internal/format/asciidoc_table_test.go index 31cecbf..be81d81 100644 --- a/internal/format/asciidoc_table_test.go +++ b/internal/format/asciidoc_table_test.go @@ -5,7 +5,7 @@ import ( "github.com/stretchr/testify/assert" - "github.com/terraform-docs/terraform-docs/internal/module" + "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/internal/testutil" "github.com/terraform-docs/terraform-docs/pkg/print" ) @@ -17,7 +17,7 @@ func TestAsciidocTable(t *testing.T) { expected, err := testutil.GetExpected("asciidoc", "table") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -37,7 +37,7 @@ func TestAsciidocTableWithRequired(t *testing.T) { expected, err := testutil.GetExpected("asciidoc", "table-WithRequired") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -57,8 +57,8 @@ func TestAsciidocTableSortByName(t *testing.T) { expected, err := testutil.GetExpected("asciidoc", "table-SortByName") assert.Nil(err) - options, err := module.NewOptions().With(&module.Options{ - SortBy: &module.SortBy{ + options, err := terraform.NewOptions().With(&terraform.Options{ + SortBy: &terraform.SortBy{ Name: true, }, }) @@ -84,8 +84,8 @@ func TestAsciidocTableSortByRequired(t *testing.T) { expected, err := testutil.GetExpected("asciidoc", "table-SortByRequired") assert.Nil(err) - options, err := module.NewOptions().With(&module.Options{ - SortBy: &module.SortBy{ + options, err := terraform.NewOptions().With(&terraform.Options{ + SortBy: &terraform.SortBy{ Name: true, Required: true, }, @@ -111,8 +111,8 @@ func TestAsciidocTableSortByType(t *testing.T) { expected, err := testutil.GetExpected("asciidoc", "table-SortByType") assert.Nil(err) - options, err := module.NewOptions().With(&module.Options{ - SortBy: &module.SortBy{ + options, err := terraform.NewOptions().With(&terraform.Options{ + SortBy: &terraform.SortBy{ Type: true, }, }) @@ -141,7 +141,7 @@ func TestAsciidocTableNoHeader(t *testing.T) { expected, err := testutil.GetExpected("asciidoc", "table-NoHeader") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -165,7 +165,7 @@ func TestAsciidocTableNoInputs(t *testing.T) { expected, err := testutil.GetExpected("asciidoc", "table-NoInputs") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -189,7 +189,7 @@ func TestAsciidocTableNoOutputs(t *testing.T) { expected, err := testutil.GetExpected("asciidoc", "table-NoOutputs") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -213,7 +213,7 @@ func TestAsciidocTableNoProviders(t *testing.T) { expected, err := testutil.GetExpected("asciidoc", "table-NoProviders") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -237,7 +237,7 @@ func TestAsciidocTableNoRequirements(t *testing.T) { expected, err := testutil.GetExpected("asciidoc", "table-NoRequirements") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -261,7 +261,7 @@ func TestAsciidocTableOnlyHeader(t *testing.T) { expected, err := testutil.GetExpected("asciidoc", "table-OnlyHeader") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -285,7 +285,7 @@ func TestAsciidocTableOnlyInputs(t *testing.T) { expected, err := testutil.GetExpected("asciidoc", "table-OnlyInputs") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -309,7 +309,7 @@ func TestAsciidocTableOnlyOutputs(t *testing.T) { expected, err := testutil.GetExpected("asciidoc", "table-OnlyOutputs") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -333,7 +333,7 @@ func TestAsciidocTableOnlyProviders(t *testing.T) { expected, err := testutil.GetExpected("asciidoc", "table-OnlyProviders") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -357,7 +357,7 @@ func TestAsciidocTableOnlyRequirements(t *testing.T) { expected, err := testutil.GetExpected("asciidoc", "table-OnlyRequirements") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -377,7 +377,7 @@ func TestAsciidocTableIndentationBelowAllowed(t *testing.T) { expected, err := testutil.GetExpected("asciidoc", "table-IndentationBelowAllowed") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -397,7 +397,7 @@ func TestAsciidocTableIndentationAboveAllowed(t *testing.T) { expected, err := testutil.GetExpected("asciidoc", "table-IndentationAboveAllowed") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -417,7 +417,7 @@ func TestAsciidocTableIndentationOfFour(t *testing.T) { expected, err := testutil.GetExpected("asciidoc", "table-IndentationOfFour") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -438,7 +438,7 @@ func TestAsciidocTableOutputValues(t *testing.T) { expected, err := testutil.GetExpected("asciidoc", "table-OutputValues") assert.Nil(err) - options, err := module.NewOptions().With(&module.Options{ + options, err := terraform.NewOptions().With(&terraform.Options{ OutputValues: true, OutputValuesPath: "output_values.json", }) @@ -489,7 +489,7 @@ func TestAsciidocTableHeaderFromFile(t *testing.T) { expected, err := testutil.GetExpected("asciidoc", tt.golden) assert.Nil(err) - options, err := module.NewOptions().WithOverwrite(&module.Options{ + options, err := terraform.NewOptions().WithOverwrite(&terraform.Options{ HeaderFromFile: tt.file, }) assert.Nil(err) @@ -516,7 +516,7 @@ func TestAsciidocTableOutputValuesNoSensitivity(t *testing.T) { expected, err := testutil.GetExpected("asciidoc", "table-OutputValuesNoSensitivity") assert.Nil(err) - options, err := module.NewOptions().With(&module.Options{ + options, err := terraform.NewOptions().With(&terraform.Options{ OutputValues: true, OutputValuesPath: "output_values.json", }) @@ -541,7 +541,7 @@ func TestAsciidocTableEmpty(t *testing.T) { ShowOutputs: false, }).Build() - options, err := module.NewOptions().WithOverwrite(&module.Options{ + options, err := terraform.NewOptions().WithOverwrite(&terraform.Options{ HeaderFromFile: "bad.tf", }) options.ShowHeader = false // Since we don't show the header, the file won't be loaded at all diff --git a/internal/format/json.go b/internal/format/json.go index 070c5ea..b43e4d8 100644 --- a/internal/format/json.go +++ b/internal/format/json.go @@ -5,8 +5,8 @@ import ( "encoding/json" "strings" + "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/pkg/print" - "github.com/terraform-docs/terraform-docs/pkg/tfconf" ) // JSON represents JSON format. @@ -18,13 +18,13 @@ func NewJSON(settings *print.Settings) *JSON { } // Print prints a Terraform module as json. -func (j *JSON) Print(module *tfconf.Module, settings *print.Settings) (string, error) { - copy := &tfconf.Module{ +func (j *JSON) Print(module *terraform.Module, settings *print.Settings) (string, error) { + copy := &terraform.Module{ Header: "", - Inputs: make([]*tfconf.Input, 0), - Outputs: make([]*tfconf.Output, 0), - Providers: make([]*tfconf.Provider, 0), - Requirements: make([]*tfconf.Requirement, 0), + Inputs: make([]*terraform.Input, 0), + Outputs: make([]*terraform.Output, 0), + Providers: make([]*terraform.Provider, 0), + Requirements: make([]*terraform.Requirement, 0), } if settings.ShowHeader { diff --git a/internal/format/json_test.go b/internal/format/json_test.go index 0a03a0e..a1084a9 100644 --- a/internal/format/json_test.go +++ b/internal/format/json_test.go @@ -5,7 +5,7 @@ import ( "github.com/stretchr/testify/assert" - "github.com/terraform-docs/terraform-docs/internal/module" + "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/internal/testutil" "github.com/terraform-docs/terraform-docs/pkg/print" ) @@ -17,7 +17,7 @@ func TestJson(t *testing.T) { expected, err := testutil.GetExpected("json", "json") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -37,8 +37,8 @@ func TestJsonSortByName(t *testing.T) { expected, err := testutil.GetExpected("json", "json-SortByName") assert.Nil(err) - options, err := module.NewOptions().With(&module.Options{ - SortBy: &module.SortBy{ + options, err := terraform.NewOptions().With(&terraform.Options{ + SortBy: &terraform.SortBy{ Name: true, }, }) @@ -64,8 +64,8 @@ func TestJsonSortByRequired(t *testing.T) { expected, err := testutil.GetExpected("json", "json-SortByRequired") assert.Nil(err) - options, err := module.NewOptions().With(&module.Options{ - SortBy: &module.SortBy{ + options, err := terraform.NewOptions().With(&terraform.Options{ + SortBy: &terraform.SortBy{ Name: true, Required: true, }, @@ -91,8 +91,8 @@ func TestJsonSortByType(t *testing.T) { expected, err := testutil.GetExpected("json", "json-SortByType") assert.Nil(err) - options, err := module.NewOptions().With(&module.Options{ - SortBy: &module.SortBy{ + options, err := terraform.NewOptions().With(&terraform.Options{ + SortBy: &terraform.SortBy{ Type: true, }, }) @@ -121,7 +121,7 @@ func TestJsonNoHeader(t *testing.T) { expected, err := testutil.GetExpected("json", "json-NoHeader") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -145,7 +145,7 @@ func TestJsonNoInputs(t *testing.T) { expected, err := testutil.GetExpected("json", "json-NoInputs") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -169,7 +169,7 @@ func TestJsonNoOutputs(t *testing.T) { expected, err := testutil.GetExpected("json", "json-NoOutputs") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -193,7 +193,7 @@ func TestJsonNoProviders(t *testing.T) { expected, err := testutil.GetExpected("json", "json-NoProviders") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -217,7 +217,7 @@ func TestJsonNoRequirements(t *testing.T) { expected, err := testutil.GetExpected("json", "json-NoRequirements") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -241,7 +241,7 @@ func TestJsonOnlyHeader(t *testing.T) { expected, err := testutil.GetExpected("json", "json-OnlyHeader") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -265,7 +265,7 @@ func TestJsonOnlyInputs(t *testing.T) { expected, err := testutil.GetExpected("json", "json-OnlyInputs") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -289,7 +289,7 @@ func TestJsonOnlyOutputs(t *testing.T) { expected, err := testutil.GetExpected("json", "json-OnlyOutputs") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -313,7 +313,7 @@ func TestJsonOnlyProviders(t *testing.T) { expected, err := testutil.GetExpected("json", "json-OnlyProviders") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -337,7 +337,7 @@ func TestJsonOnlyRequirements(t *testing.T) { expected, err := testutil.GetExpected("json", "json-OnlyRequirements") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -357,7 +357,7 @@ func TestJsonEscapeCharacters(t *testing.T) { expected, err := testutil.GetExpected("json", "json-EscapeCharacters") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -377,7 +377,7 @@ func TestJsonOutputValues(t *testing.T) { expected, err := testutil.GetExpected("json", "json-OutputValues") assert.Nil(err) - options, err := module.NewOptions().With(&module.Options{ + options, err := terraform.NewOptions().With(&terraform.Options{ OutputValues: true, OutputValuesPath: "output_values.json", }) @@ -428,7 +428,7 @@ func TestJsonHeaderFromFile(t *testing.T) { expected, err := testutil.GetExpected("json", tt.golden) assert.Nil(err) - options, err := module.NewOptions().WithOverwrite(&module.Options{ + options, err := terraform.NewOptions().WithOverwrite(&terraform.Options{ HeaderFromFile: tt.file, }) assert.Nil(err) @@ -457,7 +457,7 @@ func TestJsonEmpty(t *testing.T) { expected, err := testutil.GetExpected("json", "json-Empty") assert.Nil(err) - options, err := module.NewOptions().WithOverwrite(&module.Options{ + options, err := terraform.NewOptions().WithOverwrite(&terraform.Options{ HeaderFromFile: "bad.tf", }) options.ShowHeader = false // Since we don't show the header, the file won't be loaded at all diff --git a/internal/format/markdown_document.go b/internal/format/markdown_document.go index 5ac3dde..f97ef11 100644 --- a/internal/format/markdown_document.go +++ b/internal/format/markdown_document.go @@ -3,8 +3,8 @@ package format import ( "text/template" + "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/pkg/print" - "github.com/terraform-docs/terraform-docs/pkg/tfconf" "github.com/terraform-docs/terraform-docs/pkg/tmpl" ) @@ -189,7 +189,7 @@ func NewDocument(settings *print.Settings) *Document { } // Print prints a Terraform module as Markdown document. -func (d *Document) Print(module *tfconf.Module, settings *print.Settings) (string, error) { +func (d *Document) Print(module *terraform.Module, settings *print.Settings) (string, error) { rendered, err := d.template.Render(module) if err != nil { return "", err diff --git a/internal/format/markdown_document_test.go b/internal/format/markdown_document_test.go index d47e5e0..a27326b 100644 --- a/internal/format/markdown_document_test.go +++ b/internal/format/markdown_document_test.go @@ -5,7 +5,7 @@ import ( "github.com/stretchr/testify/assert" - "github.com/terraform-docs/terraform-docs/internal/module" + "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/internal/testutil" "github.com/terraform-docs/terraform-docs/pkg/print" ) @@ -17,7 +17,7 @@ func TestDocument(t *testing.T) { expected, err := testutil.GetExpected("markdown", "document") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -37,7 +37,7 @@ func TestDocumentWithRequired(t *testing.T) { expected, err := testutil.GetExpected("markdown", "document-WithRequired") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -57,8 +57,8 @@ func TestDocumentSortByName(t *testing.T) { expected, err := testutil.GetExpected("markdown", "document-SortByName") assert.Nil(err) - options, err := module.NewOptions().With(&module.Options{ - SortBy: &module.SortBy{ + options, err := terraform.NewOptions().With(&terraform.Options{ + SortBy: &terraform.SortBy{ Name: true, }, }) @@ -84,8 +84,8 @@ func TestDocumentSortByRequired(t *testing.T) { expected, err := testutil.GetExpected("markdown", "document-SortByRequired") assert.Nil(err) - options, err := module.NewOptions().With(&module.Options{ - SortBy: &module.SortBy{ + options, err := terraform.NewOptions().With(&terraform.Options{ + SortBy: &terraform.SortBy{ Name: true, Required: true, }, @@ -111,8 +111,8 @@ func TestDocumentSortByType(t *testing.T) { expected, err := testutil.GetExpected("markdown", "document-SortByType") assert.Nil(err) - options, err := module.NewOptions().With(&module.Options{ - SortBy: &module.SortBy{ + options, err := terraform.NewOptions().With(&terraform.Options{ + SortBy: &terraform.SortBy{ Type: true, }, }) @@ -141,7 +141,7 @@ func TestDocumentNoHeader(t *testing.T) { expected, err := testutil.GetExpected("markdown", "document-NoHeader") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -165,7 +165,7 @@ func TestDocumentNoInputs(t *testing.T) { expected, err := testutil.GetExpected("markdown", "document-NoInputs") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -189,7 +189,7 @@ func TestDocumentNoOutputs(t *testing.T) { expected, err := testutil.GetExpected("markdown", "document-NoOutputs") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -213,7 +213,7 @@ func TestDocumentNoProviders(t *testing.T) { expected, err := testutil.GetExpected("markdown", "document-NoProviders") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -237,7 +237,7 @@ func TestDocumentNoRequirements(t *testing.T) { expected, err := testutil.GetExpected("markdown", "document-NoRequirements") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -261,7 +261,7 @@ func TestDocumentOnlyHeader(t *testing.T) { expected, err := testutil.GetExpected("markdown", "document-OnlyHeader") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -285,7 +285,7 @@ func TestDocumentOnlyInputs(t *testing.T) { expected, err := testutil.GetExpected("markdown", "document-OnlyInputs") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -309,7 +309,7 @@ func TestDocumentOnlyOutputs(t *testing.T) { expected, err := testutil.GetExpected("markdown", "document-OnlyOutputs") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -333,7 +333,7 @@ func TestDocumentOnlyProviders(t *testing.T) { expected, err := testutil.GetExpected("markdown", "document-OnlyProviders") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -357,7 +357,7 @@ func TestDocumentOnlyRequirements(t *testing.T) { expected, err := testutil.GetExpected("markdown", "document-OnlyRequirements") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -377,7 +377,7 @@ func TestDocumentEscapeCharacters(t *testing.T) { expected, err := testutil.GetExpected("markdown", "document-EscapeCharacters") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -397,7 +397,7 @@ func TestDocumentIndentationBelowAllowed(t *testing.T) { expected, err := testutil.GetExpected("markdown", "document-IndentationBelowAllowed") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -417,7 +417,7 @@ func TestDocumentIndentationAboveAllowed(t *testing.T) { expected, err := testutil.GetExpected("markdown", "document-IndentationAboveAllowed") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -437,7 +437,7 @@ func TestDocumentIndentationOfFour(t *testing.T) { expected, err := testutil.GetExpected("markdown", "document-IndentationOfFour") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -458,7 +458,7 @@ func TestDocumentOutputValues(t *testing.T) { expected, err := testutil.GetExpected("markdown", "document-OutputValues") assert.Nil(err) - options, err := module.NewOptions().With(&module.Options{ + options, err := terraform.NewOptions().With(&terraform.Options{ OutputValues: true, OutputValuesPath: "output_values.json", }) @@ -509,7 +509,7 @@ func TestDocumentHeaderFromFile(t *testing.T) { expected, err := testutil.GetExpected("markdown", tt.golden) assert.Nil(err) - options, err := module.NewOptions().WithOverwrite(&module.Options{ + options, err := terraform.NewOptions().WithOverwrite(&terraform.Options{ HeaderFromFile: tt.file, }) assert.Nil(err) @@ -536,7 +536,7 @@ func TestDocumentOutputValuesNoSensitivity(t *testing.T) { expected, err := testutil.GetExpected("markdown", "document-OutputValuesNoSensitivity") assert.Nil(err) - options, err := module.NewOptions().With(&module.Options{ + options, err := terraform.NewOptions().With(&terraform.Options{ OutputValues: true, OutputValuesPath: "output_values.json", }) @@ -561,7 +561,7 @@ func TestDocumentEmpty(t *testing.T) { ShowOutputs: false, }).Build() - options, err := module.NewOptions().WithOverwrite(&module.Options{ + options, err := terraform.NewOptions().WithOverwrite(&terraform.Options{ HeaderFromFile: "bad.tf", }) options.ShowHeader = false // Since we don't show the header, the file won't be loaded at all diff --git a/internal/format/markdown_table.go b/internal/format/markdown_table.go index 0424088..ada670d 100644 --- a/internal/format/markdown_table.go +++ b/internal/format/markdown_table.go @@ -3,8 +3,8 @@ package format import ( "text/template" + "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/pkg/print" - "github.com/terraform-docs/terraform-docs/pkg/tfconf" "github.com/terraform-docs/terraform-docs/pkg/tmpl" ) @@ -143,7 +143,7 @@ func NewTable(settings *print.Settings) *Table { } // Print prints a Terraform module as Markdown tables. -func (t *Table) Print(module *tfconf.Module, settings *print.Settings) (string, error) { +func (t *Table) Print(module *terraform.Module, settings *print.Settings) (string, error) { rendered, err := t.template.Render(module) if err != nil { return "", err diff --git a/internal/format/markdown_table_test.go b/internal/format/markdown_table_test.go index 5d74828..643bfe9 100644 --- a/internal/format/markdown_table_test.go +++ b/internal/format/markdown_table_test.go @@ -5,7 +5,7 @@ import ( "github.com/stretchr/testify/assert" - "github.com/terraform-docs/terraform-docs/internal/module" + "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/internal/testutil" "github.com/terraform-docs/terraform-docs/pkg/print" ) @@ -17,7 +17,7 @@ func TestTable(t *testing.T) { expected, err := testutil.GetExpected("markdown", "table") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -37,7 +37,7 @@ func TestTableWithRequired(t *testing.T) { expected, err := testutil.GetExpected("markdown", "table-WithRequired") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -57,8 +57,8 @@ func TestTableSortByName(t *testing.T) { expected, err := testutil.GetExpected("markdown", "table-SortByName") assert.Nil(err) - options, err := module.NewOptions().With(&module.Options{ - SortBy: &module.SortBy{ + options, err := terraform.NewOptions().With(&terraform.Options{ + SortBy: &terraform.SortBy{ Name: true, }, }) @@ -84,8 +84,8 @@ func TestTableSortByRequired(t *testing.T) { expected, err := testutil.GetExpected("markdown", "table-SortByRequired") assert.Nil(err) - options, err := module.NewOptions().With(&module.Options{ - SortBy: &module.SortBy{ + options, err := terraform.NewOptions().With(&terraform.Options{ + SortBy: &terraform.SortBy{ Name: true, Required: true, }, @@ -111,8 +111,8 @@ func TestTableSortByType(t *testing.T) { expected, err := testutil.GetExpected("markdown", "table-SortByType") assert.Nil(err) - options, err := module.NewOptions().With(&module.Options{ - SortBy: &module.SortBy{ + options, err := terraform.NewOptions().With(&terraform.Options{ + SortBy: &terraform.SortBy{ Type: true, }, }) @@ -141,7 +141,7 @@ func TestTableNoHeader(t *testing.T) { expected, err := testutil.GetExpected("markdown", "table-NoHeader") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -165,7 +165,7 @@ func TestTableNoInputs(t *testing.T) { expected, err := testutil.GetExpected("markdown", "table-NoInputs") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -189,7 +189,7 @@ func TestTableNoOutputs(t *testing.T) { expected, err := testutil.GetExpected("markdown", "table-NoOutputs") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -213,7 +213,7 @@ func TestTableNoProviders(t *testing.T) { expected, err := testutil.GetExpected("markdown", "table-NoProviders") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -237,7 +237,7 @@ func TestTableNoRequirements(t *testing.T) { expected, err := testutil.GetExpected("markdown", "table-NoRequirements") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -261,7 +261,7 @@ func TestTableOnlyHeader(t *testing.T) { expected, err := testutil.GetExpected("markdown", "table-OnlyHeader") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -285,7 +285,7 @@ func TestTableOnlyInputs(t *testing.T) { expected, err := testutil.GetExpected("markdown", "table-OnlyInputs") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -309,7 +309,7 @@ func TestTableOnlyOutputs(t *testing.T) { expected, err := testutil.GetExpected("markdown", "table-OnlyOutputs") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -333,7 +333,7 @@ func TestTableOnlyProviders(t *testing.T) { expected, err := testutil.GetExpected("markdown", "table-OnlyProviders") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -357,7 +357,7 @@ func TestTableOnlyRequirements(t *testing.T) { expected, err := testutil.GetExpected("markdown", "table-OnlyRequirements") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -377,7 +377,7 @@ func TestTableEscapeCharacters(t *testing.T) { expected, err := testutil.GetExpected("markdown", "table-EscapeCharacters") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -397,7 +397,7 @@ func TestTableIndentationBelowAllowed(t *testing.T) { expected, err := testutil.GetExpected("markdown", "table-IndentationBelowAllowed") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -417,7 +417,7 @@ func TestTableIndentationAboveAllowed(t *testing.T) { expected, err := testutil.GetExpected("markdown", "table-IndentationAboveAllowed") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -437,7 +437,7 @@ func TestTableIndentationOfFour(t *testing.T) { expected, err := testutil.GetExpected("markdown", "table-IndentationOfFour") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -458,7 +458,7 @@ func TestTableOutputValues(t *testing.T) { expected, err := testutil.GetExpected("markdown", "table-OutputValues") assert.Nil(err) - options, err := module.NewOptions().With(&module.Options{ + options, err := terraform.NewOptions().With(&terraform.Options{ OutputValues: true, OutputValuesPath: "output_values.json", }) @@ -509,7 +509,7 @@ func TestTableHeaderFromFile(t *testing.T) { expected, err := testutil.GetExpected("markdown", tt.golden) assert.Nil(err) - options, err := module.NewOptions().WithOverwrite(&module.Options{ + options, err := terraform.NewOptions().WithOverwrite(&terraform.Options{ HeaderFromFile: tt.file, }) assert.Nil(err) @@ -536,7 +536,7 @@ func TestTableOutputValuesNoSensitivity(t *testing.T) { expected, err := testutil.GetExpected("markdown", "table-OutputValuesNoSensitivity") assert.Nil(err) - options, err := module.NewOptions().With(&module.Options{ + options, err := terraform.NewOptions().With(&terraform.Options{ OutputValues: true, OutputValuesPath: "output_values.json", }) @@ -561,7 +561,7 @@ func TestTableEmpty(t *testing.T) { ShowOutputs: false, }).Build() - options, err := module.NewOptions().WithOverwrite(&module.Options{ + options, err := terraform.NewOptions().WithOverwrite(&terraform.Options{ HeaderFromFile: "bad.tf", }) options.ShowHeader = false // Since we don't show the header, the file won't be loaded at all diff --git a/internal/format/pretty.go b/internal/format/pretty.go index 492dfde..da29123 100644 --- a/internal/format/pretty.go +++ b/internal/format/pretty.go @@ -5,8 +5,8 @@ import ( "regexp" "text/template" + "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/pkg/print" - "github.com/terraform-docs/terraform-docs/pkg/tfconf" "github.com/terraform-docs/terraform-docs/pkg/tmpl" ) @@ -125,7 +125,7 @@ func NewPretty(settings *print.Settings) *Pretty { } // Print prints a Terraform module document. -func (p *Pretty) Print(module *tfconf.Module, settings *print.Settings) (string, error) { +func (p *Pretty) Print(module *terraform.Module, settings *print.Settings) (string, error) { rendered, err := p.template.Render(module) if err != nil { return "", err diff --git a/internal/format/pretty_test.go b/internal/format/pretty_test.go index 9139f15..96e05d9 100644 --- a/internal/format/pretty_test.go +++ b/internal/format/pretty_test.go @@ -5,7 +5,7 @@ import ( "github.com/stretchr/testify/assert" - "github.com/terraform-docs/terraform-docs/internal/module" + "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/internal/testutil" "github.com/terraform-docs/terraform-docs/pkg/print" ) @@ -17,7 +17,7 @@ func TestPretty(t *testing.T) { expected, err := testutil.GetExpected("pretty", "pretty") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -37,8 +37,8 @@ func TestPrettySortByName(t *testing.T) { expected, err := testutil.GetExpected("pretty", "pretty-SortByName") assert.Nil(err) - options, err := module.NewOptions().With(&module.Options{ - SortBy: &module.SortBy{ + options, err := terraform.NewOptions().With(&terraform.Options{ + SortBy: &terraform.SortBy{ Name: true, }, }) @@ -64,8 +64,8 @@ func TestPrettySortByRequired(t *testing.T) { expected, err := testutil.GetExpected("pretty", "pretty-SortByRequired") assert.Nil(err) - options, err := module.NewOptions().With(&module.Options{ - SortBy: &module.SortBy{ + options, err := terraform.NewOptions().With(&terraform.Options{ + SortBy: &terraform.SortBy{ Name: true, Required: true, }, @@ -91,8 +91,8 @@ func TestPrettySortByType(t *testing.T) { expected, err := testutil.GetExpected("pretty", "pretty-SortByType") assert.Nil(err) - options, err := module.NewOptions().With(&module.Options{ - SortBy: &module.SortBy{ + options, err := terraform.NewOptions().With(&terraform.Options{ + SortBy: &terraform.SortBy{ Type: true, }, }) @@ -121,7 +121,7 @@ func TestPrettyNoHeader(t *testing.T) { expected, err := testutil.GetExpected("pretty", "pretty-NoHeader") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -145,7 +145,7 @@ func TestPrettyNoInputs(t *testing.T) { expected, err := testutil.GetExpected("pretty", "pretty-NoInputs") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -169,7 +169,7 @@ func TestPrettyNoOutputs(t *testing.T) { expected, err := testutil.GetExpected("pretty", "pretty-NoOutputs") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -193,7 +193,7 @@ func TestPrettyNoProviders(t *testing.T) { expected, err := testutil.GetExpected("pretty", "pretty-NoProviders") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -217,7 +217,7 @@ func TestPrettyNoRequirements(t *testing.T) { expected, err := testutil.GetExpected("pretty", "pretty-NoRequirements") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -241,7 +241,7 @@ func TestPrettyOnlyHeader(t *testing.T) { expected, err := testutil.GetExpected("pretty", "pretty-OnlyHeader") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -265,7 +265,7 @@ func TestPrettyOnlyInputs(t *testing.T) { expected, err := testutil.GetExpected("pretty", "pretty-OnlyInputs") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -289,7 +289,7 @@ func TestPrettyOnlyOutputs(t *testing.T) { expected, err := testutil.GetExpected("pretty", "pretty-OnlyOutputs") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -313,7 +313,7 @@ func TestPrettyOnlyProviders(t *testing.T) { expected, err := testutil.GetExpected("pretty", "pretty-OnlyProviders") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -337,7 +337,7 @@ func TestPrettyOnlyRequirements(t *testing.T) { expected, err := testutil.GetExpected("pretty", "pretty-OnlyRequirements") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -357,7 +357,7 @@ func TestPrettyNoColor(t *testing.T) { expected, err := testutil.GetExpected("pretty", "pretty-NoColor") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -377,7 +377,7 @@ func TestPrettyOutputValues(t *testing.T) { expected, err := testutil.GetExpected("pretty", "pretty-OutputValues") assert.Nil(err) - options, err := module.NewOptions().With(&module.Options{ + options, err := terraform.NewOptions().With(&terraform.Options{ OutputValues: true, OutputValuesPath: "output_values.json", }) @@ -428,7 +428,7 @@ func TestPrettyHeaderFromFile(t *testing.T) { expected, err := testutil.GetExpected("pretty", tt.golden) assert.Nil(err) - options, err := module.NewOptions().WithOverwrite(&module.Options{ + options, err := terraform.NewOptions().WithOverwrite(&terraform.Options{ HeaderFromFile: tt.file, }) assert.Nil(err) @@ -454,7 +454,7 @@ func TestPrettyEmpty(t *testing.T) { ShowOutputs: false, }).Build() - options, err := module.NewOptions().WithOverwrite(&module.Options{ + options, err := terraform.NewOptions().WithOverwrite(&terraform.Options{ HeaderFromFile: "bad.tf", }) options.ShowHeader = false // Since we don't show the header, the file won't be loaded at all diff --git a/internal/format/tfvars_hcl.go b/internal/format/tfvars_hcl.go index c8becaf..0e4ddf9 100644 --- a/internal/format/tfvars_hcl.go +++ b/internal/format/tfvars_hcl.go @@ -6,8 +6,8 @@ import ( "strings" "text/template" + "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/pkg/print" - "github.com/terraform-docs/terraform-docs/pkg/tfconf" "github.com/terraform-docs/terraform-docs/pkg/tmpl" ) @@ -52,7 +52,7 @@ func NewTfvarsHCL(settings *print.Settings) *TfvarsHCL { } // Print prints a Terraform module as Terraform tfvars HCL document. -func (h *TfvarsHCL) Print(module *tfconf.Module, settings *print.Settings) (string, error) { +func (h *TfvarsHCL) Print(module *terraform.Module, settings *print.Settings) (string, error) { alignments(module.Inputs) rendered, err := h.template.Render(module) if err != nil { @@ -61,7 +61,7 @@ func (h *TfvarsHCL) Print(module *tfconf.Module, settings *print.Settings) (stri return strings.TrimSuffix(sanitize(rendered), "\n"), nil } -func alignments(inputs []*tfconf.Input) { +func alignments(inputs []*terraform.Input) { padding = make([]int, len(inputs)) maxlen := 0 index := 0 diff --git a/internal/format/tfvars_hcl_test.go b/internal/format/tfvars_hcl_test.go index 1b495ce..7c08490 100644 --- a/internal/format/tfvars_hcl_test.go +++ b/internal/format/tfvars_hcl_test.go @@ -5,7 +5,7 @@ import ( "github.com/stretchr/testify/assert" - "github.com/terraform-docs/terraform-docs/internal/module" + "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/internal/testutil" "github.com/terraform-docs/terraform-docs/pkg/print" ) @@ -17,7 +17,7 @@ func TestTfvarsHcl(t *testing.T) { expected, err := testutil.GetExpected("tfvars", "hcl") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -37,8 +37,8 @@ func TestTfvarsHclSortByName(t *testing.T) { expected, err := testutil.GetExpected("tfvars", "hcl-SortByName") assert.Nil(err) - options, err := module.NewOptions().With(&module.Options{ - SortBy: &module.SortBy{ + options, err := terraform.NewOptions().With(&terraform.Options{ + SortBy: &terraform.SortBy{ Name: true, }, }) @@ -64,8 +64,8 @@ func TestTfvarsHclSortByRequired(t *testing.T) { expected, err := testutil.GetExpected("tfvars", "hcl-SortByRequired") assert.Nil(err) - options, err := module.NewOptions().With(&module.Options{ - SortBy: &module.SortBy{ + options, err := terraform.NewOptions().With(&terraform.Options{ + SortBy: &terraform.SortBy{ Name: true, Required: true, }, @@ -91,8 +91,8 @@ func TestTfvarsHclSortByType(t *testing.T) { expected, err := testutil.GetExpected("tfvars", "hcl-SortByType") assert.Nil(err) - options, err := module.NewOptions().With(&module.Options{ - SortBy: &module.SortBy{ + options, err := terraform.NewOptions().With(&terraform.Options{ + SortBy: &terraform.SortBy{ Type: true, }, }) @@ -121,7 +121,7 @@ func TestTfvarsHclNoInputs(t *testing.T) { expected, err := testutil.GetExpected("tfvars", "hcl-NoInputs") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -141,7 +141,7 @@ func TestTfvarsHclEscapeCharacters(t *testing.T) { expected, err := testutil.GetExpected("tfvars", "hcl-EscapeCharacters") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) diff --git a/internal/format/tfvars_json.go b/internal/format/tfvars_json.go index 6918070..40f2adf 100644 --- a/internal/format/tfvars_json.go +++ b/internal/format/tfvars_json.go @@ -7,8 +7,8 @@ import ( "github.com/iancoleman/orderedmap" + "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/pkg/print" - "github.com/terraform-docs/terraform-docs/pkg/tfconf" ) // TfvarsJSON represents Terraform tfvars JSON format. @@ -20,7 +20,7 @@ func NewTfvarsJSON(settings *print.Settings) *TfvarsJSON { } // Print prints a Terraform module as Terraform tfvars JSON document. -func (j *TfvarsJSON) Print(module *tfconf.Module, settings *print.Settings) (string, error) { +func (j *TfvarsJSON) Print(module *terraform.Module, settings *print.Settings) (string, error) { copy := orderedmap.New() copy.SetEscapeHTML(false) for _, i := range module.Inputs { diff --git a/internal/format/tfvars_json_test.go b/internal/format/tfvars_json_test.go index d8e3535..858ee98 100644 --- a/internal/format/tfvars_json_test.go +++ b/internal/format/tfvars_json_test.go @@ -5,7 +5,7 @@ import ( "github.com/stretchr/testify/assert" - "github.com/terraform-docs/terraform-docs/internal/module" + "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/internal/testutil" "github.com/terraform-docs/terraform-docs/pkg/print" ) @@ -17,7 +17,7 @@ func TestTfvarsJson(t *testing.T) { expected, err := testutil.GetExpected("tfvars", "json") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -37,8 +37,8 @@ func TestTfvarsJsonSortByName(t *testing.T) { expected, err := testutil.GetExpected("tfvars", "json-SortByName") assert.Nil(err) - options, err := module.NewOptions().With(&module.Options{ - SortBy: &module.SortBy{ + options, err := terraform.NewOptions().With(&terraform.Options{ + SortBy: &terraform.SortBy{ Name: true, }, }) @@ -64,8 +64,8 @@ func TestTfvarsJsonSortByRequired(t *testing.T) { expected, err := testutil.GetExpected("tfvars", "json-SortByRequired") assert.Nil(err) - options, err := module.NewOptions().With(&module.Options{ - SortBy: &module.SortBy{ + options, err := terraform.NewOptions().With(&terraform.Options{ + SortBy: &terraform.SortBy{ Name: true, Required: true, }, @@ -91,8 +91,8 @@ func TestTfvarsJsonSortByType(t *testing.T) { expected, err := testutil.GetExpected("tfvars", "json-SortByType") assert.Nil(err) - options, err := module.NewOptions().With(&module.Options{ - SortBy: &module.SortBy{ + options, err := terraform.NewOptions().With(&terraform.Options{ + SortBy: &terraform.SortBy{ Type: true, }, }) @@ -121,7 +121,7 @@ func TestTfvarsJsonNoInputs(t *testing.T) { expected, err := testutil.GetExpected("tfvars", "json-NoInputs") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -141,7 +141,7 @@ func TestTfvarsJsonEscapeCharacters(t *testing.T) { expected, err := testutil.GetExpected("tfvars", "json-EscapeCharacters") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) diff --git a/internal/format/toml.go b/internal/format/toml.go index 29ebd84..f8ebc73 100644 --- a/internal/format/toml.go +++ b/internal/format/toml.go @@ -6,8 +6,8 @@ import ( "github.com/BurntSushi/toml" + "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/pkg/print" - "github.com/terraform-docs/terraform-docs/pkg/tfconf" ) // TOML represents TOML format. @@ -19,13 +19,13 @@ func NewTOML(settings *print.Settings) *TOML { } // Print prints a Terraform module as toml. -func (t *TOML) Print(module *tfconf.Module, settings *print.Settings) (string, error) { - copy := tfconf.Module{ +func (t *TOML) Print(module *terraform.Module, settings *print.Settings) (string, error) { + copy := terraform.Module{ Header: "", - Providers: make([]*tfconf.Provider, 0), - Inputs: make([]*tfconf.Input, 0), - Outputs: make([]*tfconf.Output, 0), - Requirements: make([]*tfconf.Requirement, 0), + Providers: make([]*terraform.Provider, 0), + Inputs: make([]*terraform.Input, 0), + Outputs: make([]*terraform.Output, 0), + Requirements: make([]*terraform.Requirement, 0), } if settings.ShowHeader { diff --git a/internal/format/toml_test.go b/internal/format/toml_test.go index f7feeec..bc53aa3 100644 --- a/internal/format/toml_test.go +++ b/internal/format/toml_test.go @@ -5,7 +5,7 @@ import ( "github.com/stretchr/testify/assert" - "github.com/terraform-docs/terraform-docs/internal/module" + "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/internal/testutil" "github.com/terraform-docs/terraform-docs/pkg/print" ) @@ -17,7 +17,7 @@ func TestToml(t *testing.T) { expected, err := testutil.GetExpected("toml", "toml") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -37,8 +37,8 @@ func TestTomlSortByName(t *testing.T) { expected, err := testutil.GetExpected("toml", "toml-SortByName") assert.Nil(err) - options, err := module.NewOptions().With(&module.Options{ - SortBy: &module.SortBy{ + options, err := terraform.NewOptions().With(&terraform.Options{ + SortBy: &terraform.SortBy{ Name: true, }, }) @@ -64,8 +64,8 @@ func TestTomlSortByRequired(t *testing.T) { expected, err := testutil.GetExpected("toml", "toml-SortByRequired") assert.Nil(err) - options, err := module.NewOptions().With(&module.Options{ - SortBy: &module.SortBy{ + options, err := terraform.NewOptions().With(&terraform.Options{ + SortBy: &terraform.SortBy{ Name: true, Required: true, }, @@ -91,8 +91,8 @@ func TestTomlSortByType(t *testing.T) { expected, err := testutil.GetExpected("toml", "toml-SortByType") assert.Nil(err) - options, err := module.NewOptions().With(&module.Options{ - SortBy: &module.SortBy{ + options, err := terraform.NewOptions().With(&terraform.Options{ + SortBy: &terraform.SortBy{ Type: true, }, }) @@ -121,7 +121,7 @@ func TestTomlNoHeader(t *testing.T) { expected, err := testutil.GetExpected("toml", "toml-NoHeader") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -145,7 +145,7 @@ func TestTomlNoInputs(t *testing.T) { expected, err := testutil.GetExpected("toml", "toml-NoInputs") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -169,7 +169,7 @@ func TestTomlNoOutputs(t *testing.T) { expected, err := testutil.GetExpected("toml", "toml-NoOutputs") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -193,7 +193,7 @@ func TestTomlNoProviders(t *testing.T) { expected, err := testutil.GetExpected("toml", "toml-NoProviders") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -217,7 +217,7 @@ func TestTomlNoRequirements(t *testing.T) { expected, err := testutil.GetExpected("toml", "toml-NoRequirements") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -241,7 +241,7 @@ func TestTomlOnlyHeader(t *testing.T) { expected, err := testutil.GetExpected("toml", "toml-OnlyHeader") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -265,7 +265,7 @@ func TestTomlOnlyInputs(t *testing.T) { expected, err := testutil.GetExpected("toml", "toml-OnlyInputs") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -289,7 +289,7 @@ func TestTomlOnlyOutputs(t *testing.T) { expected, err := testutil.GetExpected("toml", "toml-OnlyOutputs") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -313,7 +313,7 @@ func TestTomlOnlyProviders(t *testing.T) { expected, err := testutil.GetExpected("toml", "toml-OnlyProviders") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -337,7 +337,7 @@ func TestTomlOnlyRequirements(t *testing.T) { expected, err := testutil.GetExpected("toml", "toml-OnlyRequirements") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -357,7 +357,7 @@ func TestTomlOutputValues(t *testing.T) { expected, err := testutil.GetExpected("toml", "toml-OutputValues") assert.Nil(err) - options, err := module.NewOptions().With(&module.Options{ + options, err := terraform.NewOptions().With(&terraform.Options{ OutputValues: true, OutputValuesPath: "output_values.json", }) @@ -380,7 +380,7 @@ func TestTomlHeaderFromFile(t *testing.T) { expected, err := testutil.GetExpected("toml", "toml-HeaderFromFile") assert.Nil(err) - options, err := module.NewOptions().WithOverwrite(&module.Options{ + options, err := terraform.NewOptions().WithOverwrite(&terraform.Options{ HeaderFromFile: "doc.tf", }) assert.Nil(err) @@ -408,7 +408,7 @@ func TestTomlEmpty(t *testing.T) { expected, err := testutil.GetExpected("toml", "toml-Empty") assert.Nil(err) - options, err := module.NewOptions().WithOverwrite(&module.Options{ + options, err := terraform.NewOptions().WithOverwrite(&terraform.Options{ HeaderFromFile: "bad.tf", }) options.ShowHeader = false // Since we don't show the header, the file won't be loaded at all diff --git a/internal/format/xml.go b/internal/format/xml.go index f88f2b7..12c90a8 100644 --- a/internal/format/xml.go +++ b/internal/format/xml.go @@ -4,8 +4,8 @@ import ( "encoding/xml" "strings" + "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/pkg/print" - "github.com/terraform-docs/terraform-docs/pkg/tfconf" ) // XML represents XML format. @@ -17,13 +17,13 @@ func NewXML(settings *print.Settings) *XML { } // Print prints a Terraform module as xml. -func (x *XML) Print(module *tfconf.Module, settings *print.Settings) (string, error) { - copy := &tfconf.Module{ +func (x *XML) Print(module *terraform.Module, settings *print.Settings) (string, error) { + copy := &terraform.Module{ Header: "", - Inputs: make([]*tfconf.Input, 0), - Outputs: make([]*tfconf.Output, 0), - Providers: make([]*tfconf.Provider, 0), - Requirements: make([]*tfconf.Requirement, 0), + Inputs: make([]*terraform.Input, 0), + Outputs: make([]*terraform.Output, 0), + Providers: make([]*terraform.Provider, 0), + Requirements: make([]*terraform.Requirement, 0), } if settings.ShowHeader { diff --git a/internal/format/xml_test.go b/internal/format/xml_test.go index 2af0b2b..cc31ba6 100644 --- a/internal/format/xml_test.go +++ b/internal/format/xml_test.go @@ -5,7 +5,7 @@ import ( "github.com/stretchr/testify/assert" - "github.com/terraform-docs/terraform-docs/internal/module" + "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/internal/testutil" "github.com/terraform-docs/terraform-docs/pkg/print" ) @@ -17,7 +17,7 @@ func TestXml(t *testing.T) { expected, err := testutil.GetExpected("xml", "xml") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -37,8 +37,8 @@ func TestXmlSortByName(t *testing.T) { expected, err := testutil.GetExpected("xml", "xml-SortByName") assert.Nil(err) - options, err := module.NewOptions().With(&module.Options{ - SortBy: &module.SortBy{ + options, err := terraform.NewOptions().With(&terraform.Options{ + SortBy: &terraform.SortBy{ Name: true, }, }) @@ -64,8 +64,8 @@ func TestXmlSortByRequired(t *testing.T) { expected, err := testutil.GetExpected("xml", "xml-SortByRequired") assert.Nil(err) - options, err := module.NewOptions().With(&module.Options{ - SortBy: &module.SortBy{ + options, err := terraform.NewOptions().With(&terraform.Options{ + SortBy: &terraform.SortBy{ Name: true, Required: true, }, @@ -91,8 +91,8 @@ func TestXmlSortByType(t *testing.T) { expected, err := testutil.GetExpected("xml", "xml-SortByType") assert.Nil(err) - options, err := module.NewOptions().With(&module.Options{ - SortBy: &module.SortBy{ + options, err := terraform.NewOptions().With(&terraform.Options{ + SortBy: &terraform.SortBy{ Type: true, }, }) @@ -121,7 +121,7 @@ func TestXmlNoHeader(t *testing.T) { expected, err := testutil.GetExpected("xml", "xml-NoHeader") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -145,7 +145,7 @@ func TestXmlNoInputs(t *testing.T) { expected, err := testutil.GetExpected("xml", "xml-NoInputs") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -169,7 +169,7 @@ func TestXmlNoOutputs(t *testing.T) { expected, err := testutil.GetExpected("xml", "xml-NoOutputs") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -193,7 +193,7 @@ func TestXmlNoProviders(t *testing.T) { expected, err := testutil.GetExpected("xml", "xml-NoProviders") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -217,7 +217,7 @@ func TestXmlNoRequirements(t *testing.T) { expected, err := testutil.GetExpected("xml", "xml-NoRequirements") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -241,7 +241,7 @@ func TestXmlOnlyHeader(t *testing.T) { expected, err := testutil.GetExpected("xml", "xml-OnlyHeader") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -265,7 +265,7 @@ func TestXmlOnlyInputs(t *testing.T) { expected, err := testutil.GetExpected("xml", "xml-OnlyInputs") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -289,7 +289,7 @@ func TestXmlOnlyOutputs(t *testing.T) { expected, err := testutil.GetExpected("xml", "xml-OnlyOutputs") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -313,7 +313,7 @@ func TestXmlOnlyProviders(t *testing.T) { expected, err := testutil.GetExpected("xml", "xml-OnlyProviders") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -337,7 +337,7 @@ func TestXmlOnlyRequirements(t *testing.T) { expected, err := testutil.GetExpected("xml", "xml-OnlyRequirements") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -357,7 +357,7 @@ func TestXmlOutputValues(t *testing.T) { expected, err := testutil.GetExpected("xml", "xml-OutputValues") assert.Nil(err) - options, err := module.NewOptions().With(&module.Options{ + options, err := terraform.NewOptions().With(&terraform.Options{ OutputValues: true, OutputValuesPath: "output_values.json", }) @@ -408,7 +408,7 @@ func TestXmlHeaderFromFile(t *testing.T) { expected, err := testutil.GetExpected("xml", tt.golden) assert.Nil(err) - options, err := module.NewOptions().WithOverwrite(&module.Options{ + options, err := terraform.NewOptions().WithOverwrite(&terraform.Options{ HeaderFromFile: tt.file, }) assert.Nil(err) @@ -437,7 +437,7 @@ func TestXmlEmpty(t *testing.T) { expected, err := testutil.GetExpected("xml", "xml-Empty") assert.Nil(err) - options, err := module.NewOptions().WithOverwrite(&module.Options{ + options, err := terraform.NewOptions().WithOverwrite(&terraform.Options{ HeaderFromFile: "bad.tf", }) options.ShowHeader = false // Since we don't show the header, the file won't be loaded at all diff --git a/internal/format/yaml.go b/internal/format/yaml.go index 6e01678..755a856 100644 --- a/internal/format/yaml.go +++ b/internal/format/yaml.go @@ -6,8 +6,8 @@ import ( "gopkg.in/yaml.v3" + "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/pkg/print" - "github.com/terraform-docs/terraform-docs/pkg/tfconf" ) // YAML represents YAML format. @@ -19,13 +19,13 @@ func NewYAML(settings *print.Settings) *YAML { } // Print prints a Terraform module as yaml. -func (y *YAML) Print(module *tfconf.Module, settings *print.Settings) (string, error) { - copy := &tfconf.Module{ +func (y *YAML) Print(module *terraform.Module, settings *print.Settings) (string, error) { + copy := &terraform.Module{ Header: "", - Inputs: make([]*tfconf.Input, 0), - Outputs: make([]*tfconf.Output, 0), - Providers: make([]*tfconf.Provider, 0), - Requirements: make([]*tfconf.Requirement, 0), + Inputs: make([]*terraform.Input, 0), + Outputs: make([]*terraform.Output, 0), + Providers: make([]*terraform.Provider, 0), + Requirements: make([]*terraform.Requirement, 0), } if settings.ShowHeader { diff --git a/internal/format/yaml_test.go b/internal/format/yaml_test.go index b67bc16..6cdabfa 100644 --- a/internal/format/yaml_test.go +++ b/internal/format/yaml_test.go @@ -5,7 +5,7 @@ import ( "github.com/stretchr/testify/assert" - "github.com/terraform-docs/terraform-docs/internal/module" + "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/internal/testutil" "github.com/terraform-docs/terraform-docs/pkg/print" ) @@ -17,7 +17,7 @@ func TestYaml(t *testing.T) { expected, err := testutil.GetExpected("yaml", "yaml") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -37,8 +37,8 @@ func TestYamlSortByName(t *testing.T) { expected, err := testutil.GetExpected("yaml", "yaml-SortByName") assert.Nil(err) - options, err := module.NewOptions().With(&module.Options{ - SortBy: &module.SortBy{ + options, err := terraform.NewOptions().With(&terraform.Options{ + SortBy: &terraform.SortBy{ Name: true, }, }) @@ -64,8 +64,8 @@ func TestYamlSortByRequired(t *testing.T) { expected, err := testutil.GetExpected("yaml", "yaml-SortByRequired") assert.Nil(err) - options, err := module.NewOptions().With(&module.Options{ - SortBy: &module.SortBy{ + options, err := terraform.NewOptions().With(&terraform.Options{ + SortBy: &terraform.SortBy{ Name: true, Required: true, }, @@ -91,8 +91,8 @@ func TestYamlSortByType(t *testing.T) { expected, err := testutil.GetExpected("yaml", "yaml-SortByType") assert.Nil(err) - options, err := module.NewOptions().With(&module.Options{ - SortBy: &module.SortBy{ + options, err := terraform.NewOptions().With(&terraform.Options{ + SortBy: &terraform.SortBy{ Type: true, }, }) @@ -121,7 +121,7 @@ func TestYamlNoHeader(t *testing.T) { expected, err := testutil.GetExpected("yaml", "yaml-NoHeader") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -145,7 +145,7 @@ func TestYamlNoInputs(t *testing.T) { expected, err := testutil.GetExpected("yaml", "yaml-NoInputs") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -169,7 +169,7 @@ func TestYamlNoOutputs(t *testing.T) { expected, err := testutil.GetExpected("yaml", "yaml-NoOutputs") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -193,7 +193,7 @@ func TestYamlNoProviders(t *testing.T) { expected, err := testutil.GetExpected("yaml", "yaml-NoProviders") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -217,7 +217,7 @@ func TestYamlNoRequirements(t *testing.T) { expected, err := testutil.GetExpected("yaml", "yaml-NoRequirements") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -241,7 +241,7 @@ func TestYamlOnlyHeader(t *testing.T) { expected, err := testutil.GetExpected("yaml", "yaml-OnlyHeader") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -265,7 +265,7 @@ func TestYamlOnlyInputs(t *testing.T) { expected, err := testutil.GetExpected("yaml", "yaml-OnlyInputs") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -289,7 +289,7 @@ func TestYamlOnlyOutputs(t *testing.T) { expected, err := testutil.GetExpected("yaml", "yaml-OnlyOutputs") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -313,7 +313,7 @@ func TestYamlOnlyProviders(t *testing.T) { expected, err := testutil.GetExpected("yaml", "yaml-OnlyProviders") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -337,7 +337,7 @@ func TestYamlOnlyRequirements(t *testing.T) { expected, err := testutil.GetExpected("yaml", "yaml-OnlyRequirements") assert.Nil(err) - options := module.NewOptions() + options := terraform.NewOptions() module, err := testutil.GetModule(options) assert.Nil(err) @@ -357,7 +357,7 @@ func TestYamlOutputValues(t *testing.T) { expected, err := testutil.GetExpected("yaml", "yaml-OutputValues") assert.Nil(err) - options, err := module.NewOptions().With(&module.Options{ + options, err := terraform.NewOptions().With(&terraform.Options{ OutputValues: true, OutputValuesPath: "output_values.json", }) @@ -408,7 +408,7 @@ func TestYamlHeaderFromFile(t *testing.T) { expected, err := testutil.GetExpected("yaml", tt.golden) assert.Nil(err) - options, err := module.NewOptions().WithOverwrite(&module.Options{ + options, err := terraform.NewOptions().WithOverwrite(&terraform.Options{ HeaderFromFile: tt.file, }) assert.Nil(err) @@ -437,7 +437,7 @@ func TestYamlEmpty(t *testing.T) { expected, err := testutil.GetExpected("yaml", "yaml-Empty") assert.Nil(err) - options, err := module.NewOptions().WithOverwrite(&module.Options{ + options, err := terraform.NewOptions().WithOverwrite(&terraform.Options{ HeaderFromFile: "bad.tf", }) options.ShowHeader = false // Since we don't show the header, the file won't be loaded at all diff --git a/internal/module/input.go b/internal/module/input.go deleted file mode 100644 index 32c0a59..0000000 --- a/internal/module/input.go +++ /dev/null @@ -1,43 +0,0 @@ -package module - -import ( - "github.com/terraform-docs/terraform-docs/pkg/tfconf" -) - -type inputsSortedByName []*tfconf.Input - -func (a inputsSortedByName) Len() int { return len(a) } -func (a inputsSortedByName) Swap(i, j int) { a[i], a[j] = a[j], a[i] } -func (a inputsSortedByName) Less(i, j int) bool { - return a[i].Name < a[j].Name -} - -type inputsSortedByRequired []*tfconf.Input - -func (a inputsSortedByRequired) Len() int { return len(a) } -func (a inputsSortedByRequired) Swap(i, j int) { a[i], a[j] = a[j], a[i] } -func (a inputsSortedByRequired) Less(i, j int) bool { - if a[i].HasDefault() == a[j].HasDefault() { - return a[i].Name < a[j].Name - } - return !a[i].HasDefault() && a[j].HasDefault() -} - -type inputsSortedByPosition []*tfconf.Input - -func (a inputsSortedByPosition) Len() int { return len(a) } -func (a inputsSortedByPosition) Swap(i, j int) { a[i], a[j] = a[j], a[i] } -func (a inputsSortedByPosition) Less(i, j int) bool { - return a[i].Position.Filename < a[j].Position.Filename || a[i].Position.Line < a[j].Position.Line -} - -type inputsSortedByType []*tfconf.Input - -func (a inputsSortedByType) Len() int { return len(a) } -func (a inputsSortedByType) Swap(i, j int) { a[i], a[j] = a[j], a[i] } -func (a inputsSortedByType) Less(i, j int) bool { - if a[i].Type == a[j].Type { - return a[i].Name < a[j].Name - } - return a[i].Type < a[j].Type -} diff --git a/internal/module/input_test.go b/internal/module/input_test.go deleted file mode 100644 index f843472..0000000 --- a/internal/module/input_test.go +++ /dev/null @@ -1,112 +0,0 @@ -package module - -import ( - "sort" - "testing" - - "github.com/stretchr/testify/assert" - - "github.com/terraform-docs/terraform-docs/internal/types" - "github.com/terraform-docs/terraform-docs/pkg/tfconf" -) - -func TestInputsSortedByName(t *testing.T) { - assert := assert.New(t) - inputs := sampleInputs() - - sort.Sort(inputsSortedByName(inputs)) - - expected := []string{"a", "b", "c", "d", "e", "f"} - actual := make([]string, len(inputs)) - - for k, i := range inputs { - actual[k] = i.Name - } - - assert.Equal(expected, actual) -} - -func TestInputsSortedByRequired(t *testing.T) { - assert := assert.New(t) - inputs := sampleInputs() - - sort.Sort(inputsSortedByRequired(inputs)) - - expected := []string{"b", "d", "a", "c", "e", "f"} - actual := make([]string, len(inputs)) - - for k, i := range inputs { - actual[k] = i.Name - } - - assert.Equal(expected, actual) -} - -func TestInputsSortedByPosition(t *testing.T) { - assert := assert.New(t) - inputs := sampleInputs() - - sort.Sort(inputsSortedByPosition(inputs)) - - expected := []string{"a", "d", "e", "b", "c", "f"} - actual := make([]string, len(inputs)) - - for k, i := range inputs { - actual[k] = i.Name - } - - assert.Equal(expected, actual) -} - -func sampleInputs() []*tfconf.Input { - return []*tfconf.Input{ - { - Name: "e", - Type: types.String(""), - Description: types.String("description of e"), - Default: types.ValueOf(true), - Required: false, - Position: tfconf.Position{Filename: "foo/variables.tf", Line: 35}, - }, - { - Name: "a", - Type: types.String("string"), - Description: types.String(""), - Default: types.ValueOf("a"), - Required: false, - Position: tfconf.Position{Filename: "foo/variables.tf", Line: 10}, - }, - { - Name: "d", - Type: types.String("string"), - Description: types.String("description for d"), - Default: types.ValueOf(nil), - Required: true, - Position: tfconf.Position{Filename: "foo/variables.tf", Line: 23}, - }, - { - Name: "b", - Type: types.String("number"), - Description: types.String("description of b"), - Default: types.ValueOf(nil), - Required: true, - Position: tfconf.Position{Filename: "foo/variables.tf", Line: 42}, - }, - { - Name: "c", - Type: types.String("list"), - Description: types.String("description of c"), - Default: types.ValueOf("c"), - Required: false, - Position: tfconf.Position{Filename: "foo/variables.tf", Line: 51}, - }, - { - Name: "f", - Type: types.String("string"), - Description: types.String("description of f"), - Default: types.ValueOf(nil), - Required: false, - Position: tfconf.Position{Filename: "foo/variables.tf", Line: 59}, - }, - } -} diff --git a/internal/module/output.go b/internal/module/output.go deleted file mode 100644 index b62dee3..0000000 --- a/internal/module/output.go +++ /dev/null @@ -1,28 +0,0 @@ -package module - -import ( - "github.com/terraform-docs/terraform-docs/pkg/tfconf" -) - -// TerraformOutput is used for unmarshalling `terraform outputs --json` into -type TerraformOutput struct { - Sensitive bool `json:"sensitive"` - Type interface{} `json:"type"` - Value interface{} `json:"value"` -} - -type outputsSortedByName []*tfconf.Output - -func (a outputsSortedByName) Len() int { return len(a) } -func (a outputsSortedByName) Swap(i, j int) { a[i], a[j] = a[j], a[i] } -func (a outputsSortedByName) Less(i, j int) bool { - return a[i].Name < a[j].Name -} - -type outputsSortedByPosition []*tfconf.Output - -func (a outputsSortedByPosition) Len() int { return len(a) } -func (a outputsSortedByPosition) Swap(i, j int) { a[i], a[j] = a[j], a[i] } -func (a outputsSortedByPosition) Less(i, j int) bool { - return a[i].Position.Filename < a[j].Position.Filename || a[i].Position.Line < a[j].Position.Line -} diff --git a/internal/module/output_test.go b/internal/module/output_test.go deleted file mode 100644 index f2aaa04..0000000 --- a/internal/module/output_test.go +++ /dev/null @@ -1,78 +0,0 @@ -package module - -import ( - "sort" - "testing" - - "github.com/stretchr/testify/assert" - - "github.com/terraform-docs/terraform-docs/internal/types" - "github.com/terraform-docs/terraform-docs/pkg/tfconf" -) - -func TestOutputsSortedByName(t *testing.T) { - assert := assert.New(t) - outputs := sampleOutputs() - - sort.Sort(outputsSortedByName(outputs)) - - expected := []string{"a", "b", "c", "d", "e"} - actual := make([]string, len(outputs)) - - for k, o := range outputs { - actual[k] = o.Name - } - - assert.Equal(expected, actual) -} - -func TestOutputsSortedByPosition(t *testing.T) { - assert := assert.New(t) - outputs := sampleOutputs() - - sort.Sort(outputsSortedByPosition(outputs)) - - expected := []string{"d", "a", "e", "b", "c"} - actual := make([]string, len(outputs)) - - for k, o := range outputs { - actual[k] = o.Name - } - - assert.Equal(expected, actual) -} - -func sampleOutputs() []*tfconf.Output { - return []*tfconf.Output{ - { - Name: "a", - Description: types.String("description of a"), - Value: nil, - Position: tfconf.Position{Filename: "foo/outputs.tf", Line: 25}, - }, - { - Name: "d", - Description: types.String("description of d"), - Value: nil, - Position: tfconf.Position{Filename: "foo/outputs.tf", Line: 10}, - }, - { - Name: "e", - Description: types.String("description of e"), - Value: nil, - Position: tfconf.Position{Filename: "foo/outputs.tf", Line: 33}, - }, - { - Name: "b", - Description: types.String("description of b"), - Value: nil, - Position: tfconf.Position{Filename: "foo/outputs.tf", Line: 39}, - }, - { - Name: "c", - Description: types.String("description of c"), - Value: nil, - Position: tfconf.Position{Filename: "foo/outputs.tf", Line: 42}, - }, - } -} diff --git a/internal/module/provider.go b/internal/module/provider.go deleted file mode 100644 index a23c79a..0000000 --- a/internal/module/provider.go +++ /dev/null @@ -1,21 +0,0 @@ -package module - -import ( - "github.com/terraform-docs/terraform-docs/pkg/tfconf" -) - -type providersSortedByName []*tfconf.Provider - -func (a providersSortedByName) Len() int { return len(a) } -func (a providersSortedByName) Swap(i, j int) { a[i], a[j] = a[j], a[i] } -func (a providersSortedByName) Less(i, j int) bool { - return a[i].Name < a[j].Name || (a[i].Name == a[j].Name && a[i].Alias < a[j].Alias) -} - -type providersSortedByPosition []*tfconf.Provider - -func (a providersSortedByPosition) Len() int { return len(a) } -func (a providersSortedByPosition) Swap(i, j int) { a[i], a[j] = a[j], a[i] } -func (a providersSortedByPosition) Less(i, j int) bool { - return a[i].Position.Filename < a[j].Position.Filename || a[i].Position.Line < a[j].Position.Line -} diff --git a/internal/terraform/doc.go b/internal/terraform/doc.go new file mode 100644 index 0000000..d87ef35 --- /dev/null +++ b/internal/terraform/doc.go @@ -0,0 +1,2 @@ +// Package terraform is the representation of a Terraform Module +package terraform diff --git a/pkg/tfconf/input.go b/internal/terraform/input.go similarity index 52% rename from pkg/tfconf/input.go rename to internal/terraform/input.go index ee0e1d6..ef7c8e0 100644 --- a/pkg/tfconf/input.go +++ b/internal/terraform/input.go @@ -1,4 +1,4 @@ -package tfconf +package terraform import ( "bytes" @@ -44,3 +44,41 @@ func (i *Input) GetValue() string { func (i *Input) HasDefault() bool { return i.Default.HasDefault() || !i.Required } + +type inputsSortedByName []*Input + +func (a inputsSortedByName) Len() int { return len(a) } +func (a inputsSortedByName) Swap(i, j int) { a[i], a[j] = a[j], a[i] } +func (a inputsSortedByName) Less(i, j int) bool { + return a[i].Name < a[j].Name +} + +type inputsSortedByRequired []*Input + +func (a inputsSortedByRequired) Len() int { return len(a) } +func (a inputsSortedByRequired) Swap(i, j int) { a[i], a[j] = a[j], a[i] } +func (a inputsSortedByRequired) Less(i, j int) bool { + if a[i].HasDefault() == a[j].HasDefault() { + return a[i].Name < a[j].Name + } + return !a[i].HasDefault() && a[j].HasDefault() +} + +type inputsSortedByPosition []*Input + +func (a inputsSortedByPosition) Len() int { return len(a) } +func (a inputsSortedByPosition) Swap(i, j int) { a[i], a[j] = a[j], a[i] } +func (a inputsSortedByPosition) Less(i, j int) bool { + return a[i].Position.Filename < a[j].Position.Filename || a[i].Position.Line < a[j].Position.Line +} + +type inputsSortedByType []*Input + +func (a inputsSortedByType) Len() int { return len(a) } +func (a inputsSortedByType) Swap(i, j int) { a[i], a[j] = a[j], a[i] } +func (a inputsSortedByType) Less(i, j int) bool { + if a[i].Type == a[j].Type { + return a[i].Name < a[j].Name + } + return a[i].Type < a[j].Type +} diff --git a/pkg/tfconf/input_test.go b/internal/terraform/input_test.go similarity index 65% rename from pkg/tfconf/input_test.go rename to internal/terraform/input_test.go index 3858b63..0fa6e64 100644 --- a/pkg/tfconf/input_test.go +++ b/internal/terraform/input_test.go @@ -1,6 +1,7 @@ -package tfconf +package terraform import ( + "sort" "testing" "github.com/stretchr/testify/assert" @@ -199,3 +200,104 @@ func TestInputValue(t *testing.T) { }) } } + +func TestInputsSortedByName(t *testing.T) { + assert := assert.New(t) + inputs := sampleInputs() + + sort.Sort(inputsSortedByName(inputs)) + + expected := []string{"a", "b", "c", "d", "e", "f"} + actual := make([]string, len(inputs)) + + for k, i := range inputs { + actual[k] = i.Name + } + + assert.Equal(expected, actual) +} + +func TestInputsSortedByRequired(t *testing.T) { + assert := assert.New(t) + inputs := sampleInputs() + + sort.Sort(inputsSortedByRequired(inputs)) + + expected := []string{"b", "d", "a", "c", "e", "f"} + actual := make([]string, len(inputs)) + + for k, i := range inputs { + actual[k] = i.Name + } + + assert.Equal(expected, actual) +} + +func TestInputsSortedByPosition(t *testing.T) { + assert := assert.New(t) + inputs := sampleInputs() + + sort.Sort(inputsSortedByPosition(inputs)) + + expected := []string{"a", "d", "e", "b", "c", "f"} + actual := make([]string, len(inputs)) + + for k, i := range inputs { + actual[k] = i.Name + } + + assert.Equal(expected, actual) +} + +func sampleInputs() []*Input { + return []*Input{ + { + Name: "e", + Type: types.String(""), + Description: types.String("description of e"), + Default: types.ValueOf(true), + Required: false, + Position: Position{Filename: "foo/variables.tf", Line: 35}, + }, + { + Name: "a", + Type: types.String("string"), + Description: types.String(""), + Default: types.ValueOf("a"), + Required: false, + Position: Position{Filename: "foo/variables.tf", Line: 10}, + }, + { + Name: "d", + Type: types.String("string"), + Description: types.String("description for d"), + Default: types.ValueOf(nil), + Required: true, + Position: Position{Filename: "foo/variables.tf", Line: 23}, + }, + { + Name: "b", + Type: types.String("number"), + Description: types.String("description of b"), + Default: types.ValueOf(nil), + Required: true, + Position: Position{Filename: "foo/variables.tf", Line: 42}, + }, + { + Name: "c", + Type: types.String("list"), + Description: types.String("description of c"), + Default: types.ValueOf("c"), + Required: false, + Position: Position{Filename: "foo/variables.tf", Line: 51}, + }, + { + Name: "f", + Type: types.String("string"), + Description: types.String("description of f"), + Default: types.ValueOf(nil), + Required: false, + Position: Position{Filename: "foo/variables.tf", Line: 59}, + }, + } +} diff --git a/internal/module/module.go b/internal/terraform/module.go similarity index 73% rename from internal/module/module.go rename to internal/terraform/module.go index 94f3331..a4e5401 100644 --- a/internal/module/module.go +++ b/internal/terraform/module.go @@ -1,7 +1,8 @@ -package module +package terraform import ( "encoding/json" + "encoding/xml" "fmt" "io/ioutil" "os" @@ -14,12 +15,56 @@ import ( "github.com/terraform-docs/terraform-docs/internal/reader" "github.com/terraform-docs/terraform-docs/internal/types" - "github.com/terraform-docs/terraform-docs/pkg/tfconf" ) +// Module represents a Terraform module. It consists of +// +// - Header ('header' json key): Module header found in shape of multi line comments at the beginning of 'main.tf' +// - Inputs ('inputs' json key): List of input 'variables' extracted from the Terraform module .tf files +// - Outputs ('outputs' json key): List of 'outputs' extracted from Terraform module .tf files +// - Providers ('providers' json key): List of 'providers' extracted from resources used in Terraform module +// - Requirements ('header' json key): List of 'requirements' extracted from the Terraform module .tf files +type Module struct { + XMLName xml.Name `json:"-" toml:"-" xml:"module" yaml:"-"` + + Header string `json:"header" toml:"header" xml:"header" yaml:"header"` + Inputs []*Input `json:"inputs" toml:"inputs" xml:"inputs>input" yaml:"inputs"` + Outputs []*Output `json:"outputs" toml:"outputs" xml:"outputs>output" yaml:"outputs"` + Providers []*Provider `json:"providers" toml:"providers" xml:"providers>provider" yaml:"providers"` + Requirements []*Requirement `json:"requirements" toml:"requirements" xml:"requirements>requirement" yaml:"requirements"` + + RequiredInputs []*Input `json:"-" toml:"-" xml:"-" yaml:"-"` + OptionalInputs []*Input `json:"-" toml:"-" xml:"-" yaml:"-"` +} + +// HasHeader indicates if the module has header. +func (m *Module) HasHeader() bool { + return len(m.Header) > 0 +} + +// HasInputs indicates if the module has inputs. +func (m *Module) HasInputs() bool { + return len(m.Inputs) > 0 +} + +// HasOutputs indicates if the module has outputs. +func (m *Module) HasOutputs() bool { + return len(m.Outputs) > 0 +} + +// HasProviders indicates if the module has providers. +func (m *Module) HasProviders() bool { + return len(m.Providers) > 0 +} + +// HasRequirements indicates if the module has requirements. +func (m *Module) HasRequirements() bool { + return len(m.Requirements) > 0 +} + // LoadWithOptions returns new instance of Module with all the inputs and // outputs discovered from provided 'path' containing Terraform config -func LoadWithOptions(options *Options) (*tfconf.Module, error) { +func LoadWithOptions(options *Options) (*Module, error) { tfmodule, err := loadModule(options.Path) if err != nil { return nil, err @@ -40,7 +85,7 @@ func loadModule(path string) (*tfconfig.Module, error) { return module, nil } -func loadModuleItems(tfmodule *tfconfig.Module, options *Options) (*tfconf.Module, error) { +func loadModuleItems(tfmodule *tfconfig.Module, options *Options) (*Module, error) { header, err := loadHeader(options) if err != nil { return nil, err @@ -54,7 +99,7 @@ func loadModuleItems(tfmodule *tfconfig.Module, options *Options) (*tfconf.Modul providers := loadProviders(tfmodule) requirements := loadRequirements(tfmodule) - return &tfconf.Module{ + return &Module{ Header: header, Inputs: inputs, Outputs: outputs, @@ -134,10 +179,10 @@ func loadHeader(options *Options) (string, error) { return strings.Join(header, "\n"), nil } -func loadInputs(tfmodule *tfconfig.Module) ([]*tfconf.Input, []*tfconf.Input, []*tfconf.Input) { - var inputs = make([]*tfconf.Input, 0, len(tfmodule.Variables)) - var required = make([]*tfconf.Input, 0, len(tfmodule.Variables)) - var optional = make([]*tfconf.Input, 0, len(tfmodule.Variables)) +func loadInputs(tfmodule *tfconfig.Module) ([]*Input, []*Input, []*Input) { + var inputs = make([]*Input, 0, len(tfmodule.Variables)) + var required = make([]*Input, 0, len(tfmodule.Variables)) + var optional = make([]*Input, 0, len(tfmodule.Variables)) for _, input := range tfmodule.Variables { // convert CRLF to LF early on (https://github.com/terraform-docs/terraform-docs/issues/305) @@ -146,13 +191,13 @@ func loadInputs(tfmodule *tfconfig.Module) ([]*tfconf.Input, []*tfconf.Input, [] inputDescription = loadComments(input.Pos.Filename, input.Pos.Line) } - i := &tfconf.Input{ + i := &Input{ Name: input.Name, Type: types.TypeOf(input.Type, input.Default), Description: types.String(inputDescription), Default: types.ValueOf(input.Default), Required: input.Required, - Position: tfconf.Position{ + Position: Position{ Filename: input.Pos.Filename, Line: input.Pos.Line, }, @@ -168,9 +213,9 @@ func loadInputs(tfmodule *tfconfig.Module) ([]*tfconf.Input, []*tfconf.Input, [] return inputs, required, optional } -func loadOutputs(tfmodule *tfconfig.Module, options *Options) ([]*tfconf.Output, error) { - outputs := make([]*tfconf.Output, 0, len(tfmodule.Outputs)) - values := make(map[string]*TerraformOutput) +func loadOutputs(tfmodule *tfconfig.Module, options *Options) ([]*Output, error) { + outputs := make([]*Output, 0, len(tfmodule.Outputs)) + values := make(map[string]*output) if options.OutputValues { var err error values, err = loadOutputValues(options) @@ -183,10 +228,10 @@ func loadOutputs(tfmodule *tfconfig.Module, options *Options) ([]*tfconf.Output, if description == "" { description = loadComments(o.Pos.Filename, o.Pos.Line) } - output := &tfconf.Output{ + output := &Output{ Name: o.Name, Description: types.String(description), - Position: tfconf.Position{ + Position: Position{ Filename: o.Pos.Filename, Line: o.Pos.Line, }, @@ -205,7 +250,7 @@ func loadOutputs(tfmodule *tfconfig.Module, options *Options) ([]*tfconf.Output, return outputs, nil } -func loadOutputValues(options *Options) (map[string]*TerraformOutput, error) { +func loadOutputValues(options *Options) (map[string]*output, error) { var out []byte var err error if options.OutputValuesPath == "" { @@ -219,7 +264,7 @@ func loadOutputValues(options *Options) (map[string]*TerraformOutput, error) { return nil, fmt.Errorf("caught error while reading the terraform outputs file at %s: %v", options.OutputValuesPath, err) } } - var terraformOutputs map[string]*TerraformOutput + var terraformOutputs map[string]*output err = json.Unmarshal(out, &terraformOutputs) if err != nil { return nil, err @@ -227,9 +272,9 @@ func loadOutputValues(options *Options) (map[string]*TerraformOutput, error) { return terraformOutputs, err } -func loadProviders(tfmodule *tfconfig.Module) []*tfconf.Provider { +func loadProviders(tfmodule *tfconfig.Module) []*Provider { resources := []map[string]*tfconfig.Resource{tfmodule.ManagedResources, tfmodule.DataResources} - discovered := make(map[string]*tfconf.Provider) + discovered := make(map[string]*Provider) for _, resource := range resources { for _, r := range resource { var version = "" @@ -237,28 +282,28 @@ func loadProviders(tfmodule *tfconfig.Module) []*tfconf.Provider { version = strings.Join(rv.VersionConstraints, " ") } key := fmt.Sprintf("%s.%s", r.Provider.Name, r.Provider.Alias) - discovered[key] = &tfconf.Provider{ + discovered[key] = &Provider{ Name: r.Provider.Name, Alias: types.String(r.Provider.Alias), Version: types.String(version), - Position: tfconf.Position{ + Position: Position{ Filename: r.Pos.Filename, Line: r.Pos.Line, }, } } } - providers := make([]*tfconf.Provider, 0, len(discovered)) + providers := make([]*Provider, 0, len(discovered)) for _, provider := range discovered { providers = append(providers, provider) } return providers } -func loadRequirements(tfmodule *tfconfig.Module) []*tfconf.Requirement { - var requirements = make([]*tfconf.Requirement, 0) +func loadRequirements(tfmodule *tfconfig.Module) []*Requirement { + var requirements = make([]*Requirement, 0) for _, core := range tfmodule.RequiredCore { - requirements = append(requirements, &tfconf.Requirement{ + requirements = append(requirements, &Requirement{ Name: "terraform", Version: types.String(core), }) @@ -270,7 +315,7 @@ func loadRequirements(tfmodule *tfconfig.Module) []*tfconf.Requirement { sort.Strings(names) for _, name := range names { for _, version := range tfmodule.RequiredProviders[name].VersionConstraints { - requirements = append(requirements, &tfconf.Requirement{ + requirements = append(requirements, &Requirement{ Name: name, Version: types.String(version), }) @@ -301,7 +346,7 @@ func loadComments(filename string, lineNum int) string { return strings.Join(comment, " ") } -func sortItems(tfmodule *tfconf.Module, sortby *SortBy) { +func sortItems(tfmodule *Module, sortby *SortBy) { if sortby.Type { sort.Sort(inputsSortedByType(tfmodule.Inputs)) sort.Sort(inputsSortedByType(tfmodule.RequiredInputs)) diff --git a/internal/module/module_test.go b/internal/terraform/module_test.go similarity index 99% rename from internal/module/module_test.go rename to internal/terraform/module_test.go index 5d39b99..7c01f36 100644 --- a/internal/module/module_test.go +++ b/internal/terraform/module_test.go @@ -1,4 +1,4 @@ -package module +package terraform import ( "path/filepath" diff --git a/internal/module/options.go b/internal/terraform/options.go similarity index 98% rename from internal/module/options.go rename to internal/terraform/options.go index ce16246..637e237 100644 --- a/internal/module/options.go +++ b/internal/terraform/options.go @@ -1,4 +1,4 @@ -package module +package terraform import ( "errors" diff --git a/internal/module/options_test.go b/internal/terraform/options_test.go similarity index 99% rename from internal/module/options_test.go rename to internal/terraform/options_test.go index 7d7ff2a..739dd82 100644 --- a/internal/module/options_test.go +++ b/internal/terraform/options_test.go @@ -1,4 +1,4 @@ -package module +package terraform import ( "testing" diff --git a/pkg/tfconf/output.go b/internal/terraform/output.go similarity index 83% rename from pkg/tfconf/output.go rename to internal/terraform/output.go index 9de0210..2e51ff4 100644 --- a/pkg/tfconf/output.go +++ b/internal/terraform/output.go @@ -1,4 +1,4 @@ -package tfconf +package terraform import ( "bytes" @@ -114,3 +114,26 @@ func (o *Output) MarshalYAML() (interface{}, error) { o.Sensitive = false // explicitly make empty return *o, nil } + +// output is used for unmarshalling `terraform outputs --json` into +type output struct { + Sensitive bool `json:"sensitive"` + Type interface{} `json:"type"` + Value interface{} `json:"value"` +} + +type outputsSortedByName []*Output + +func (a outputsSortedByName) Len() int { return len(a) } +func (a outputsSortedByName) Swap(i, j int) { a[i], a[j] = a[j], a[i] } +func (a outputsSortedByName) Less(i, j int) bool { + return a[i].Name < a[j].Name +} + +type outputsSortedByPosition []*Output + +func (a outputsSortedByPosition) Len() int { return len(a) } +func (a outputsSortedByPosition) Swap(i, j int) { a[i], a[j] = a[j], a[i] } +func (a outputsSortedByPosition) Less(i, j int) bool { + return a[i].Position.Filename < a[j].Position.Filename || a[i].Position.Line < a[j].Position.Line +} diff --git a/pkg/tfconf/output_test.go b/internal/terraform/output_test.go similarity index 84% rename from pkg/tfconf/output_test.go rename to internal/terraform/output_test.go index 74a80b4..53665a0 100644 --- a/pkg/tfconf/output_test.go +++ b/internal/terraform/output_test.go @@ -1,9 +1,10 @@ -package tfconf +package terraform import ( "bytes" "encoding/xml" "reflect" + "sort" "testing" "github.com/stretchr/testify/assert" @@ -278,62 +279,62 @@ func TestOutputMarshalYAML(t *testing.T) { { name: "output marshal JSON", output: outputs[0], - expected: "tfconf.withvalue", + expected: "terraform.withvalue", }, { name: "output marshal JSON", output: outputs[1], - expected: "tfconf.Output", + expected: "terraform.Output", }, { name: "output marshal JSON", output: outputs[2], - expected: "tfconf.withvalue", + expected: "terraform.withvalue", }, { name: "output marshal JSON", output: outputs[3], - expected: "tfconf.withvalue", + expected: "terraform.withvalue", }, { name: "output marshal JSON", output: outputs[4], - expected: "tfconf.withvalue", + expected: "terraform.withvalue", }, { name: "output marshal JSON", output: outputs[5], - expected: "tfconf.Output", + expected: "terraform.Output", }, { name: "output marshal JSON", output: outputs[6], - expected: "tfconf.withvalue", + expected: "terraform.withvalue", }, { name: "output marshal JSON", output: outputs[7], - expected: "tfconf.withvalue", + expected: "terraform.withvalue", }, { name: "output marshal JSON", output: outputs[8], - expected: "tfconf.withvalue", + expected: "terraform.withvalue", }, { name: "output marshal JSON", output: outputs[9], - expected: "tfconf.withvalue", + expected: "terraform.withvalue", }, { name: "output marshal JSON", output: outputs[10], - expected: "tfconf.withvalue", + expected: "terraform.withvalue", }, { name: "output marshal JSON", output: outputs[11], - expected: "tfconf.withvalue", + expected: "terraform.withvalue", }, } for _, tt := range tests { @@ -448,3 +449,70 @@ func sampleOutputs() []Output { }, } } + +func TestOutputsSortedByName(t *testing.T) { + assert := assert.New(t) + outputs := sampleOutputsForSort() + + sort.Sort(outputsSortedByName(outputs)) + + expected := []string{"a", "b", "c", "d", "e"} + actual := make([]string, len(outputs)) + + for k, o := range outputs { + actual[k] = o.Name + } + + assert.Equal(expected, actual) +} + +func TestOutputsSortedByPosition(t *testing.T) { + assert := assert.New(t) + outputs := sampleOutputsForSort() + + sort.Sort(outputsSortedByPosition(outputs)) + + expected := []string{"d", "a", "e", "b", "c"} + actual := make([]string, len(outputs)) + + for k, o := range outputs { + actual[k] = o.Name + } + + assert.Equal(expected, actual) +} + +func sampleOutputsForSort() []*Output { + return []*Output{ + { + Name: "a", + Description: types.String("description of a"), + Value: nil, + Position: Position{Filename: "foo/outputs.tf", Line: 25}, + }, + { + Name: "d", + Description: types.String("description of d"), + Value: nil, + Position: Position{Filename: "foo/outputs.tf", Line: 10}, + }, + { + Name: "e", + Description: types.String("description of e"), + Value: nil, + Position: Position{Filename: "foo/outputs.tf", Line: 33}, + }, + { + Name: "b", + Description: types.String("description of b"), + Value: nil, + Position: Position{Filename: "foo/outputs.tf", Line: 39}, + }, + { + Name: "c", + Description: types.String("description of c"), + Value: nil, + Position: Position{Filename: "foo/outputs.tf", Line: 42}, + }, + } +} diff --git a/pkg/tfconf/position.go b/internal/terraform/position.go similarity index 91% rename from pkg/tfconf/position.go rename to internal/terraform/position.go index d48888b..fcb6775 100644 --- a/pkg/tfconf/position.go +++ b/internal/terraform/position.go @@ -1,4 +1,4 @@ -package tfconf +package terraform // Position represents position of Terraform input or output in a file. type Position struct { diff --git a/internal/terraform/provider.go b/internal/terraform/provider.go new file mode 100644 index 0000000..659e68b --- /dev/null +++ b/internal/terraform/provider.go @@ -0,0 +1,39 @@ +package terraform + +import ( + "fmt" + + "github.com/terraform-docs/terraform-docs/internal/types" +) + +// Provider represents a Terraform output. +type Provider struct { + Name string `json:"name" toml:"name" xml:"name" yaml:"name"` + Alias types.String `json:"alias" toml:"alias" xml:"alias" yaml:"alias"` + Version types.String `json:"version" toml:"version" xml:"version" yaml:"version"` + Position Position `json:"-" toml:"-" xml:"-" yaml:"-"` +} + +// FullName returns full name of the provider, with alias if available +func (p *Provider) FullName() string { + if p.Alias != "" { + return fmt.Sprintf("%s.%s", p.Name, p.Alias) + } + return p.Name +} + +type providersSortedByName []*Provider + +func (a providersSortedByName) Len() int { return len(a) } +func (a providersSortedByName) Swap(i, j int) { a[i], a[j] = a[j], a[i] } +func (a providersSortedByName) Less(i, j int) bool { + return a[i].Name < a[j].Name || (a[i].Name == a[j].Name && a[i].Alias < a[j].Alias) +} + +type providersSortedByPosition []*Provider + +func (a providersSortedByPosition) Len() int { return len(a) } +func (a providersSortedByPosition) Swap(i, j int) { a[i], a[j] = a[j], a[i] } +func (a providersSortedByPosition) Less(i, j int) bool { + return a[i].Position.Filename < a[j].Position.Filename || a[i].Position.Line < a[j].Position.Line +} diff --git a/internal/module/provider_test.go b/internal/terraform/provider_test.go similarity index 58% rename from internal/module/provider_test.go rename to internal/terraform/provider_test.go index 8444199..74bb40c 100644 --- a/internal/module/provider_test.go +++ b/internal/terraform/provider_test.go @@ -1,4 +1,4 @@ -package module +package terraform import ( "sort" @@ -7,9 +7,30 @@ import ( "github.com/stretchr/testify/assert" "github.com/terraform-docs/terraform-docs/internal/types" - "github.com/terraform-docs/terraform-docs/pkg/tfconf" ) +func TestProviderNameWithoutAlias(t *testing.T) { + assert := assert.New(t) + provider := Provider{ + Name: "provider", + Alias: types.String(""), + Version: types.String(">= 1.2.3"), + Position: Position{Filename: "foo.tf", Line: 13}, + } + assert.Equal("provider", provider.FullName()) +} + +func TestProviderNameWithAlias(t *testing.T) { + assert := assert.New(t) + provider := Provider{ + Name: "provider", + Alias: types.String("alias"), + Version: types.String(">= 1.2.3"), + Position: Position{Filename: "foo.tf", Line: 13}, + } + assert.Equal("provider.alias", provider.FullName()) +} + func TestProvidersSortedByName(t *testing.T) { assert := assert.New(t) providers := sampleProviders() @@ -42,49 +63,49 @@ func TestProvidersSortedByPosition(t *testing.T) { assert.Equal(expected, actual) } -func sampleProviders() []*tfconf.Provider { - return []*tfconf.Provider{ +func sampleProviders() []*Provider { + return []*Provider{ { Name: "d", Alias: types.String(""), Version: types.String("1.3.2"), - Position: tfconf.Position{Filename: "foo/main.tf", Line: 21}, + Position: Position{Filename: "foo/main.tf", Line: 21}, }, { Name: "d", Alias: types.String("a"), Version: types.String("> 1.x"), - Position: tfconf.Position{Filename: "foo/main.tf", Line: 25}, + Position: Position{Filename: "foo/main.tf", Line: 25}, }, { Name: "b", Alias: types.String(""), Version: types.String("= 2.1.0"), - Position: tfconf.Position{Filename: "foo/main.tf", Line: 13}, + Position: Position{Filename: "foo/main.tf", Line: 13}, }, { Name: "a", Alias: types.String(""), Version: types.String(""), - Position: tfconf.Position{Filename: "foo/main.tf", Line: 39}, + Position: Position{Filename: "foo/main.tf", Line: 39}, }, { Name: "c", Alias: types.String(""), Version: types.String("~> 0.5.0"), - Position: tfconf.Position{Filename: "foo/main.tf", Line: 53}, + Position: Position{Filename: "foo/main.tf", Line: 53}, }, { Name: "e", Alias: types.String(""), Version: types.String(""), - Position: tfconf.Position{Filename: "foo/main.tf", Line: 47}, + Position: Position{Filename: "foo/main.tf", Line: 47}, }, { Name: "e", Alias: types.String("a"), Version: types.String("> 1.0"), - Position: tfconf.Position{Filename: "foo/main.tf", Line: 5}, + Position: Position{Filename: "foo/main.tf", Line: 5}, }, } } diff --git a/pkg/tfconf/requirement.go b/internal/terraform/requirement.go similarity index 94% rename from pkg/tfconf/requirement.go rename to internal/terraform/requirement.go index f66730d..2abd303 100644 --- a/pkg/tfconf/requirement.go +++ b/internal/terraform/requirement.go @@ -1,4 +1,4 @@ -package tfconf +package terraform import ( "github.com/terraform-docs/terraform-docs/internal/types" diff --git a/internal/module/testdata/empty-header/main.tf b/internal/terraform/testdata/empty-header/main.tf similarity index 100% rename from internal/module/testdata/empty-header/main.tf rename to internal/terraform/testdata/empty-header/main.tf diff --git a/internal/module/testdata/full-example/doc.adoc b/internal/terraform/testdata/full-example/doc.adoc similarity index 100% rename from internal/module/testdata/full-example/doc.adoc rename to internal/terraform/testdata/full-example/doc.adoc diff --git a/internal/module/testdata/full-example/doc.md b/internal/terraform/testdata/full-example/doc.md similarity index 100% rename from internal/module/testdata/full-example/doc.md rename to internal/terraform/testdata/full-example/doc.md diff --git a/internal/module/testdata/full-example/doc.tf b/internal/terraform/testdata/full-example/doc.tf similarity index 100% rename from internal/module/testdata/full-example/doc.tf rename to internal/terraform/testdata/full-example/doc.tf diff --git a/internal/module/testdata/full-example/doc.txt b/internal/terraform/testdata/full-example/doc.txt similarity index 100% rename from internal/module/testdata/full-example/doc.txt rename to internal/terraform/testdata/full-example/doc.txt diff --git a/internal/module/testdata/full-example/main.tf b/internal/terraform/testdata/full-example/main.tf similarity index 100% rename from internal/module/testdata/full-example/main.tf rename to internal/terraform/testdata/full-example/main.tf diff --git a/internal/module/testdata/full-example/output-values.json b/internal/terraform/testdata/full-example/output-values.json similarity index 100% rename from internal/module/testdata/full-example/output-values.json rename to internal/terraform/testdata/full-example/output-values.json diff --git a/internal/module/testdata/full-example/outputs.tf b/internal/terraform/testdata/full-example/outputs.tf similarity index 100% rename from internal/module/testdata/full-example/outputs.tf rename to internal/terraform/testdata/full-example/outputs.tf diff --git a/internal/module/testdata/full-example/variables.tf b/internal/terraform/testdata/full-example/variables.tf similarity index 100% rename from internal/module/testdata/full-example/variables.tf rename to internal/terraform/testdata/full-example/variables.tf diff --git a/internal/module/testdata/inputs-crlf/variables.tf b/internal/terraform/testdata/inputs-crlf/variables.tf similarity index 100% rename from internal/module/testdata/inputs-crlf/variables.tf rename to internal/terraform/testdata/inputs-crlf/variables.tf diff --git a/internal/module/testdata/inputs-lf/variables.tf b/internal/terraform/testdata/inputs-lf/variables.tf similarity index 100% rename from internal/module/testdata/inputs-lf/variables.tf rename to internal/terraform/testdata/inputs-lf/variables.tf diff --git a/internal/module/testdata/no-inputs/variables.tf b/internal/terraform/testdata/no-inputs/variables.tf similarity index 100% rename from internal/module/testdata/no-inputs/variables.tf rename to internal/terraform/testdata/no-inputs/variables.tf diff --git a/internal/module/testdata/no-optional-inputs/variables.tf b/internal/terraform/testdata/no-optional-inputs/variables.tf similarity index 100% rename from internal/module/testdata/no-optional-inputs/variables.tf rename to internal/terraform/testdata/no-optional-inputs/variables.tf diff --git a/internal/module/testdata/no-outputs/outputs.tf b/internal/terraform/testdata/no-outputs/outputs.tf similarity index 100% rename from internal/module/testdata/no-outputs/outputs.tf rename to internal/terraform/testdata/no-outputs/outputs.tf diff --git a/internal/module/testdata/no-providers/main.tf b/internal/terraform/testdata/no-providers/main.tf similarity index 100% rename from internal/module/testdata/no-providers/main.tf rename to internal/terraform/testdata/no-providers/main.tf diff --git a/internal/module/testdata/no-required-inputs/variables.tf b/internal/terraform/testdata/no-required-inputs/variables.tf similarity index 100% rename from internal/module/testdata/no-required-inputs/variables.tf rename to internal/terraform/testdata/no-required-inputs/variables.tf diff --git a/internal/testutil/testing.go b/internal/testutil/testing.go index e5af735..720ee61 100644 --- a/internal/testutil/testing.go +++ b/internal/testutil/testing.go @@ -6,12 +6,11 @@ import ( "path/filepath" "runtime" - "github.com/terraform-docs/terraform-docs/internal/module" - "github.com/terraform-docs/terraform-docs/pkg/tfconf" + "github.com/terraform-docs/terraform-docs/internal/terraform" ) // GetModule returns 'example' Module -func GetModule(options *module.Options) (*tfconf.Module, error) { +func GetModule(options *terraform.Options) (*terraform.Module, error) { path, err := getExampleFolder() if err != nil { return nil, err @@ -20,7 +19,7 @@ func GetModule(options *module.Options) (*tfconf.Module, error) { if options.OutputValues { options.OutputValuesPath = filepath.Join(path, options.OutputValuesPath) } - tfmodule, err := module.LoadWithOptions(options) + tfmodule, err := terraform.LoadWithOptions(options) if err != nil { return nil, err } diff --git a/pkg/print/print.go b/pkg/print/print.go index a740a42..ac0a40f 100644 --- a/pkg/print/print.go +++ b/pkg/print/print.go @@ -1,10 +1,10 @@ package print import ( - "github.com/terraform-docs/terraform-docs/pkg/tfconf" + "github.com/terraform-docs/terraform-docs/internal/terraform" ) // Format represents a printer format (e.g. json, table, yaml, ...) type Format interface { - Print(*tfconf.Module, *Settings) (string, error) + Print(*terraform.Module, *Settings) (string, error) } diff --git a/pkg/tfconf/doc.go b/pkg/tfconf/doc.go deleted file mode 100644 index 089e108..0000000 --- a/pkg/tfconf/doc.go +++ /dev/null @@ -1,2 +0,0 @@ -// Package tfconf is the representation of a Terraform Module -package tfconf diff --git a/pkg/tfconf/module.go b/pkg/tfconf/module.go deleted file mode 100644 index 7b108c8..0000000 --- a/pkg/tfconf/module.go +++ /dev/null @@ -1,50 +0,0 @@ -package tfconf - -import ( - "encoding/xml" -) - -// Module represents a Terraform module. It consists of -// -// - Header ('header' json key): Module header found in shape of multi line comments at the beginning of 'main.tf' -// - Inputs ('inputs' json key): List of input 'variables' extracted from the Terraform module .tf files -// - Outputs ('outputs' json key): List of 'outputs' extracted from Terraform module .tf files -// - Providers ('providers' json key): List of 'providers' extracted from resources used in Terraform module -// - Requirements ('header' json key): List of 'requirements' extracted from the Terraform module .tf files -type Module struct { - XMLName xml.Name `json:"-" toml:"-" xml:"module" yaml:"-"` - - Header string `json:"header" toml:"header" xml:"header" yaml:"header"` - Inputs []*Input `json:"inputs" toml:"inputs" xml:"inputs>input" yaml:"inputs"` - Outputs []*Output `json:"outputs" toml:"outputs" xml:"outputs>output" yaml:"outputs"` - Providers []*Provider `json:"providers" toml:"providers" xml:"providers>provider" yaml:"providers"` - Requirements []*Requirement `json:"requirements" toml:"requirements" xml:"requirements>requirement" yaml:"requirements"` - - RequiredInputs []*Input `json:"-" toml:"-" xml:"-" yaml:"-"` - OptionalInputs []*Input `json:"-" toml:"-" xml:"-" yaml:"-"` -} - -// HasHeader indicates if the module has header. -func (m *Module) HasHeader() bool { - return len(m.Header) > 0 -} - -// HasInputs indicates if the module has inputs. -func (m *Module) HasInputs() bool { - return len(m.Inputs) > 0 -} - -// HasOutputs indicates if the module has outputs. -func (m *Module) HasOutputs() bool { - return len(m.Outputs) > 0 -} - -// HasProviders indicates if the module has providers. -func (m *Module) HasProviders() bool { - return len(m.Providers) > 0 -} - -// HasRequirements indicates if the module has requirements. -func (m *Module) HasRequirements() bool { - return len(m.Requirements) > 0 -} diff --git a/pkg/tfconf/provider.go b/pkg/tfconf/provider.go deleted file mode 100644 index 9bd29a5..0000000 --- a/pkg/tfconf/provider.go +++ /dev/null @@ -1,23 +0,0 @@ -package tfconf - -import ( - "fmt" - - "github.com/terraform-docs/terraform-docs/internal/types" -) - -// Provider represents a Terraform output. -type Provider struct { - Name string `json:"name" toml:"name" xml:"name" yaml:"name"` - Alias types.String `json:"alias" toml:"alias" xml:"alias" yaml:"alias"` - Version types.String `json:"version" toml:"version" xml:"version" yaml:"version"` - Position Position `json:"-" toml:"-" xml:"-" yaml:"-"` -} - -// FullName returns full name of the provider, with alias if available -func (p *Provider) FullName() string { - if p.Alias != "" { - return fmt.Sprintf("%s.%s", p.Name, p.Alias) - } - return p.Name -} diff --git a/pkg/tfconf/provider_test.go b/pkg/tfconf/provider_test.go deleted file mode 100644 index 2b94109..0000000 --- a/pkg/tfconf/provider_test.go +++ /dev/null @@ -1,31 +0,0 @@ -package tfconf - -import ( - "testing" - - "github.com/stretchr/testify/assert" - - "github.com/terraform-docs/terraform-docs/internal/types" -) - -func TestProviderNameWithoutAlias(t *testing.T) { - assert := assert.New(t) - provider := Provider{ - Name: "provider", - Alias: types.String(""), - Version: types.String(">= 1.2.3"), - Position: Position{Filename: "foo.tf", Line: 13}, - } - assert.Equal("provider", provider.FullName()) -} - -func TestProviderNameWithAlias(t *testing.T) { - assert := assert.New(t) - provider := Provider{ - Name: "provider", - Alias: types.String("alias"), - Version: types.String(">= 1.2.3"), - Position: Position{Filename: "foo.tf", Line: 13}, - } - assert.Equal("provider.alias", provider.FullName()) -} diff --git a/pkg/tmpl/template.go b/pkg/tmpl/template.go index 4f1a8f7..9c88755 100644 --- a/pkg/tmpl/template.go +++ b/pkg/tmpl/template.go @@ -6,9 +6,9 @@ import ( "strings" "text/template" + "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/internal/types" "github.com/terraform-docs/terraform-docs/pkg/print" - "github.com/terraform-docs/terraform-docs/pkg/tfconf" ) // Item represents a named templated which can reference @@ -57,7 +57,7 @@ func (t *Template) Settings(settings *print.Settings) { } // Render renders the Template with given Module struct -func (t *Template) Render(module *tfconf.Module) (string, error) { +func (t *Template) Render(module *terraform.Module) (string, error) { if len(t.Items) < 1 { return "", fmt.Errorf("base template not found") } @@ -74,7 +74,7 @@ func (t *Template) Render(module *tfconf.Module) (string, error) { template.Must(tt.Parse(normalize(item.Text))) } err := tmpl.ExecuteTemplate(&buffer, t.Items[0].Name, struct { - Module *tfconf.Module + Module *terraform.Module Settings *print.Settings }{ Module: module, diff --git a/pkg/tmpl/template_test.go b/pkg/tmpl/template_test.go index 2ee3c82..83716cc 100644 --- a/pkg/tmpl/template_test.go +++ b/pkg/tmpl/template_test.go @@ -10,9 +10,9 @@ import ( "github.com/stretchr/testify/assert" + "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/internal/types" "github.com/terraform-docs/terraform-docs/pkg/print" - "github.com/terraform-docs/terraform-docs/pkg/tfconf" ) func TestTemplateRender(t *testing.T) { @@ -26,7 +26,7 @@ func TestTemplateRender(t *testing.T) { return fmt.Sprintf("customized <<%s>>", s) }, } - module := &tfconf.Module{ + module := &terraform.Module{ Header: "sample header", } tests := []struct { diff --git a/scripts/docs/generate.go b/scripts/docs/generate.go index 842101c..15cf5b0 100644 --- a/scripts/docs/generate.go +++ b/scripts/docs/generate.go @@ -14,7 +14,7 @@ import ( "github.com/terraform-docs/terraform-docs/cmd" "github.com/terraform-docs/terraform-docs/internal/format" - "github.com/terraform-docs/terraform-docs/internal/module" + "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/pkg/print" ) @@ -148,11 +148,11 @@ func printExample(buf *bytes.Buffer, name string) error { settings := print.NewSettings() settings.ShowColor = false - options := &module.Options{ + options := &terraform.Options{ Path: "./examples", ShowHeader: true, HeaderFromFile: "main.tf", - SortBy: &module.SortBy{ + SortBy: &terraform.SortBy{ Name: settings.SortByName, Required: settings.SortByRequired, }, @@ -163,7 +163,7 @@ func printExample(buf *bytes.Buffer, name string) error { if err != nil { return err } - tfmodule, err := module.LoadWithOptions(options) + tfmodule, err := terraform.LoadWithOptions(options) if err != nil { log.Fatal(err) }