@@ -16,6 +16,7 @@ import (
1616 "github.com/hashicorp/terraform/internal/backend"
1717 backendInit "github.com/hashicorp/terraform/internal/backend/init"
1818 "github.com/hashicorp/terraform/internal/cloud"
19+ "github.com/hashicorp/terraform/internal/command/arguments"
1920 "github.com/hashicorp/terraform/internal/configs"
2021 "github.com/hashicorp/terraform/internal/configs/configschema"
2122 "github.com/hashicorp/terraform/internal/getproviders"
@@ -34,13 +35,14 @@ type InitCommand struct {
3435
3536func (c * InitCommand ) Run (args []string ) int {
3637 var flagFromModule , flagLockfile string
37- var flagBackend , flagGet , flagUpgrade bool
38+ var flagBackend , flagCloud , flagGet , flagUpgrade bool
3839 var flagPluginPath FlagStringSlice
3940 flagConfigExtra := newRawFlags ("-backend-config" )
4041
4142 args = c .Meta .process (args )
4243 cmdFlags := c .Meta .extendedFlagSet ("init" )
4344 cmdFlags .BoolVar (& flagBackend , "backend" , true , "" )
45+ cmdFlags .BoolVar (& flagCloud , "cloud" , true , "" )
4446 cmdFlags .Var (flagConfigExtra , "backend-config" , "" )
4547 cmdFlags .StringVar (& flagFromModule , "from-module" , "" , "copy the source of the given module into the directory before init" )
4648 cmdFlags .BoolVar (& flagGet , "get" , true , "" )
@@ -58,6 +60,19 @@ func (c *InitCommand) Run(args []string) int {
5860 return 1
5961 }
6062
63+ backendFlagSet := arguments .FlagIsSet (cmdFlags , "backend" )
64+ cloudFlagSet := arguments .FlagIsSet (cmdFlags , "cloud" )
65+
66+ switch {
67+ case backendFlagSet && cloudFlagSet :
68+ c .Ui .Error ("The -backend and -cloud options are aliases of one another and mutually-exclusive in their use" )
69+ return 1
70+ case backendFlagSet :
71+ flagCloud = flagBackend
72+ case cloudFlagSet :
73+ flagBackend = flagCloud
74+ }
75+
6176 if c .migrateState && c .reconfigure {
6277 c .Ui .Error ("The -migrate-state and -reconfigure options are mutually-exclusive" )
6378 return 1
@@ -212,7 +227,7 @@ func (c *InitCommand) Run(args []string) int {
212227 var back backend.Backend
213228
214229 switch {
215- case config .Module .CloudConfig != nil :
230+ case flagCloud && config .Module .CloudConfig != nil :
216231 be , backendOutput , backendDiags := c .initCloud (config .Module , flagConfigExtra )
217232 diags = diags .Append (backendDiags )
218233 if backendDiags .HasErrors () {
@@ -992,6 +1007,7 @@ func (c *InitCommand) AutocompleteArgs() complete.Predictor {
9921007func (c * InitCommand ) AutocompleteFlags () complete.Flags {
9931008 return complete.Flags {
9941009 "-backend" : completePredictBoolean ,
1010+ "-cloud" : completePredictBoolean ,
9951011 "-backend-config" : complete .PredictFiles ("*.tfvars" ), // can also be key=value, but we can't "predict" that
9961012 "-force-copy" : complete .PredictNothing ,
9971013 "-from-module" : completePredictModuleSource ,
@@ -1026,8 +1042,11 @@ Usage: terraform [global options] init [options]
10261042
10271043Options:
10281044
1029- -backend=false Disable backend initialization for this configuration
1030- and use the previously initialized backend instead.
1045+ -backend=false Disable backend or Terraform Cloud initialization for
1046+ this configuration and use what what was previously
1047+ initialized instead.
1048+
1049+ aliases: -cloud=false
10311050
10321051 -backend-config=path This can be either a path to an HCL file with key/value
10331052 assignments (same format as terraform.tfvars) or a
0 commit comments