@@ -97,15 +97,23 @@ depends on the existing profiles you have set in your configuration file
9797
9898 var loginTimeout time.Duration
9999 var configureCluster bool
100+ var configureServerless bool
100101 cmd .Flags ().DurationVar (& loginTimeout , "timeout" , defaultTimeout ,
101102 "Timeout for completing login challenge in the browser" )
102103 cmd .Flags ().BoolVar (& configureCluster , "configure-cluster" , false ,
103104 "Prompts to configure cluster" )
105+ cmd .Flags ().BoolVar (& configureServerless , "configure-serverless" , false ,
106+ "Prompts to configure serverless" )
104107
105108 cmd .RunE = func (cmd * cobra.Command , args []string ) error {
106109 ctx := cmd .Context ()
107110 profileName := cmd .Flag ("profile" ).Value .String ()
108111
112+ // Cluster and Serverless are mutually exclusive.
113+ if configureCluster && configureServerless {
114+ return errors .New ("please either configure serverless or cluster, not both" )
115+ }
116+
109117 // If the user has not specified a profile name, prompt for one.
110118 if profileName == "" {
111119 var err error
@@ -119,22 +127,16 @@ depends on the existing profiles you have set in your configuration file
119127 }
120128 }
121129
130+ // Load parameters from the existing profile if any.
122131 existingProfile , err := loadProfileByName (ctx , profileName , profile .DefaultProfiler )
123132 if err != nil {
124133 return err
125134 }
126-
127- // Set the host and account-id based on the provided arguments and flags.
128135 err = setHostAndAccountId (ctx , existingProfile , authArguments , args )
129136 if err != nil {
130137 return err
131138 }
132139
133- clusterID := ""
134- if existingProfile != nil {
135- clusterID = existingProfile .ClusterID
136- }
137-
138140 oauthArgument , err := authArguments .ToOAuthArgument ()
139141 if err != nil {
140142 return err
@@ -155,7 +157,6 @@ depends on the existing profiles you have set in your configuration file
155157 Host : authArguments .Host ,
156158 AccountID : authArguments .AccountID ,
157159 AuthType : "databricks-cli" ,
158- ClusterID : clusterID ,
159160 }
160161 databricksCfgFile := os .Getenv ("DATABRICKS_CONFIG_FILE" )
161162 if databricksCfgFile != "" {
@@ -169,28 +170,44 @@ depends on the existing profiles you have set in your configuration file
169170 return err
170171 }
171172
172- if configureCluster {
173+ switch {
174+ case configureCluster :
173175 w , err := databricks .NewWorkspaceClient ((* databricks .Config )(& cfg ))
174176 if err != nil {
175177 return err
176178 }
177- ctx := cmd .Context ()
178179 clusterID , err := cfgpickers .AskForCluster (ctx , w ,
179180 cfgpickers .WithDatabricksConnect (minimalDbConnectVersion ))
180181 if err != nil {
181182 return err
182183 }
183184 cfg .ClusterID = clusterID
185+ case configureServerless :
186+ cfg .ClusterID = ""
187+ cfg .ServerlessComputeID = "auto"
188+ default :
189+ // Respect the existing profile if it exists, even if it has
190+ // both cluster and serverless configured. Tools relying on
191+ // these fields from the profile will need to handle this case.
192+ //
193+ // TODO: consider whether we should use this an an opportunity
194+ // to clean up the profile under the assumption that serverless
195+ // is the preferred option.
196+ if existingProfile != nil {
197+ cfg .ClusterID = existingProfile .ClusterID
198+ cfg .ServerlessComputeID = existingProfile .ServerlessComputeID
199+ }
184200 }
185201
186202 if profileName != "" {
187203 err = databrickscfg .SaveToProfile (ctx , & config.Config {
188- Profile : profileName ,
189- Host : cfg .Host ,
190- AuthType : cfg .AuthType ,
191- AccountID : cfg .AccountID ,
192- ClusterID : cfg .ClusterID ,
193- ConfigFile : cfg .ConfigFile ,
204+ Profile : profileName ,
205+ Host : cfg .Host ,
206+ AuthType : cfg .AuthType ,
207+ AccountID : cfg .AccountID ,
208+ ClusterID : cfg .ClusterID ,
209+ ConfigFile : cfg .ConfigFile ,
210+ ServerlessComputeID : cfg .ServerlessComputeID ,
194211 })
195212 if err != nil {
196213 return err
0 commit comments