Skip to content

Commit

Permalink
Copy internal packages from Terraform v1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
wata727 committed Jun 28, 2021
1 parent c86fb4f commit 32d3b29
Show file tree
Hide file tree
Showing 247 changed files with 41,902 additions and 292 deletions.
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ prepare:
go run ./plugin/stub-generator

test: prepare
go test -timeout 5m $$(go list ./... | grep -v test-fixtures | grep -v stub-generator | grep -v integrationtest)
go test -timeout 5m $$(go list ./... | grep -v tflint/terraform | grep -v test-fixtures | grep -v stub-generator | grep -v integrationtest)

build:
mkdir -p dist
Expand All @@ -17,8 +17,7 @@ e2e: prepare install
go test -timeout 5m ./integrationtest/inspection ./integrationtest/langserver ./integrationtest/bundled ./integrationtest/init

lint:
go run golang.org/x/lint/golint --set_exit_status $$(go list ./...)
go vet ./...
go run golang.org/x/lint/golint --set_exit_status $$(go list ./... | grep -v tflint/terraform)

clean:
rm -rf dist/
Expand Down
4 changes: 2 additions & 2 deletions cmd/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import (
"github.com/fatih/color"
"github.com/golang/mock/gomock"
hcl "github.com/hashicorp/hcl/v2"
"github.com/hashicorp/terraform/configs"
"github.com/hashicorp/terraform/terraform"
"github.com/terraform-linters/tflint/rules"
"github.com/terraform-linters/tflint/terraform/configs"
"github.com/terraform-linters/tflint/terraform/terraform"
"github.com/terraform-linters/tflint/tflint"
)

Expand Down
19 changes: 18 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,26 @@ go 1.16

require (
github.com/Masterminds/semver/v3 v3.1.1
github.com/agext/levenshtein v1.2.2
github.com/apparentlymart/go-cidr v1.1.0
github.com/apparentlymart/go-versions v1.0.1
github.com/bmatcuk/doublestar v1.1.5
github.com/fatih/color v1.10.0
github.com/golang/mock v1.5.0
github.com/golang/protobuf v1.4.3 // indirect
github.com/google/go-cmp v0.5.6
github.com/google/go-github/v35 v35.2.0
github.com/google/uuid v1.2.0
github.com/gorilla/websocket v1.4.0 // indirect
github.com/hashicorp/errwrap v1.1.0
github.com/hashicorp/go-getter v1.5.3
github.com/hashicorp/go-multierror v1.1.1
github.com/hashicorp/go-plugin v1.4.1
github.com/hashicorp/go-uuid v1.0.1
github.com/hashicorp/go-version v1.3.0
github.com/hashicorp/hcl/v2 v2.10.0
github.com/hashicorp/logutils v1.0.0
github.com/hashicorp/terraform v0.15.3
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734
github.com/jessevdk/go-flags v1.5.0
github.com/jstemmer/go-junit-report v0.9.1
github.com/mattn/go-colorable v0.1.8
Expand All @@ -24,6 +34,13 @@ require (
github.com/terraform-linters/tflint-plugin-sdk v0.8.3-0.20210614125323-8364139f3745
github.com/terraform-linters/tflint-ruleset-aws v0.4.1
github.com/zclconf/go-cty v1.8.3
github.com/zclconf/go-cty-yaml v1.0.2
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a
golang.org/x/lint v0.0.0-20200302205851-738671d3881b
golang.org/x/mod v0.4.2
golang.org/x/net v0.0.0-20210326060303-6b1517762897
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf // indirect
golang.org/x/text v0.3.5
golang.org/x/tools v0.0.0-20201028111035-eafbe7b904eb // indirect
google.golang.org/api v0.34.0 // indirect
)
252 changes: 2 additions & 250 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion plugin/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package plugin

import (
hcl "github.com/hashicorp/hcl/v2"
tfconfigs "github.com/hashicorp/terraform/configs"
"github.com/terraform-linters/tflint-plugin-sdk/terraform/addrs"
"github.com/terraform-linters/tflint-plugin-sdk/terraform/configs"
"github.com/terraform-linters/tflint-plugin-sdk/terraform/experiments"
tfplugin "github.com/terraform-linters/tflint-plugin-sdk/tflint/client"
tfconfigs "github.com/terraform-linters/tflint/terraform/configs"
"github.com/terraform-linters/tflint/tflint"
"github.com/zclconf/go-cty/cty/json"
"github.com/zclconf/go-cty/cty/msgpack"
Expand Down
2 changes: 1 addition & 1 deletion plugin/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package plugin
import (
hcl "github.com/hashicorp/hcl/v2"
"github.com/hashicorp/hcl/v2/hclsyntax"
"github.com/hashicorp/terraform/configs"
client "github.com/terraform-linters/tflint-plugin-sdk/tflint"
tfplugin "github.com/terraform-linters/tflint-plugin-sdk/tflint/client"
"github.com/terraform-linters/tflint/terraform/configs"
"github.com/terraform-linters/tflint/tflint"
)

Expand Down
2 changes: 1 addition & 1 deletion rules/terraformrules/terraform_module_pinned_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/Masterminds/semver/v3"
"github.com/hashicorp/go-getter"

"github.com/hashicorp/terraform/configs"
"github.com/terraform-linters/tflint/terraform/configs"
"github.com/terraform-linters/tflint/tflint"
)

Expand Down
6 changes: 3 additions & 3 deletions rules/terraformrules/terraform_unused_declaration.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"log"

"github.com/hashicorp/hcl/v2"
"github.com/hashicorp/terraform/addrs"
"github.com/hashicorp/terraform/configs"
"github.com/hashicorp/terraform/lang"
"github.com/terraform-linters/tflint/terraform/addrs"
"github.com/terraform-linters/tflint/terraform/configs"
"github.com/terraform-linters/tflint/terraform/lang"
"github.com/terraform-linters/tflint/tflint"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"log"

"github.com/hashicorp/terraform/configs"
"github.com/terraform-linters/tflint/terraform/configs"
"github.com/terraform-linters/tflint/tflint"
)

Expand Down
4 changes: 2 additions & 2 deletions rules/terraformrules/terraform_workspace_remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"log"

"github.com/hashicorp/hcl/v2"
"github.com/hashicorp/terraform/addrs"
"github.com/hashicorp/terraform/lang"
"github.com/terraform-linters/tflint/terraform/addrs"
"github.com/terraform-linters/tflint/terraform/lang"
"github.com/terraform-linters/tflint/tflint"
)

Expand Down
148 changes: 148 additions & 0 deletions terraform/addrs/addrs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
package addrs

import (
"strings"
)

// Module is an address for a module call within configuration. This is
// the static counterpart of ModuleInstance, representing a traversal through
// the static module call tree in configuration and does not take into account
// the potentially-multiple instances of a module that might be created by
// "count" and "for_each" arguments within those calls.
//
// This type should be used only in very specialized cases when working with
// the static module call tree. Type ModuleInstance is appropriate in more cases.
//
// Although Module is a slice, it should be treated as immutable after creation.
type Module []string

// RootModule is the module address representing the root of the static module
// call tree, which is also the zero value of Module.
//
// Note that this is not the root of the dynamic module tree, which is instead
// represented by RootModuleInstance.
var RootModule Module

// IsRoot returns true if the receiver is the address of the root module,
// or false otherwise.
func (m Module) IsRoot() bool {
return len(m) == 0
}

func (m Module) String() string {
if len(m) == 0 {
return ""
}
var steps []string
for _, s := range m {
steps = append(steps, "module", s)
}
return strings.Join(steps, ".")
}

func (m Module) Equal(other Module) bool {
if len(m) != len(other) {
return false
}
for i := range m {
if m[i] != other[i] {
return false
}
}
return true
}

func (m Module) targetableSigil() {
// Module is targetable
}

// TargetContains implements Targetable for Module by returning true if the given other
// address either matches the receiver, is a sub-module-instance of the
// receiver, or is a targetable absolute address within a module that
// is contained within the receiver.
func (m Module) TargetContains(other Targetable) bool {
switch to := other.(type) {

case Module:
if len(to) < len(m) {
// Can't be contained if the path is shorter
return false
}
// Other is contained if its steps match for the length of our own path.
for i, ourStep := range m {
otherStep := to[i]
if ourStep != otherStep {
return false
}
}
// If we fall out here then the prefixed matched, so it's contained.
return true

case ModuleInstance:
return m.TargetContains(to.Module())

case ConfigResource:
return m.TargetContains(to.Module)

case AbsResource:
return m.TargetContains(to.Module)

case AbsResourceInstance:
return m.TargetContains(to.Module)

default:
return false
}
}

// Child returns the address of a child call in the receiver, identified by the
// given name.
func (m Module) Child(name string) Module {
ret := make(Module, 0, len(m)+1)
ret = append(ret, m...)
return append(ret, name)
}

// Parent returns the address of the parent module of the receiver, or the
// receiver itself if there is no parent (if it's the root module address).
func (m Module) Parent() Module {
if len(m) == 0 {
return m
}
return m[:len(m)-1]
}

// Call returns the module call address that corresponds to the given module
// instance, along with the address of the module that contains it.
//
// There is no call for the root module, so this method will panic if called
// on the root module address.
//
// In practice, this just turns the last element of the receiver into a
// ModuleCall and then returns a slice of the receiever that excludes that
// last part. This is just a convenience for situations where a call address
// is required, such as when dealing with *Reference and Referencable values.
func (m Module) Call() (Module, ModuleCall) {
if len(m) == 0 {
panic("cannot produce ModuleCall for root module")
}

caller, callName := m[:len(m)-1], m[len(m)-1]
return caller, ModuleCall{
Name: callName,
}
}

// Ancestors returns a slice containing the receiver and all of its ancestor
// modules, all the way up to (and including) the root module. The result is
// ordered by depth, with the root module always first.
//
// Since the result always includes the root module, a caller may choose to
// ignore it by slicing the result with [1:].
func (m Module) Ancestors() []Module {
ret := make([]Module, 0, len(m)+1)
for i := 0; i <= len(m); i++ {
ret = append(ret, m[:i])
}
return ret
}
12 changes: 12 additions & 0 deletions terraform/addrs/count_attr.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package addrs

// CountAttr is the address of an attribute of the "count" object in
// the interpolation scope, like "count.index".
type CountAttr struct {
referenceable
Name string
}

func (ca CountAttr) String() string {
return "count." + ca.Name
}
12 changes: 12 additions & 0 deletions terraform/addrs/for_each_attr.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package addrs

// ForEachAttr is the address of an attribute referencing the current "for_each" object in
// the interpolation scope, addressed using the "each" keyword, ex. "each.key" and "each.value"
type ForEachAttr struct {
referenceable
Name string
}

func (f ForEachAttr) String() string {
return "each." + f.Name
}
50 changes: 50 additions & 0 deletions terraform/addrs/input_variable.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package addrs

import (
"fmt"
)

// InputVariable is the address of an input variable.
type InputVariable struct {
referenceable
Name string
}

func (v InputVariable) String() string {
return "var." + v.Name
}

// Absolute converts the receiver into an absolute address within the given
// module instance.
func (v InputVariable) Absolute(m ModuleInstance) AbsInputVariableInstance {
return AbsInputVariableInstance{
Module: m,
Variable: v,
}
}

// AbsInputVariableInstance is the address of an input variable within a
// particular module instance.
type AbsInputVariableInstance struct {
Module ModuleInstance
Variable InputVariable
}

// InputVariable returns the absolute address of the input variable of the
// given name inside the receiving module instance.
func (m ModuleInstance) InputVariable(name string) AbsInputVariableInstance {
return AbsInputVariableInstance{
Module: m,
Variable: InputVariable{
Name: name,
},
}
}

func (v AbsInputVariableInstance) String() string {
if len(v.Module) == 0 {
return v.Variable.String()
}

return fmt.Sprintf("%s.%s", v.Module.String(), v.Variable.String())
}
Loading

0 comments on commit 32d3b29

Please sign in to comment.