Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaozhu36 authored Nov 21, 2018
2 parents 2c4ece8 + 7d5db95 commit a59308f
Show file tree
Hide file tree
Showing 331 changed files with 21,888 additions and 6,444 deletions.
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ go:
# add TF_ETCDV3_TEST=1 to run etcdv3 tests
# if added, TF_ETCDV3_ENDPOINTS must be set to a comma-separated list of (insecure) etcd endpoints against which to test
env:
- CONSUL_VERSION=0.7.5 GOMAXPROCS=4
- CONSUL_VERSION=0.7.5 GOMAXPROCS=4 GO111MODULE=on

# Fetch consul for the backend and provider tests
before_install:
Expand All @@ -36,8 +36,9 @@ script:
- make vendor-status
- make test
- make e2etest
- GOOS=windows go build
- make website-test
- GOOS=windows go build -mod=vendor
# website-test is temporarily disabled while we get the website build back in shape after the v0.12 reorganization
#- make website-test

branches:
only:
Expand Down
3,278 changes: 29 additions & 3,249 deletions CHANGELOG.md

Large diffs are not rendered by default.

35 changes: 19 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ WEBSITE_REPO=github.com/hashicorp/terraform-website
default: test

tools:
go get -u github.com/kardianos/govendor
go get -u golang.org/x/tools/cmd/stringer
go get -u golang.org/x/tools/cmd/cover
go get -u github.com/golang/mock/mockgen
GO111MODULE=off go get -u github.com/kardianos/govendor
GO111MODULE=off go get -u golang.org/x/tools/cmd/stringer
GO111MODULE=off go get -u golang.org/x/tools/cmd/cover
GO111MODULE=off go get -u github.com/golang/mock/mockgen

# bin generates the releaseable binaries for Terraform
bin: fmtcheck generate
Expand All @@ -18,10 +18,10 @@ bin: fmtcheck generate
# dev creates binaries for testing Terraform locally. These are put
# into ./bin/ as well as $GOPATH/bin
dev: fmtcheck generate
@TF_DEV=1 sh -c "'$(CURDIR)/scripts/build.sh'"
go install -mod=vendor .

quickdev: generate
@TF_DEV=1 sh -c "'$(CURDIR)/scripts/build.sh'"
go install -mod=vendor .

# Shorthand for building and installing just one plugin for local testing.
# Run as (for example): make plugin-dev PLUGIN=provider-aws
Expand All @@ -33,34 +33,34 @@ plugin-dev: generate
# we run this one package at a time here because running the entire suite in
# one command creates memory usage issues when running in Travis-CI.
test: fmtcheck generate
go list $(TEST) | xargs -t -n4 go test $(TESTARGS) -timeout=2m -parallel=4
go list -mod=vendor $(TEST) | xargs -t -n4 go test $(TESTARGS) -mod=vendor -timeout=2m -parallel=4

# testacc runs acceptance tests
testacc: fmtcheck generate
@if [ "$(TEST)" = "./..." ]; then \
echo "ERROR: Set TEST to a specific package. For example,"; \
echo " make testacc TEST=./builtin/providers/aws"; \
echo " make testacc TEST=./builtin/providers/test"; \
exit 1; \
fi
TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 120m
TF_ACC=1 go test $(TEST) -v $(TESTARGS) -mod=vendor -timeout 120m

# e2etest runs the end-to-end tests against a generated Terraform binary
# The TF_ACC here allows network access, but does not require any special
# credentials since the e2etests use local-only providers such as "null".
e2etest: generate
TF_ACC=1 go test -v ./command/e2etest
TF_ACC=1 go test -mod=vendor -v ./command/e2etest

test-compile: fmtcheck generate
@if [ "$(TEST)" = "./..." ]; then \
echo "ERROR: Set TEST to a specific package. For example,"; \
echo " make test-compile TEST=./builtin/providers/aws"; \
echo " make test-compile TEST=./builtin/providers/test"; \
exit 1; \
fi
go test -c $(TEST) $(TESTARGS)

# testrace runs the race checker
testrace: fmtcheck generate
TF_ACC= go test -race $(TEST) $(TESTARGS)
TF_ACC= go test -mod=vendor -race $(TEST) $(TESTARGS)

cover:
@go tool cover 2>/dev/null; if [ $$? -eq 3 ]; then \
Expand All @@ -75,10 +75,13 @@ cover:
# "make protobuf".
generate:
@which stringer > /dev/null; if [ $$? -ne 0 ]; then \
go get -u golang.org/x/tools/cmd/stringer; \
GO111MODULE=off go get -u golang.org/x/tools/cmd/stringer; \
fi
go generate ./...
@go fmt command/internal_plugin_list.go > /dev/null
# We turn off modules for "go generate" because our downstream generate
# commands are not all ready to deal with Go modules yet, and this
# avoids downloading all of the deps that are in the vendor dir anyway.
GO111MODULE=off go generate ./...
GO111MODULE=off go fmt command/internal_plugin_list.go > /dev/null

# We separate the protobuf generation because most development tasks on
# Terraform do not involve changing protobuf files and protoc is not a
Expand All @@ -87,7 +90,7 @@ generate:
# If you are working on changes to protobuf interfaces you may either use
# this target or run the individual scripts below directly.
protobuf:
bash plugin/proto/generate.sh
bash internal/tfplugin5/generate.sh
bash plans/internal/planproto/generate.sh

fmt:
Expand Down
11 changes: 8 additions & 3 deletions backend/atlas/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ type Backend struct {

var _ backend.Backend = (*Backend)(nil)

// New returns a new initialized Atlas backend.
func New() *Backend {
return &Backend{}
}

func (b *Backend) ConfigSchema() *configschema.Block {
return &configschema.Block{
Attributes: map[string]*configschema.Attribute{
Expand Down Expand Up @@ -163,16 +168,16 @@ func (b *Backend) Configure(obj cty.Value) tfdiags.Diagnostics {
}

func (b *Backend) Workspaces() ([]string, error) {
return nil, backend.ErrNamedStatesNotSupported
return nil, backend.ErrWorkspacesNotSupported
}

func (b *Backend) DeleteWorkspace(name string) error {
return backend.ErrNamedStatesNotSupported
return backend.ErrWorkspacesNotSupported
}

func (b *Backend) StateMgr(name string) (state.State, error) {
if name != backend.DefaultStateName {
return nil, backend.ErrNamedStatesNotSupported
return nil, backend.ErrWorkspacesNotSupported
}

return &remote.State{Client: b.stateClient}, nil
Expand Down
4 changes: 2 additions & 2 deletions backend/atlas/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestConfigure_envAddr(t *testing.T) {
defer os.Setenv("ATLAS_ADDRESS", os.Getenv("ATLAS_ADDRESS"))
os.Setenv("ATLAS_ADDRESS", "http://foo.com")

b := &Backend{}
b := New()
diags := b.Configure(cty.ObjectVal(map[string]cty.Value{
"name": cty.StringVal("foo/bar"),
"address": cty.NullVal(cty.String),
Expand All @@ -37,7 +37,7 @@ func TestConfigure_envToken(t *testing.T) {
defer os.Setenv("ATLAS_TOKEN", os.Getenv("ATLAS_TOKEN"))
os.Setenv("ATLAS_TOKEN", "foo")

b := &Backend{}
b := New()
diags := b.Configure(cty.ObjectVal(map[string]cty.Value{
"name": cty.StringVal("foo/bar"),
"address": cty.NullVal(cty.String),
Expand Down
7 changes: 3 additions & 4 deletions backend/atlas/state_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package atlas

import (
"bytes"
"context"
"crypto/md5"
"crypto/tls"
"crypto/x509"
Expand Down Expand Up @@ -231,18 +232,16 @@ func (c *stateClient) http() (*retryablehttp.Client, error) {
}
rc := retryablehttp.NewClient()

rc.CheckRetry = func(resp *http.Response, err error) (bool, error) {
rc.CheckRetry = func(ctx context.Context, resp *http.Response, err error) (bool, error) {
if err != nil {
// don't bother retrying if the certs don't match
if err, ok := err.(*url.Error); ok {
if _, ok := err.Err.(x509.UnknownAuthorityError); ok {
return false, nil
}
}
// continue retrying
return true, nil
}
return retryablehttp.DefaultRetryPolicy(resp, err)
return retryablehttp.DefaultRetryPolicy(ctx, resp, err)
}

t := cleanhttp.DefaultTransport()
Expand Down
7 changes: 4 additions & 3 deletions backend/atlas/state_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package atlas

import (
"bytes"
"context"
"crypto/md5"
"crypto/tls"
"crypto/x509"
Expand Down Expand Up @@ -29,7 +30,7 @@ func testStateClient(t *testing.T, c map[string]string) remote.Client {
}
synthBody := configs.SynthBody("<test>", vals)

b := backend.TestBackendConfig(t, &Backend{}, synthBody)
b := backend.TestBackendConfig(t, New(), synthBody)
raw, err := b.StateMgr(backend.DefaultStateName)
if err != nil {
t.Fatalf("err: %s", err)
Expand Down Expand Up @@ -83,12 +84,12 @@ func TestStateClient_noRetryOnBadCerts(t *testing.T) {
// Instrument CheckRetry to make sure we didn't retry
retries := 0
oldCheck := httpClient.CheckRetry
httpClient.CheckRetry = func(resp *http.Response, err error) (bool, error) {
httpClient.CheckRetry = func(ctx context.Context, resp *http.Response, err error) (bool, error) {
if retries > 0 {
t.Fatal("retried after certificate error")
}
retries++
return oldCheck(resp, err)
return oldCheck(ctx, resp, err)
}

_, err = client.Get()
Expand Down
44 changes: 25 additions & 19 deletions backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
"errors"
"time"

"github.com/zclconf/go-cty/cty"

"github.com/hashicorp/terraform/addrs"
"github.com/hashicorp/terraform/command/clistate"
"github.com/hashicorp/terraform/configs"
Expand All @@ -22,24 +20,35 @@ import (
"github.com/hashicorp/terraform/states/statemgr"
"github.com/hashicorp/terraform/terraform"
"github.com/hashicorp/terraform/tfdiags"
"github.com/zclconf/go-cty/cty"
)

// DefaultStateName is the name of the default, initial state that every
// backend must have. This state cannot be deleted.
const DefaultStateName = "default"

// ErrWorkspacesNotSupported is an error returned when a caller attempts
// to perform an operation on a workspace other than "default" for a
// backend that doesn't support multiple workspaces.
//
// The caller can detect this to do special fallback behavior or produce
// a specific, helpful error message.
var ErrWorkspacesNotSupported = errors.New("workspaces not supported")
var (
// ErrDefaultWorkspaceNotSupported is returned when an operation does not
// support using the default workspace, but requires a named workspace to
// be selected.
ErrDefaultWorkspaceNotSupported = errors.New("default workspace not supported\n" +
"You can create a new workspace with the \"workspace new\" command.")

// ErrNamedStatesNotSupported is an older name for ErrWorkspacesNotSupported.
//
// Deprecated: Use ErrWorkspacesNotSupported instead.
var ErrNamedStatesNotSupported = ErrWorkspacesNotSupported
// ErrOperationNotSupported is returned when an unsupported operation
// is detected by the configured backend.
ErrOperationNotSupported = errors.New("operation not supported")

// ErrWorkspacesNotSupported is an error returned when a caller attempts
// to perform an operation on a workspace other than "default" for a
// backend that doesn't support multiple workspaces.
//
// The caller can detect this to do special fallback behavior or produce
// a specific, helpful error message.
ErrWorkspacesNotSupported = errors.New("workspaces not supported")
)

// InitFn is used to initialize a new backend.
type InitFn func() Backend

// Backend is the minimal interface that must be implemented to enable Terraform.
type Backend interface {
Expand Down Expand Up @@ -179,11 +188,12 @@ type Operation struct {

// The options below are more self-explanatory and affect the runtime
// behavior of the operation.
AutoApprove bool
Destroy bool
DestroyForce bool
Parallelism int
Targets []addrs.Targetable
Variables map[string]UnparsedVariableValue
AutoApprove bool
DestroyForce bool

// Input/output/control options.
UIIn terraform.UIInput
Expand Down Expand Up @@ -244,10 +254,6 @@ type RunningOperation struct {
// operation has completed.
Result OperationResult

// ExitCode can be used to set a custom exit code. This enables enhanced
// backends to set specific exit codes that miror any remote exit codes.
ExitCode int

// PlanEmpty is populated after a Plan operation completes without error
// to note whether a plan is empty or has changes.
PlanEmpty bool
Expand Down
Loading

0 comments on commit a59308f

Please sign in to comment.