Skip to content

Commit

Permalink
Merge pull request #14 from minamijoyo/tf-0.12-beta2
Browse files Browse the repository at this point in the history
Terraform v0.12 support
  • Loading branch information
minamijoyo committed May 9, 2019
2 parents d942a18 + 47c30c9 commit 1211586
Show file tree
Hide file tree
Showing 19 changed files with 812 additions and 264 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

A schema inspector for Terraform providers.

NOTICE: The master branch may be broken due to development for Terraform v0.12 support.

# Features

- Get resource type definitions dynamically from Terraform providers via go-plugin protocol.
- List available resource types.
- Autocomplete resource types in bash/zsh.
- Open official provider documents quickly by your system web browser.
- Terraform v0.11/v0.12 support

![demo](/images/tfschema-demo.gif)

Expand Down
21 changes: 8 additions & 13 deletions command/autocomplete.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ func (m *Meta) completePredictResourceType() complete.Predictor {
return nil
}

defer client.Kill()
defer client.Close()

res := client.Resources()

resourceTypes := []string{}
for _, r := range res {
resourceTypes = append(resourceTypes, r.Name)
resourceTypes, err := client.ResourceTypes()
if err != nil {
return nil
}

return resourceTypes
Expand All @@ -47,16 +45,13 @@ func (m *Meta) completePredictDataSource() complete.Predictor {
return nil
}

defer client.Kill()

res := client.DataSources()
defer client.Close()

dataSources := []string{}
for _, r := range res {
dataSources = append(dataSources, r.Name)
dataSources, err := client.DataSources()
if err != nil {
return nil
}

return dataSources

})
}
11 changes: 5 additions & 6 deletions command/data_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,12 @@ func (c *DataListCommand) Run(args []string) int {
return 1
}

defer client.Kill()
defer client.Close()

res := client.DataSources()

