Conditional run for data.external resource

Hello,

I have following code.

resource "random_id" "this" {
  byte_length = 4
}

data "external" "this" {
  program = ["/bin/sh", "-c", "./script.sh ${random_id.this.hex}"]
}

# Put result to state
resource "null_resource" "state" {
  triggers = {
    key = data.external.this.result.key
  }

  lifecycle {
    ignore_changes = [triggers]
  }
}

I’m need to run data.external resource only once due API architecture because second call with same param will fail. Is it possible to do it somehow only during creation of random_id.this resource?

I cannot think of a way to do this … there may be some obscure trick that I’m missing, but I think you’ve arrived at the point where you should write a custom Terraform provider.

It may be more work to start with, but it will free you from having to chain together terraform-provider-external and terraform-provider-null in complex ways.

Sad to hear this because I was sure that some trick exist to workaround this issue. :frowning: