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

Don't print a warning if there is no message #30

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

jangrewe
Copy link

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

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

beelit94 commented Jan 24, 2018

@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
Copy link
Owner

ping @jangrewe :)

@jangrewe
Copy link
Author

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.

@kirankotari
Copy link
Collaborator

kirankotari commented May 27, 2021

@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

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

Successfully merging this pull request may close these issues.

3 participants