Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem when using inside IDE #92

Open
mateuszzz88 opened this issue Dec 23, 2020 · 3 comments
Open

Problem when using inside IDE #92

mateuszzz88 opened this issue Dec 23, 2020 · 3 comments

Comments

@mateuszzz88
Copy link

Hello,
I have python script that successfully runs from console

  • I did az login
  • I have main.tf
  • scripts does create resources and then destroys them.
  • and it all works.

However when run from IDE (in my case JetBrains clion) I get errors like this:

Error: Error building account: Error getting authenticated object ID: Error parsing json result from the Azure CLI: Error unmarshaling the result of Azure CLI: invalid character '\x1b' after top-level value

  on main.tf line 1, in provider "azurerm":
   1: provider "azurerm" {
(...)

WARNING:python_terraform:error: b"\x1b[31mThe output variable requested could not be found in the state\nfile. If you recently added this to your configuration, be\nsure to run `terraform apply`, since the state won't be updated\nwith new output variables until that command is run.\x1b[0m\x1b[0m\n"

Do you have an idea what am I doing wrong?

@mateuszzz88
Copy link
Author

more concretely first part of error stems from

    t = Terraform(working_dir=working_dir)
    t.init('./')

    applyVariables = {
        'system': system,
        'disk_size': disk_size,
        'disk_type': disk_type,
        'tag': tag,
        'vm_count': vm_count,
        'vm_size': vm_size,
        'username': username,
        'allowed_connection_ip': allowed_connection_ip,
        'enable_firewall': enable_firewall,
        'ssh_pubkey': ssh_pubkey
    }
    print(applyVariables)

    print('############ Applying... ############')
    _long_procedure_message()
    ret_code, stdout, stderr = t.apply('./', no_color=IsFlagged, skip_plan=True, var=applyVariables, capture_output=False)

The warning comes from

returnValue = t.output('vm_network_values', full_value=True)

@mateuszzz88
Copy link
Author

I still have this problem, I reproduce it very reliably on pycharm and clion both, on two different computers.

  • enabling/disabling capture_output doesn't help
  • enabling/disabling no_color doesn't help either
  • executing inside my script (in IDE) subprocess.run(['terraform','plan']) has the same problem, so probably this is not library's bug.

I think it "should" be caused by some env flag set in IDE, but I couldn't reproduce it in console by replicating environment.

@jon-dennis
Copy link

I had the same problem running terraform plan under the Azure CLI. I found it can be resolved by setting an environment variable in the PyCharm Run Configuration as follows:
AZURE_CORE_NO_COLOR=1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants