Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Remove tfcli configuration with environment variables
Browse files Browse the repository at this point in the history
Signed-off-by: Alper Rifat Ulucinar <ulucinar@users.noreply.github.com>
  • Loading branch information
ulucinar committed Aug 26, 2021
1 parent 22c1e38 commit 33c5d44
Showing 1 changed file with 2 additions and 36 deletions.
38 changes: 2 additions & 36 deletions pkg/tfcli/builders.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package tfcli
import (
"context"
"fmt"
"os"
"time"

"github.com/pkg/errors"
Expand All @@ -36,11 +35,6 @@ const (
errValidationNoLogger = "no logger has been configured"
fmtErrValidationResource = "invalid resource specification: both type and name are required: type=%q and name=%q"
fmtErrValidationProvider = "invalid provider specification: both source and version are required: source=%q and version=%q"
// env variable names
envTFProviderVersion = "XP_TERRAFORM_PROVIDER_VERSION"
envTFProviderSource = "XP_TERRAFORM_PROVIDER_SOURCE"
envTFProviderConfiguration = "XP_TERRAFORM_PROVIDER_CONFIG"
envTFExecTimeout = "XP_TERRAFORM_CLI_EXEC_TIMEOUT"

fmtResourceAddress = "%s.%s"
)
Expand Down Expand Up @@ -124,9 +118,9 @@ func (cb clientBuilder) Build(ctx context.Context) (model.Client, error) {
func defaultClient() *client {
return &client{
state: &withState{},
provider: providerFromEnv(),
provider: &withProvider{},
resource: &withResource{},
execTimeout: timeoutFromEnv(),
execTimeout: &withTimeout{},
logger: &withLogger{},
}
}
Expand All @@ -135,19 +129,6 @@ type withTimeout struct {
to time.Duration
}

func timeoutFromEnv() *withTimeout {
result := &withTimeout{}
toStr := os.Getenv(envTFExecTimeout)
if toStr == "" {
return result
}

// silently ignore unparsable timeout errors, we will observe
// execution timeout values in logs
result.to, _ = time.ParseDuration(toStr)
return result
}

type withLogger struct {
log logging.Logger
}
Expand Down Expand Up @@ -203,21 +184,6 @@ func (p withProvider) validate() error {
return nil
}

func providerFromEnv() *withProvider {
p := &withProvider{}
if p.source == "" {
p.source = os.Getenv(envTFProviderSource)
}
if p.version == "" {
p.version = os.Getenv(envTFProviderVersion)
}
if p.configuration == nil {
p.configuration = []byte(os.Getenv(envTFProviderConfiguration))
}

return p
}

func (cb *clientBuilder) WithLogger(logger logging.Logger) Builder {
cb.c.logger.log = logger.WithValues("tfcli-version", version.Version)
return cb
Expand Down

0 comments on commit 33c5d44

Please sign in to comment.