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 using depends_on with splat output from external provider #21151

Closed
thomasinsel opened this issue Apr 29, 2019 · 4 comments
Closed

Problem using depends_on with splat output from external provider #21151

thomasinsel opened this issue Apr 29, 2019 · 4 comments

Comments

@thomasinsel
Copy link

I don't think this is specific to the external provider, but it's the simplest way to demonstrate the problem.

Terraform Version

Terraform v0.11.13

Terraform Configuration Files

locals {
  fruit = [
    "apple",
    "banana"
  ]
}

resource "null_resource" "foo" { }

data "external" "cat" {
  count = "${length(local.fruit)}"
  depends_on = [ "null_resource.foo" ]
  program = [ "cat" ]
  query = {
    fruit = "${local.fruit[count.index]}"
  }
}

Expected Behavior

fruits = [
    apple,
    banana
]

Actual Behavior

* output.fruits: Resource 'data.external.cat' does not have attribute 'result.fruit' for variable 'data.external.cat.*.result.fruit'

Steps to Reproduce

I'm trying to use an external provider to transform a list. In the real world, this would be converting a list of hostnames to IP addresses. In the example, I just use cat to do nothing. Since I want a list instead of a list of maps, I use output ${data.external.cat.*.result.fruit}.

If I comment out the depends_on line and run terraform init && terraform apply, everything works as expected.

But, with depends_on it gives the error above.

Also, ${data.external.cat.*.result} works fine in either case.

@jbardin
Copy link
Member

jbardin commented Apr 29, 2019

Hi @thomasinsel,

Sorry about the unexpected behavior here, but the depends_on meta argument is not really useful on a data source (see https://www.terraform.io/docs/configuration/data-sources.html#data-resource-dependencies).

We're tracking this case in #18600, and a proposal for changing the lifecycle of data sources in #17034.

@jbardin jbardin closed this as completed Apr 29, 2019
@thomasinsel
Copy link
Author

thomasinsel commented Apr 29, 2019

Got it @jbardin, but could you tell me the recommended method to ensure that a custom executable used for an external provider exists?

My plan would have been to make the data provider depend on a local_file resource.

Thanks!

@apparentlymart
Copy link
Contributor

@thomasinsel generating a program with local_exec and then immediately running it with external isn't really a use-case these mechanisms were designed for, but I think you could make it work by using a reference to the other resource rather than using depends_on:

resource "local_file" "example" {
  filename = "${path.module}/example"
  content  = "..."
}

data "external" "example" {
  program = ["${local_file.example.filename}"]
}

local_file currently generates a file with executable permissions set on Unix systems, but that is an implementation detail rather than contract and so may change in a future version, depending on how hashicorp/terraform-provider-local#3 is resolved. If you do the above, be sure to pin your local provider dependency to a specific version to be sure that a future change in that area won't break your configuration.

@ghost
Copy link

ghost commented Jul 26, 2019

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Jul 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants