Rename internal/cloud to OpenTofu (#505)

This commit is contained in:
7h3-3mp7y-m4n 2023-09-21 14:09:47 +05:30 committed by GitHub
parent 46d6bad7f5
commit 915eb488fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 44 additions and 44 deletions

View File

@ -286,7 +286,7 @@ func (b *Cloud) Configure(obj cty.Value) tfdiags.Diagnostics {
fmt.Sprintf(
"Run the following command to generate a token for %s:\n %s",
b.hostname,
fmt.Sprintf("opentf login %s", b.hostname),
fmt.Sprintf("tofu login %s", b.hostname),
),
))
return diags
@ -403,7 +403,7 @@ func (b *Cloud) setConfigurationFields(obj cty.Value) tfdiags.Diagnostics {
diags = diags.Append(tfdiags.Sourceless(
tfdiags.Error,
"Hostname is required for the cloud backend",
`OpenTF does not provide a default "hostname" attribute, so it must be set to the hostname of the cloud backend.`,
`OpenTofu does not provide a default "hostname" attribute, so it must be set to the hostname of the cloud backend.`,
))
return diags
@ -742,7 +742,7 @@ func (b *Cloud) StateMgr(name string) (statemgr.Full, error) {
// Explicitly ignore the pseudo-version "latest" here, as it will cause
// plan and apply to always fail.
if remoteTFVersion != tfversion.String() && remoteTFVersion != "latest" {
return nil, fmt.Errorf("Remote workspace TF version %q does not match local OpenTF version %q", remoteTFVersion, tfversion.String())
return nil, fmt.Errorf("Remote workspace TF version %q does not match local OpenTofu version %q", remoteTFVersion, tfversion.String())
}
}
@ -786,7 +786,7 @@ func (b *Cloud) Operation(ctx context.Context, op *backend.Operation) (*backend.
case backend.OperationTypeApply:
f = b.opApply
case backend.OperationTypeRefresh:
// The `opentf refresh` command has been deprecated in favor of `opentf apply -refresh-state`.
// The `tofu refresh` command has been deprecated in favor of `tofu apply -refresh-state`.
// Rather than respond with an error telling the user to run the other command we can just run
// that command instead. We will tell the user what we are doing, and then do it.
if b.CLI != nil {
@ -967,7 +967,7 @@ func (b *Cloud) VerifyWorkspaceTerraformVersion(workspaceName string) tfdiags.Di
if err != nil {
message := fmt.Sprintf(
"The remote workspace specified an invalid TF version or constraint (%s), "+
"and it isn't possible to determine whether the local OpenTF version (%s) is compatible.",
"and it isn't possible to determine whether the local OpenTofu version (%s) is compatible.",
workspace.TerraformVersion,
tfversion.String(),
)
@ -1019,7 +1019,7 @@ func (b *Cloud) VerifyWorkspaceTerraformVersion(workspaceName string) tfdiags.Di
}
message := fmt.Sprintf(
"The local OpenTF version (%s) does not meet the version requirements for remote workspace %s/%s (%s).",
"The local OpenTofu version (%s) does not meet the version requirements for remote workspace %s/%s (%s).",
tfversion.String(),
b.organization,
workspace.Name,
@ -1149,7 +1149,7 @@ func (b *Cloud) validWorkspaceEnvVar(ctx context.Context, organization, workspac
return tfdiags.Sourceless(
tfdiags.Error,
"Invalid workspace selection",
fmt.Sprintf(`OpenTF failed to find workspace %q in organization %s.`, workspace, organization),
fmt.Sprintf(`OpenTofu failed to find workspace %q in organization %s.`, workspace, organization),
)
}
@ -1186,7 +1186,7 @@ func (b *Cloud) validWorkspaceEnvVar(ctx context.Context, organization, workspac
tfdiags.Error,
"Invalid workspace selection",
fmt.Sprintf(
"OpenTF failed to find workspace %q with the tags specified in your configuration:\n[%s]",
"OpenTofu failed to find workspace %q with the tags specified in your configuration:\n[%s]",
workspace,
strings.ReplaceAll(opts.Tags, ",", ", "),
),
@ -1246,7 +1246,7 @@ func generalError(msg string, err error) error {
// The newline in this error is to make it look good in the CLI!
const initialRetryError = `
[reset][yellow]There was an error connecting to Terraform Cloud. Please do not exit
OpenTF to prevent data loss! Trying to restore the connection...
OpenTofu to prevent data loss! Trying to restore the connection...
[reset]
`
@ -1262,10 +1262,10 @@ const operationNotCanceled = `
[reset][red]The remote operation was not cancelled.[reset]
`
const refreshToApplyRefresh = `[bold][yellow]Proceeding with 'opentf apply -refresh-only -auto-approve'.[reset]`
const refreshToApplyRefresh = `[bold][yellow]Proceeding with 'tofu apply -refresh-only -auto-approve'.[reset]`
const unavailableTerraformVersion = `
[reset][yellow]The local OpenTF version (%s) is not available in Terraform Cloud, or your
[reset][yellow]The local OpenTofu version (%s) is not available in Terraform Cloud, or your
organization does not have access to it. The new workspace will use %s. You can
change this later in the workspace settings.[reset]`
@ -1273,11 +1273,11 @@ const cloudIntegrationUsedInUnsupportedTFE = `
This version of cloud backend does not support the state mechanism
attempting to be used by the platform. This should never happen.
Please reach out to OpenTF Support to resolve this issue.`
Please reach out to OpenTofu Support to resolve this issue.`
var (
workspaceConfigurationHelp = fmt.Sprintf(
`The 'workspaces' block configures how OpenTF CLI maps its workspaces for this single
`The 'workspaces' block configures how OpenTofu CLI maps its workspaces for this single
configuration to workspaces within a Terraform Cloud organization. Two strategies are available:
[bold]tags[reset] - %s
@ -1289,7 +1289,7 @@ configuration to workspaces within a Terraform Cloud organization. Two strategie
schemaDescriptionOrganization = `The name of the organization containing the targeted workspace(s).`
schemaDescriptionToken = `The token used to authenticate with the cloud backend. Typically this argument should not
be set, and 'opentf login' used instead; your credentials will then be fetched from your CLI
be set, and 'tofu login' used instead; your credentials will then be fetched from your CLI
configuration file or configured credential helper.`
schemaDescriptionTags = `A set of tags used to select remote Terraform Cloud workspaces to be used for this single

View File

@ -71,7 +71,7 @@ func (b *Cloud) opApply(stopCtx, cancelCtx context.Context, op *backend.Operatio
"No configuration files found",
`Apply requires configuration to be present. Applying without a configuration `+
`would mark everything for destruction, which is normally not what is desired. `+
`If you would like to destroy everything, please run 'opentf destroy' which `+
`If you would like to destroy everything, please run 'tofu destroy' which `+
`does not require any configuration files.`,
))
}
@ -158,11 +158,11 @@ func (b *Cloud) opApply(stopCtx, cancelCtx context.Context, op *backend.Operatio
if op.PlanMode == plans.DestroyMode {
opts.Query = "\nDo you really want to destroy all resources in workspace \"" + op.Workspace + "\"?"
opts.Description = "OpenTF will destroy all your managed infrastructure, as shown above.\n" +
opts.Description = "OpenTofu will destroy all your managed infrastructure, as shown above.\n" +
"There is no undo. Only 'yes' will be accepted to confirm."
} else {
opts.Query = "\nDo you want to perform these actions in workspace \"" + op.Workspace + "\"?"
opts.Description = "OpenTF will perform the actions described above.\n" +
opts.Description = "OpenTofu will perform the actions described above.\n" +
"Only 'yes' will be accepted to approve."
}

View File

@ -1948,7 +1948,7 @@ func TestCloud_applyVersionCheck(t *testing.T) {
}
const applySuccessOneResourceAdded = `
OpenTF v0.11.10
OpenTofu v0.11.10
Initializing plugins and modules...
null_resource.hello: Creating...

View File

@ -147,7 +147,7 @@ func (b *Cloud) LocalRun(op *backend.Operation) (*backend.LocalRun, statemgr.Ful
diags = diags.Append(ctxDiags)
ret.Core = tfCtx
log.Printf("[TRACE] cloud: finished building opentf.Context")
log.Printf("[TRACE] cloud: finished building tofu.Context")
return ret, stateMgr, diags
}

View File

@ -73,7 +73,7 @@ func (b *Cloud) opPlan(stopCtx, cancelCtx context.Context, op *backend.Operation
`would mark everything for destruction, which is normally not what is desired. `+
`If you would like to destroy everything, please run plan with the "-destroy" `+
`flag or create a single empty configuration file. Otherwise, please create `+
`a OpenTF configuration file in the path being executed and try again.`,
`a OpenTofu configuration file in the path being executed and try again.`,
))
}
@ -159,7 +159,7 @@ func (b *Cloud) plan(stopCtx, cancelCtx context.Context, op *backend.Operation,
The remote workspace is configured to work with configuration at
%s relative to the target repository.
OpenTF will upload the contents of the following directory,
OpenTofu will upload the contents of the following directory,
excluding files or directories as defined by a .terraformignore file
at %s/.terraformignore (if it is present),
in order to capture the filesystem context the remote workspace expects:
@ -399,7 +399,7 @@ func (b *Cloud) AssertImportCompatible(config *configs.Config) error {
// First, check the remote API version is high enough.
currentAPIVersion, err := version.NewVersion(b.client.RemoteAPIVersion())
if err != nil {
return fmt.Errorf("Error parsing remote API version. To proceed, please remove any import blocks from your config. Please report the following error to the OpenTF team: %w", err)
return fmt.Errorf("Error parsing remote API version. To proceed, please remove any import blocks from your config. Please report the following error to the OpenTofu team: %w", err)
}
desiredAPIVersion, _ := version.NewVersion("2.6")
if currentAPIVersion.LessThan(desiredAPIVersion) {
@ -409,11 +409,11 @@ func (b *Cloud) AssertImportCompatible(config *configs.Config) error {
// Second, check the agent version is high enough.
agentEnv, isSet := os.LookupEnv("TFC_AGENT_VERSION")
if !isSet {
return fmt.Errorf("Error reading TFC agent version. To proceed, please remove any import blocks from your config. Please report the following error to the OpenTF team: TFC_AGENT_VERSION not present.")
return fmt.Errorf("Error reading TFC agent version. To proceed, please remove any import blocks from your config. Please report the following error to the OpenTofu team: TFC_AGENT_VERSION not present.")
}
currentAgentVersion, err := version.NewVersion(agentEnv)
if err != nil {
return fmt.Errorf("Error parsing TFC agent version. To proceed, please remove any import blocks from your config. Please report the following error to the OpenTF team: %w", err)
return fmt.Errorf("Error parsing TFC agent version. To proceed, please remove any import blocks from your config. Please report the following error to the OpenTofu team: %w", err)
}
desiredAgentVersion, _ := version.NewVersion("1.10")
if currentAgentVersion.LessThan(desiredAgentVersion) {

View File

@ -947,7 +947,7 @@ func TestCloud_planWithWorkingDirectory(t *testing.T) {
defer bCleanup()
options := tfe.WorkspaceUpdateOptions{
WorkingDirectory: tfe.String("opentf"),
WorkingDirectory: tfe.String("tofu"),
}
// Configure the workspace to use a custom working directory.
@ -956,7 +956,7 @@ func TestCloud_planWithWorkingDirectory(t *testing.T) {
t.Fatalf("error configuring working directory: %v", err)
}
op, configCleanup, done := testOperationPlan(t, "./testdata/plan-with-working-directory/opentf")
op, configCleanup, done := testOperationPlan(t, "./testdata/plan-with-working-directory/tofu")
defer configCleanup()
defer done(t)
@ -992,7 +992,7 @@ func TestCloud_planWithWorkingDirectoryFromCurrentPath(t *testing.T) {
defer bCleanup()
options := tfe.WorkspaceUpdateOptions{
WorkingDirectory: tfe.String("opentf"),
WorkingDirectory: tfe.String("tofu"),
}
// Configure the workspace to use a custom working directory.
@ -1008,7 +1008,7 @@ func TestCloud_planWithWorkingDirectoryFromCurrentPath(t *testing.T) {
// We need to change into the configuration directory to make sure
// the logic to upload the correct slug is working as expected.
if err := os.Chdir("./testdata/plan-with-working-directory/opentf"); err != nil {
if err := os.Chdir("./testdata/plan-with-working-directory/tofu"); err != nil {
t.Fatalf("error changing directory: %v", err)
}
defer os.Chdir(wd) // Make sure we change back again when were done.

View File

@ -71,7 +71,7 @@ func TestCloud_refreshBasicActuallyRunsApplyRefresh(t *testing.T) {
}
output := b.CLI.(*cli.MockUi).OutputWriter.String()
if !strings.Contains(output, "Proceeding with 'opentf apply -refresh-only -auto-approve'") {
if !strings.Contains(output, "Proceeding with 'tofu apply -refresh-only -auto-approve'") {
t.Fatalf("expected TFC header in output: %s", output)
}

View File

@ -31,7 +31,7 @@ func (b *Cloud) ShowPlanForRun(ctx context.Context, runID, runHostname string, r
// Get run and plan
r, err := b.client.Runs.ReadWithOptions(ctx, runID, &tfe.RunReadOptions{Include: []tfe.RunIncludeOpt{tfe.RunPlan, tfe.RunWorkspace}})
if err == tfe.ErrResourceNotFound {
return nil, fmt.Errorf("couldn't read information for cloud run %s; make sure you've run `opentf login` and that you have permission to view the run", runID)
return nil, fmt.Errorf("couldn't read information for cloud run %s; make sure you've run `tofu login` and that you have permission to view the run", runID)
} else if err != nil {
return nil, fmt.Errorf("couldn't read information for cloud run %s: %w", runID, err)
}
@ -67,9 +67,9 @@ func (b *Cloud) ShowPlanForRun(ctx context.Context, runID, runHostname string, r
}
if err == tfe.ErrResourceNotFound {
if redacted {
return nil, fmt.Errorf("couldn't read plan data for cloud run %s; make sure you've run `opentf login` and that you have permission to view the run", runID)
return nil, fmt.Errorf("couldn't read plan data for cloud run %s; make sure you've run `tofu login` and that you have permission to view the run", runID)
} else {
return nil, fmt.Errorf("couldn't read unredacted JSON plan data for cloud run %s; make sure you've run `opentf login` and that you have admin permissions on the workspace", runID)
return nil, fmt.Errorf("couldn't read unredacted JSON plan data for cloud run %s; make sure you've run `tofu login` and that you have admin permissions on the workspace", runID)
}
} else if err != nil {
return nil, fmt.Errorf("couldn't read plan data for cloud run %s: %w", runID, err)

View File

@ -39,7 +39,7 @@ func TestCloud_showMissingRun(t *testing.T) {
absentRunID := "run-WwwwXxxxYyyyZzzz"
_, err := b.ShowPlanForRun(context.Background(), absentRunID, "app.terraform.io", true)
if !strings.Contains(err.Error(), "opentf login") {
if !strings.Contains(err.Error(), "tofu login") {
t.Fatalf("expected error message to suggest checking your login status, instead got: %s", err)
}
}

View File

@ -389,7 +389,7 @@ func WithEnvVars(t *testing.T) {
vars: map[string]string{
"TF_WORKSPACE": "i-dont-exist-in-org",
},
expectedErr: `Invalid workspace selection: OpenTF failed to find workspace "i-dont-exist-in-org" in organization hashicorp`,
expectedErr: `Invalid workspace selection: OpenTofu failed to find workspace "i-dont-exist-in-org" in organization hashicorp`,
},
"workspaces and env var specified": {
config: cty.ObjectVal(map[string]cty.Value{
@ -432,7 +432,7 @@ func WithEnvVars(t *testing.T) {
vars: map[string]string{
"TF_WORKSPACE": "shire",
},
expectedErr: "OpenTF failed to find workspace \"shire\" with the tags specified in your configuration:\n[cloud]",
expectedErr: "OpenTofu failed to find workspace \"shire\" with the tags specified in your configuration:\n[cloud]",
},
"env var workspace has specified tag": {
setup: func(b *Cloud) {
@ -643,7 +643,7 @@ func TestCloud_config(t *testing.T) {
"project": cty.NullVal(cty.String),
}),
}),
confErr: "opentf login localhost",
confErr: "tofu login localhost",
},
"with_tags": {
config: cty.ObjectVal(map[string]cty.Value{
@ -1109,7 +1109,7 @@ func TestCloud_StateMgr_versionCheck(t *testing.T) {
}
// This should fail
want := `Remote workspace TF version "0.13.5" does not match local OpenTF version "0.14.0"`
want := `Remote workspace TF version "0.13.5" does not match local OpenTofu version "0.14.0"`
if _, err := b.StateMgr(testBackendSingleWorkspaceName); err.Error() != want {
t.Fatalf("wrong error\n got: %v\nwant: %v", err.Error(), want)
}
@ -1327,7 +1327,7 @@ func TestCloud_VerifyWorkspaceTerraformVersion_ignoreFlagSet(t *testing.T) {
if got, want := diags[0].Description().Summary, "Incompatible TF version"; got != want {
t.Errorf("wrong summary: got %s, want %s", got, want)
}
wantDetail := "The local OpenTF version (0.14.0) does not meet the version requirements for remote workspace hashicorp/app-prod (0.13.5)."
wantDetail := "The local OpenTofu version (0.14.0) does not meet the version requirements for remote workspace hashicorp/app-prod (0.13.5)."
if got := diags[0].Description().Detail; got != wantDetail {
t.Errorf("wrong summary: got %s, want %s", got, wantDetail)
}

View File

@ -6,7 +6,7 @@ TFE_TOKEN=<token> TFE_HOSTNAME=<hostname> TF_ACC=1 go test ./internal/cloud/e2e
```
Required flags
* `TF_ACC=1`. This variable is used as part of opentf for tests that make
* `TF_ACC=1`. This variable is used as part of tofu for tests that make
external network calls. This is needed to run these tests. Without it, the
tests do not run.
* `TFE_TOKEN=<admin token>` and `TFE_HOSTNAME=<hostname>`. The helpers
@ -16,9 +16,9 @@ for these tests require admin access to a TFC/TFE instance.
### Flags
* Use the `-v` flag for normal verbose mode.
* Use the `-tfoutput` flag to print the opentf output to standard out.
* Use the `-tfoutput` flag to print the tofu output to standard out.
* Use `-ldflags` to change the version Prerelease to match a version
available remotely. Some behaviors rely on the exact local version OpenTF
available remotely. Some behaviors rely on the exact local version OpenTofu
being available in TFC/TFE, and manipulating the Prerelease during build is
often the only way to ensure this.
[(More on `-ldflags`.)](https://www.digitalocean.com/community/tutorials/using-ldflags-to-set-version-information-for-go-applications)

View File

@ -40,7 +40,7 @@ var (
)
)
const ignoreRemoteVersionHelp = "If you're sure you want to upgrade the state, you can force OpenTF to continue using the -ignore-remote-version flag. This may result in an unusable workspace."
const ignoreRemoteVersionHelp = "If you're sure you want to upgrade the state, you can force OpenTofu to continue using the -ignore-remote-version flag. This may result in an unusable workspace."
func missingConfigAttributeAndEnvVar(attribute string, envVar string) tfdiags.Diagnostic {
detail := strings.TrimSpace(fmt.Sprintf("\"%s\" must be set in the cloud configuration or as an environment variable: %s.\n", attribute, envVar))

View File

@ -76,7 +76,7 @@ type State struct {
var ErrStateVersionUnauthorizedUpgradeState = errors.New(strings.TrimSpace(`
You are not authorized to read the full state version containing outputs.
State versions created by opentf v1.3.0 and newer do not require this level
State versions created by tofu v1.3.0 and newer do not require this level
of authorization and therefore this error can usually be fixed by upgrading the
remote state version.
`))
@ -338,7 +338,7 @@ func (s *State) Lock(info *statemgr.LockInfo) (string, error) {
// Lock the workspace.
_, err := s.tfeClient.Workspaces.Lock(ctx, s.workspace.ID, tfe.WorkspaceLockOptions{
Reason: tfe.String("Locked by OpenTF"),
Reason: tfe.String("Locked by OpenTofu"),
})
if err != nil {
if err == tfe.ErrWorkspaceLocked {