python-terraform icon indicating copy to clipboard operation
python-terraform copied to clipboard

Don't print a warning if there is no message

Open jangrewe opened this issue 7 years ago • 4 comments

Only output a warning for return code 2 (changes to be applied) if stderr actually contains a string.

jangrewe avatar Jan 24 '18 10:01 jangrewe

@jangrewe thank you for the PR, Could you provide me a sample tf file the will cause return code to 2 and error message is None? I can add it to the test

beelit94 avatar Jan 24 '18 20:01 beelit94

ping @jangrewe :)

beelit94 avatar Jan 26 '18 08:01 beelit94

Uhm, i'm not that deep into the state files you're using for testing, but in theory anything that would cause Terraform to want to apply a change should trigger this behaviour - or rather: not anymore now.

jangrewe avatar Jan 29 '18 09:01 jangrewe

@beelit94 tf.plan() return code 2 in the following scenario.

In [36]: cmds = ['terraform', 'plan', '-no-color', '-input=false', '-detailed-exitcode']

In [37]: p = subprocess.Popen(
    ...:             cmds, stdout=stdout, stderr=stderr, cwd=working_folder, env=environ_vars
    ...:         )

In [38]: out, err = p.communicate()

In [39]: p.returncode
Out[39]: 2

In [40]: err
Out[40]: b''

Found following in the terraform link terraform exit codes

0 = Succeeded with empty diff (no changes)
1 = Error
2 = Succeeded with non-empty diff (changes present)

Simple Terraform Script

provider "docker" {}

resource "docker_image" "nginx" {
  name         = "nginx:latest"
  keep_locally = true
}

resource "docker_container" "instance_name" {
  name = var.instance_name
  image = docker_image.nginx.latest
  ports {
    internal = 80
    external = var.port
  }
}

here is my workspace tree

[root@localhost test]# tree .
.
|-- nginx_inputs.tf
|-- terraform.tfstate.d
|   `-- QIVQL7WSL0
|-- vars.tf
`-- versions.tf

kirankotari avatar May 27 '21 12:05 kirankotari