Don't print a warning if there is no message
Only output a warning for return code 2 (changes to be applied) if stderr actually contains a string.
@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
ping @jangrewe :)
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.
@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