Issue using config.yml with Azure Credentials
See original GitHub issueIt’s more like a question rather than an issue, and I’m probably doing something wrong, but it seems that the use_local_azure_session_directory
isn’t read or something.
Here my config.yml
filed, located on conf directory :
---
always_trigger_init: false
use_local_azure_session_directory: false
I struggled quite a long time just initing my stack, with this message on the screen :
→ tfwrapper -a melon -e test -r fr-central -s do bootstrap
INFO tfwrapper : Failed to load or parse file /home/alex/dev/guilds/poc/.run/azure/azureProfile.json. It will be overridden by default settings.
ERROR tfwrapper : Error while getting Azure token, check that you are authorized on this subscription then log yourself in with:
AZURE_CONFIG_DIR=/home/alex/dev/guilds/poc/.run/azure AZURE_ACCESS_TOKEN_FILE=/home/alex/dev/guilds/poc/.run/azure/accessTokens.json az login
I added some debug to understand the issue :
Debug log
→ tfwrapper -d -a melon -e test -r fr-central -s do bootstrap DEBUG tfwrapper : Detected confdir at 'conf' DEBUG tfwrapper : Detected rootdir at '/home/alex/dev/guilds/poc' with 0 parents from . DEBUG tfwrapper : Detected environment 'test' DEBUG tfwrapper : Loading wrapper config from 'conf/config.yml' DEBUG tfwrapper : Loading state config from 'conf/state.yml' DEBUG tfwrapper : Exporting `AZURE_CONFIG_DIR` set to `/home/alex/dev/guilds/poc/.run/azure` directory DEBUG tfwrapper : Exporting `AZURE_ACCESS_TOKEN_FILE` set to `/home/alex/dev/guilds/poc/.run/azure/accessTokens.json` INFO tfwrapper : Failed to load or parse file /home/alex/dev/guilds/poc/.run/azure/azureProfile.json. It will be overridden by default settings. --- Logging error --- Traceback (most recent call last): File "/home/alex/.local/lib/python3.8/site-packages/azure/cli/core/_session.py", line 48, in load with codecs_open(self.filename, 'r', encoding=self._encoding) as f: File "/usr/lib/python3.8/codecs.py", line 905, in open file = builtins.open(filename, mode, buffering) FileNotFoundError: [Errno 2] No such file or directory: '/home/alex/dev/guilds/poc/.run/azure/azureProfile.json'During handling of the above exception, another exception occurred:
Traceback (most recent call last): File “/home/alex/.local/lib/python3.8/site-packages/claranet_tfwrapper/init.py”, line 396, in _get_azure_token profile = get_cli_profile() File “/home/alex/.local/lib/python3.8/site-packages/azure/common/credentials.py”, line 34, in get_cli_profile ACCOUNT.load(os.path.join(azure_folder, ‘azureProfile.json’)) File “/home/alex/.local/lib/python3.8/site-packages/azure/cli/core/_session.py”, line 61, in load self.save() File “/home/alex/.local/lib/python3.8/site-packages/azure/cli/core/_session.py”, line 65, in save with codecs_open(self.filename, ‘w’, encoding=self._encoding) as f: File “/usr/lib/python3.8/codecs.py”, line 905, in open file = builtins.open(filename, mode, buffering) FileNotFoundError: [Errno 2] No such file or directory: ‘/home/alex/dev/guilds/poc/.run/azure/azureProfile.json’
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File “/usr/lib/python3.8/logging/init.py”, line 1081, in emit msg = self.format(record) File “/usr/lib/python3.8/logging/init.py”, line 925, in format return fmt.format(record) File “/home/alex/.local/lib/python3.8/site-packages/colorlog/colorlog.py”, line 135, in format message = super(ColoredFormatter, self).format(record) File “/usr/lib/python3.8/logging/init.py”, line 664, in format record.message = record.getMessage() File “/usr/lib/python3.8/logging/init.py”, line 369, in getMessage msg = msg % self.args TypeError: not all arguments converted during string formatting Call stack: File “/home/alex/.local/bin/tfwrapper”, line 8, in <module> sys.exit(main()) File “/home/alex/.local/lib/python3.8/site-packages/claranet_tfwrapper/init.py”, line 1369, in main state_session = get_session( File “/home/alex/.local/lib/python3.8/site-packages/claranet_tfwrapper/init.py”, line 482, in get_session session = _get_azure_session( File “/home/alex/.local/lib/python3.8/site-packages/claranet_tfwrapper/init.py”, line 449, in _get_azure_session if not _check_azure_auth(subscription_id=azure_subscription): File “/home/alex/.local/lib/python3.8/site-packages/claranet_tfwrapper/init.py”, line 385, in _check_azure_auth return _get_azure_token(subscription_id, tenant_id) is not None File “/home/alex/.local/lib/python3.8/site-packages/claranet_tfwrapper/init.py”, line 407, in _get_azure_token logger.debug(“Failed retrieving Azure profile and token: {}”, e) Message: ‘Failed retrieving Azure profile and token: {}’ Arguments: (FileNotFoundError(2, ‘No such file or directory’),) ERROR tfwrapper : Error while getting Azure token, check that you are authorized on this subscription then log yourself in with:
AZURE_CONFIG_DIR=/home/alex/dev/guilds/poc/.run/azure AZURE_ACCESS_TOKEN_FILE=/home/alex/dev/guilds/poc/.run/azure/accessTokens.json az login
As we can see, my config.yml
is loaded, but the parameter didn’t impact the init phase.
N.B : I used both pyton3.6 & python3.8, but nothing changed.
Then, I did run the az login
locally to my project, init, and then try again to update my config.yml
file.
always_trigger_init to true
DESKTOP-7C704V2: ~/dev/guilds/poc/melon/test/fr-central/do → tfwrapper plan INFO tfwrapper : Azure state backend initialized. INFO tfwrapper : Using Azure user mode WARNING tfwrapper : Using terraform version 1.0.9 INFO tfwrapper : Init has been activated in configInitializing the backend…
Successfully configured the backend “azurerm”! Terraform will automatically use this backend unless the backend configuration changes.
Initializing provider plugins…
Terraform has been successfully initialized!
You may now begin working with Terraform. Try running “terraform plan” to see any changes that are required for your infrastructure. All Terraform commands should now work.
If you ever set or change modules or backend configuration for Terraform, rerun this command to reinitialize your working directory. If you forget, other commands will detect it and remind you to do so if necessary.
No changes. Your infrastructure matches the configuration.
always_trigger_init to false
DESKTOP-7C704V2: ~/dev/guilds/poc/melon/test/fr-central/do → tfwrapper plan INFO tfwrapper : Azure state backend initialized. INFO tfwrapper : Using Azure user mode WARNING tfwrapper : Using terraform version 1.0.9│ Error: Backend initialization required, please run “terraform init” │ │ Reason: Initial configuration of the requested backend “azurerm” │ │ The “backend” is the interface that Terraform uses to store state, │ perform operations, etc. If this message is showing up, it means that the │ Terraform configuration you’re using is using a custom configuration for │ the Terraform backend. │ │ Changes to backend configurations require reinitialization. This allows │ Terraform to set up the new configuration, copy existing state, etc. Please run │ “terraform init” with either the “-reconfigure” or “-migrate-state” flags to │ use the current configuration. │ │ If the change reason above is incorrect, please verify your configuration │ hasn’t changed and try again. At this point, no changes to your existing │ configuration or state have been made. ╵
As we can see, the always_trigger_init
value change is well loaded during the tfwrapper plan
and the value do impact the behaviour of tfwrapper.
Now, if I delete the ~/project/.run/azure
, I’m facing again the issue with the Azure Token which is not loaded, no maters if i put true
, false
, any other word or delete the line.
Do you have an idea what can I do wrong ? Right now, I’m completly stuck.
Thanks, Regards
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (6 by maintainers)
Hi @pdecat
Thank you for the quick fix, it works perfectly fine ! Regards
Hi @Ston9, you’re welcome 😉
Fixed released in v8.1.1