Skip to content

Commit d2e999b

Browse files
authored
remove unused code (hashicorp#26503)
* remove unused code I've removed the provider-specific code under registry, and unused nil backend, and replaced a call to helper from backend/oss (the other callers of that func are provisioners scheduled to be deprecated). I also removed the Dockerfile, as our build process uses a different file. Finally I removed the examples directory, which had outdated examples and links. There are better, actively maintained examples available. * command: remove various unused bits * test wasn't running * backend: remove unused err
1 parent 7a7ad23 commit d2e999b

35 files changed

Lines changed: 33 additions & 1421 deletions

‎Dockerfile‎

Lines changed: 0 additions & 24 deletions
This file was deleted.

‎backend/backend.go‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ var (
3434
ErrDefaultWorkspaceNotSupported = errors.New("default workspace not supported\n" +
3535
"You can create a new workspace with the \"workspace new\" command.")
3636

37-
// ErrOperationNotSupported is returned when an unsupported operation
38-
// is detected by the configured backend.
39-
ErrOperationNotSupported = errors.New("operation not supported")
40-
4137
// ErrWorkspacesNotSupported is an error returned when a caller attempts
4238
// to perform an operation on a workspace other than "default" for a
4339
// backend that doesn't support multiple workspaces.

‎backend/nil.go‎

Lines changed: 0 additions & 40 deletions
This file was deleted.

‎backend/nil_test.go‎

Lines changed: 0 additions & 9 deletions
This file was deleted.

‎backend/remote-state/oss/backend.go‎

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,30 @@ import (
55
"encoding/json"
66
"fmt"
77
"io/ioutil"
8-
"os"
9-
"runtime"
10-
"strings"
11-
12-
"github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
13-
"github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses"
14-
"github.com/aliyun/alibaba-cloud-sdk-go/services/sts"
15-
"github.com/aliyun/aliyun-oss-go-sdk/oss"
16-
"github.com/hashicorp/terraform/backend"
17-
"github.com/hashicorp/terraform/helper/schema"
18-
"github.com/hashicorp/terraform/helper/validation"
19-
"github.com/jmespath/go-jmespath"
20-
218
"log"
229
"net/http"
10+
"net/url"
11+
"os"
12+
"regexp"
13+
"runtime"
2314
"strconv"
15+
"strings"
2416
"time"
2517

2618
"github.com/aliyun/alibaba-cloud-sdk-go/sdk"
2719
"github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
20+
"github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
21+
"github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses"
2822
"github.com/aliyun/alibaba-cloud-sdk-go/services/location"
23+
"github.com/aliyun/alibaba-cloud-sdk-go/services/sts"
24+
"github.com/aliyun/aliyun-oss-go-sdk/oss"
2925
"github.com/aliyun/aliyun-tablestore-go-sdk/tablestore"
3026
"github.com/hashicorp/go-cleanhttp"
27+
"github.com/hashicorp/terraform/backend"
28+
"github.com/hashicorp/terraform/helper/schema"
3129
"github.com/hashicorp/terraform/version"
30+
"github.com/jmespath/go-jmespath"
3231
"github.com/mitchellh/go-homedir"
33-
"net/url"
34-
"regexp"
3532
)
3633

3734
// New creates a new backend for OSS remote state.
@@ -196,10 +193,23 @@ func assumeRoleSchema() *schema.Schema {
196193
Description: "The permissions applied when assuming a role. You cannot use this policy to grant permissions which exceed those of the role that is being assumed.",
197194
},
198195
"session_expiration": {
199-
Type: schema.TypeInt,
200-
Optional: true,
201-
Description: "The time after which the established session for assuming role expires.",
202-
ValidateFunc: validation.IntBetween(900, 3600),
196+
Type: schema.TypeInt,
197+
Optional: true,
198+
Description: "The time after which the established session for assuming role expires.",
199+
ValidateFunc: func(v interface{}, k string) ([]string, []error) {
200+
min := 900
201+
max := 3600
202+
value, ok := v.(int)
203+
if !ok {
204+
return nil, []error{fmt.Errorf("expected type of %s to be int", k)}
205+
}
206+
207+
if value < min || value > max {
208+
return nil, []error{fmt.Errorf("expected %s to be in the range (%d - %d), got %d", k, min, max, v)}
209+
}
210+
211+
return nil, nil
212+
},
203213
},
204214
},
205215
},

‎command/init.go‎

Lines changed: 1 addition & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -427,9 +427,8 @@ func (c *InitCommand) getProviders(config *configs.Config, state *states.State,
427427
if moreDiags.HasErrors() {
428428
return false, true, diags
429429
}
430-
stateReqs := make(getproviders.Requirements, 0)
431430
if state != nil {
432-
stateReqs = state.ProviderRequirements()
431+
stateReqs := state.ProviderRequirements()
433432
reqs = reqs.Merge(stateReqs)
434433
}
435434

@@ -774,16 +773,6 @@ func (c *InitCommand) getProviders(config *configs.Config, state *states.State,
774773
return true, false, diags
775774
}
776775

777-
func (c *InitCommand) populateProviderToReqs(reqs map[addrs.Provider][]*configs.ModuleRequirements, node *configs.ModuleRequirements) {
778-
for fqn := range node.Requirements {
779-
reqs[fqn] = append(reqs[fqn], node)
780-
}
781-
782-
for _, child := range node.Children {
783-
c.populateProviderToReqs(reqs, child)
784-
}
785-
}
786-
787776
// backendConfigOverrideBody interprets the raw values of -backend-config
788777
// arguments into a hcl Body that should override the backend settings given
789778
// in the configuration.
@@ -1030,117 +1019,6 @@ changes, we recommend adding version constraints in a required_providers block
10301019
in your configuration, with the constraint strings suggested below.
10311020
`
10321021

1033-
const errDiscoveryServiceUnreachable = `
1034-
[reset][bold][red]Registry service unreachable.[reset][red]
1035-
1036-
This may indicate a network issue, or an issue with the requested Terraform Registry.
1037-
`
1038-
1039-
const errProviderNotFound = `
1040-
[reset][bold][red]Provider %[1]q not available for installation.[reset][red]
1041-
1042-
A provider named %[1]q could not be found in the Terraform Registry.
1043-
1044-
This may result from mistyping the provider name, or the given provider may
1045-
be a third-party provider that cannot be installed automatically.
1046-
1047-
In the latter case, the plugin must be installed manually by locating and
1048-
downloading a suitable distribution package and placing the plugin's executable
1049-
file in the following directory:
1050-
%[2]s
1051-
1052-
Terraform detects necessary plugins by inspecting the configuration and state.
1053-
To view the provider versions requested by each module, run
1054-
"terraform providers".
1055-
`
1056-
1057-
const errProviderVersionsUnsuitable = `
1058-
[reset][bold][red]No provider %[1]q plugins meet the constraint %[2]q.[reset][red]
1059-
1060-
The version constraint is derived from the "version" argument within the
1061-
provider %[1]q block in configuration. Child modules may also apply
1062-
provider version constraints. To view the provider versions requested by each
1063-
module in the current configuration, run "terraform providers".
1064-
1065-
To proceed, the version constraints for this provider must be relaxed by
1066-
either adjusting or removing the "version" argument in the provider blocks
1067-
throughout the configuration.
1068-
`
1069-
1070-
const errProviderIncompatible = `
1071-
[reset][bold][red]No available provider %[1]q plugins are compatible with this Terraform version.[reset][red]
1072-
1073-
From time to time, new Terraform major releases can change the requirements for
1074-
plugins such that older plugins become incompatible.
1075-
1076-
Terraform checked all of the plugin versions matching the given constraint:
1077-
%[2]s
1078-
1079-
Unfortunately, none of the suitable versions are compatible with this version
1080-
of Terraform. If you have recently upgraded Terraform, it may be necessary to
1081-
move to a newer major release of this provider. Alternatively, if you are
1082-
attempting to upgrade the provider to a new major version you may need to
1083-
also upgrade Terraform to support the new version.
1084-
1085-
Consult the documentation for this provider for more information on
1086-
compatibility between provider versions and Terraform versions.
1087-
`
1088-
1089-
const errProviderInstallError = `
1090-
[reset][bold][red]Error installing provider %[1]q: %[2]s.[reset][red]
1091-
1092-
Terraform analyses the configuration and state and automatically downloads
1093-
plugins for the providers used. However, when attempting to download this
1094-
plugin an unexpected error occurred.
1095-
1096-
This may be caused if for some reason Terraform is unable to reach the
1097-
plugin repository. The repository may be unreachable if access is blocked
1098-
by a firewall.
1099-
1100-
If automatic installation is not possible or desirable in your environment,
1101-
you may alternatively manually install plugins by downloading a suitable
1102-
distribution package and placing the plugin's executable file in the
1103-
following directory:
1104-
%[3]s
1105-
`
1106-
1107-
const errMissingProvidersNoInstall = `
1108-
[reset][bold][red]Missing required providers.[reset][red]
1109-
1110-
The following provider constraints are not met by the currently-installed
1111-
provider plugins:
1112-
1113-
%[1]s
1114-
Terraform can automatically download and install plugins to meet the given
1115-
constraints, but this step was skipped due to the use of -get-plugins=false
1116-
and/or -plugin-dir on the command line.
1117-
1118-
If automatic installation is not possible or desirable in your environment,
1119-
you may manually install plugins by downloading a suitable distribution package
1120-
and placing the plugin's executable file in one of the directories given in
1121-
by -plugin-dir on the command line, or in the following directory if custom
1122-
plugin directories are not set:
1123-
%[2]s
1124-
`
1125-
1126-
const errChecksumVerification = `
1127-
[reset][bold][red]Error verifying checksum for provider %[1]q[reset][red]
1128-
The checksum for provider distribution from the Terraform Registry
1129-
did not match the source. This may mean that the distributed files
1130-
were changed after this version was released to the Registry.
1131-
`
1132-
1133-
const errSignatureVerification = `
1134-
[reset][bold][red]Error:[reset][bold] Untrusted signing key for provider %[1]q[reset]
1135-
1136-
This provider package is not signed with the HashiCorp signing key, and is
1137-
therefore incompatible with Terraform v%[2]s.
1138-
1139-
A later version of Terraform may have introduced other signing keys that would
1140-
accept this provider. Alternatively, an earlier version of this provider may
1141-
be compatible with Terraform v%[2]s.
1142-
`
1143-
11441022
// providerProtocolTooOld is a message sent to the CLI UI if the provider's
11451023
// supported protocol versions are too old for the user's version of terraform,
11461024
// but a newer version of the provider is compatible.
@@ -1171,20 +1049,3 @@ Alternatively, upgrade to the latest version of Terraform for compatibility with
11711049

11721050
// No version of the provider is compatible.
11731051
const errProviderVersionIncompatible = `No compatible versions of provider %s were found.`
1174-
1175-
// Logic from internal/initwd/getter.go
1176-
var localSourcePrefixes = []string{
1177-
"./",
1178-
"../",
1179-
".\\",
1180-
"..\\",
1181-
}
1182-
1183-
func isLocalSourceAddr(addr string) bool {
1184-
for _, prefix := range localSourcePrefixes {
1185-
if strings.HasPrefix(addr, prefix) {
1186-
return true
1187-
}
1188-
}
1189-
return false
1190-
}

0 commit comments

Comments
 (0)