dataSources := []string{}
for _, r := range res {
dataSources = append(dataSources, r.Name)
dataSources, err := client.DataSources()
if err != nil {
c.UI.Error(err.Error())
return 1
}

c.UI.Output(strings.Join(dataSources, "\n"))
Expand Down
2 changes: 1 addition & 1 deletion command/data_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (c *DataShowCommand) Run(args []string) int {
return 1
}

defer client.Kill()
defer client.Close()

block, err := client.GetDataSourceSchema(dataSource)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion command/provider_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (c *ProviderShowCommand) Run(args []string) int {
return 1
}

defer client.Kill()
defer client.Close()

block, err := client.GetProviderSchema()
if err != nil {
Expand Down
11 changes: 5 additions & 6 deletions command/resource_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,12 @@ func (c *ResourceListCommand) Run(args []string) int {
return 1
}

defer client.Kill()
defer client.Close()

res := client.Resources()

resourceTypes := []string{}
for _, r := range res {
resourceTypes = append(resourceTypes, r.Name)
resourceTypes, err := client.ResourceTypes()
if err != nil {
c.UI.Error(err.Error())
return 1
}

c.UI.Output(strings.Join(resourceTypes, "\n"))
Expand Down
2 changes: 1 addition & 1 deletion command/resource_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (c *ResourceShowCommand) Run(args []string) int {
return 1
}

defer client.Kill()
defer client.Close()

block, err := client.GetResourceTypeSchema(resourceType)
if err != nil {
Expand Down
5 changes: 1 addition & 4 deletions formatter/json/attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ type Attribute struct {
Name string `json:"name"`

// Type is a type of the attribute's value.
// Note that Type is not cty.Type
// We cannot import github.com/hashicorp/terraform/vendor/github.com/zclconf/go-cty/cty
// On the other hand, tfschema does not need a dynamic type.
// So, we use a simple representation of type defined in tfschema package.
// Note that Type is not cty.Type to customize string representation.
Type tfschema.Type `json:"type"`
// Required is a flag whether this attribute is required.
Required bool `json:"required"`
Expand Down
2 changes: 1 addition & 1 deletion formatter/json/nested_block.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package json

import (
"github.com/hashicorp/terraform/config/configschema"
"github.com/hashicorp/terraform/configs/configschema"
"github.com/minamijoyo/tfschema/tfschema"
)

Expand Down
51 changes: 10 additions & 41 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,21 @@ module github.com/minamijoyo/tfschema
go 1.12

require (
github.com/agext/levenshtein v1.2.1 // indirect
github.com/apparentlymart/go-cidr v0.0.0-20170616213631-2bd8b58cf427 // indirect
github.com/apparentlymart/go-textseg v0.0.0-20170531203952-b836f5c4d331 // indirect
github.com/armon/go-radix v0.0.0-20170727155443-1fca145dffbc // indirect
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
github.com/bgentry/speakeasy v0.1.0 // indirect
github.com/blang/semver v0.0.0-20170202183821-4a1e882c79dc // indirect
github.com/go-test/deep v1.0.1 // indirect
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b // indirect
github.com/aws/aws-sdk-go v1.19.19 // indirect
github.com/goreleaser/goreleaser v0.106.0
github.com/hashicorp/errwrap v0.0.0-20141028054710-7554cd9344ce // indirect
github.com/hashicorp/go-cleanhttp v0.0.0-20171130225243-06c9ea3a335b // indirect
github.com/hashicorp/go-getter v0.0.0-20180327010114-90bb99a48d86 // indirect
github.com/hashicorp/go-hclog v0.0.0-20170716174523-b4e5765d1e5f // indirect
github.com/hashicorp/go-multierror v0.0.0-20180717150148-3d5d8f294aa0 // indirect
github.com/hashicorp/go-plugin v0.0.0-20180125190438-e53f54cbf51e // indirect
github.com/hashicorp/go-safetemp v0.0.0-20180326211150-b1a1dbde6fdc // indirect
github.com/hashicorp/go-uuid v0.0.0-20160120003506-36289988d83c // indirect
github.com/hashicorp/go-version v0.0.0-20171129150820-4fe82ae3040f // indirect
github.com/hashicorp/hcl v0.0.0-20170504190234-a4b07c25de5f // indirect
github.com/hashicorp/hcl2 v0.0.0-20180308163058-5f8ed954abd8 // indirect
github.com/hashicorp/hil v0.0.0-20170627220502-fa9f258a9250 // indirect
github.com/hashicorp/logutils v0.0.0-20150609070431-0dc08b1671f3
github.com/hashicorp/terraform v0.11.7
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb // indirect
github.com/kardianos/osext v0.0.0-20170510131534-ae77be60afb1 // indirect
github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348 // indirect
github.com/mattn/go-runewidth v0.0.2 // indirect
github.com/mitchellh/cli v0.0.0-20180414170447-c48282d14eba
github.com/mitchellh/copystructure v0.0.0-20170525013902-d23ffcb85de3 // indirect
github.com/hashicorp/go-hclog v0.0.0-20181001195459-61d530d6c27f
github.com/hashicorp/go-plugin v0.0.0-20190322172744-52e1c4730856
github.com/hashicorp/logutils v1.0.0
github.com/hashicorp/terraform v0.12.0-beta2
github.com/mitchellh/cli v1.0.0
github.com/mitchellh/go-homedir v1.0.0
github.com/mitchellh/go-testing-interface v0.0.0-20171004221916-a61a99592b77 // indirect
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 // indirect
github.com/mitchellh/hashstructure v0.0.0-20160209213820-6b17d669fac5 // indirect
github.com/mitchellh/mapstructure v0.0.0-20170307201123-53818660ed49 // indirect
github.com/mitchellh/panicwrap v0.0.0-20170106182340-fce601fe5557
github.com/mitchellh/reflectwalk v0.0.0-20170726202117-63d60e9d0dbc // indirect
github.com/oklog/run v1.0.0 // indirect
github.com/mitchellh/panicwrap v0.0.0-20190213213626-17011010aaa4
github.com/olekukonko/tablewriter v0.0.0-20180506121414-d4647c9c7a84
github.com/pkg/browser v0.0.0-20170505125900-c90ca0c84f15
github.com/posener/complete v1.1.1
github.com/ulikunitz/xz v0.5.4 // indirect
github.com/zclconf/go-cty v0.0.0-20180718220526-02bd58e97b57 // indirect
github.com/posener/complete v1.2.1
github.com/zclconf/go-cty v0.0.0-20190320224746-fd76348b9329
golang.org/x/lint v0.0.0-20190409202823-959b441ac422
golang.org/x/oauth2 v0.0.0-20190402181905-9f3314589c9a // indirect
golang.org/x/sync v0.0.0-20190423024810-112230192c58 // indirect
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384 // indirect
google.golang.org/genproto v0.0.0-20180726180014-2a72893556e4 // indirect
google.golang.org/grpc v1.13.0 // indirect
)

0 comments on commit 1211586

Please sign in to comment.