Skip to content
This repository has been archived by the owner on Aug 13, 2024. It is now read-only.

Add AZURE_LOCATION as default --location in capi create #143

Merged
merged 4 commits into from
Jun 14, 2022
Merged

Add AZURE_LOCATION as default --location in capi create #143

merged 4 commits into from
Jun 14, 2022

Conversation

tal66
Copy link
Contributor

@tal66 tal66 commented Jun 8, 2022

Hi, this closes #120.

When --location isn't specified, it's now determined by:

  1. config file [defaults]
  2. resource-group
  3. AZURE_LOCATION
  4. still None -> raise RequiredArgumentMissingError

Did I miss anything?

Edit: actually when i think about it, maybe it makes more sense to have config file [defaults] and AZURE_LOCATION both either before resource-group or both after..

@ghost
Copy link

ghost commented Jun 8, 2022

CLA assistant check
All CLA requirements met.

@tal66
Copy link
Contributor Author

tal66 commented Jun 9, 2022

changed the order to:

  1. config file [defaults]
  2. AZURE_LOCATION
  3. checked against resource-group (if exists)
  4. raise Error

for existing rg, maybe it would make more sense to just take the rg loaction. but i used the above order because:

a. before my pr, the config file is used first
b. since this project is an extension, i'm not sure how to check if the location came from the config file or from the cli

@DannyBrito
Copy link
Contributor

DannyBrito commented Jun 10, 2022

Hello @tal66

The order that you presented is correct to set value for location for az capi create method priority:

  1. value passed with --location flag
  2. value specified on config file defaults by az config set defaults.location=<location>
  3. Environment variable AZURE_LOCATION
  4. Use location if resource group provided exits

After looking at bit more I see that there might be a bug on check_resource_group method when the resource group is found we should use this location, as you mentioned, by returning it to az capi create. I have opened another issue about this! #144

You are definitely in the right track. However, this change should take place on create_workload_cluster method for az capi create command
It should be similar to setting the defaults of the other arguments.
And if --location is not passed on the cli the framework will retrieve the config defaults location value if exits so we only need to take care of AZURE_LOCATION:

def create_workload_cluster( # pylint: disable=unused-argument,too-many-arguments,too-many-locals,too-many-statements

Thank you for your contribution 👍

@tal66
Copy link
Contributor Author

tal66 commented Jun 11, 2022

I moved it to create_workload_cluster, but didn't set the location like the other parameters with a default - as this way is problematic to test. From what i see, once the module file is read those defaults are set, so by the time i mock an environment variable in the test, the default is already None (it's not checked again every call).

@mboersma mboersma added this to the v0.0.6 milestone Jun 13, 2022
Copy link
Member

@mboersma mboersma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm! I tested this locally and this seems like the behavior we want. Thanks @tal66!

With this and #141, if you configure a default location or set AZURE_LOCATION, you can just do az capi create without any arguments.

@mboersma mboersma merged commit 4fdf493 into Azure:main Jun 14, 2022
jsturtevant pushed a commit to jsturtevant/azure-capi-cli-extension that referenced this pull request Jul 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AZURE_LOCATION should be used as the default for --location
3 participants