Skip to content

plan -detailed-exitcode returns 2 with external provider even if there is no change #16055

@sjwl

Description

@sjwl

Terraform Version

0.10.4

Terraform Configuration Files

data "external" "foo" {
  depends_on = ["null_resource.test"]
  program = ["bash", "${path.module}/test.sh"]
}

resource "null_resource" "test" {
}
output "foo" {
  value = "${data.external.foo.result["foo"]}"
}

(test.sh)

#!/bin/bash

jq -n --arg foo "bar" '{"foo":$foo}'

Expected Behavior

terraform plan -detailed-exitcode should return 0 in this case.

Actual Behavior

it's returning 2

> terraform plan -detailed-exitcode
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.

null_resource.test: Refreshing state... (ID: 910628614195011957)

------------------------------------------------------------------------

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
 <= read (data resources)

Terraform will perform the following actions:

 <= data.external.foo
      id:        <computed>
      program.#: "2"
      program.0: "bash"
      program.1: "/Users/slee1/tmp/tf/ext-prov-detailed-exitcode/test.sh"
      result.%:  <computed>


Plan: 0 to add, 0 to change, 0 to destroy.

------------------------------------------------------------------------

Note: You didn't specify an "-out" parameter to save this plan, so Terraform
can't guarantee that exactly these actions will be performed if
"terraform apply" is subsequently run.

 > echo $?
2

Steps to Reproduce

  1. terraform init
  2. terraform apply
  3. terraform plan -detailed-exitcode
  4. echo $?

Notes

If depends_on is removed from the external provider stanza, then the exit code becomes 0. However, that is not a viable workaround when depends_on is actually necessary.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions