-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
External Data Source always forcing a replacement #22005
Comments
Seems my issue is related to #12326. |
Hi @cyrus-mc! Sorry for this surprising behavior. Currently In your case, the answer would be to represent the dependency on data "external" "get_key" {
program = [ "${path.module}/get_flux_key.sh" ]
query = {
kubeconfig = var.kubeconfig
# This is not used, but ensures that the read will be deferred until
# after the deployment is done.
deployment = null_resource.deployment.id
}
} The tracking issue for this limitation is #17034, which also includes a proposed architecture change that would address it. We're hoping to address it in a future major version of Terraform, but the changes required are quite invasive to Terraform's internals so we won't be able to tackle this in the near future without disturbing other work in progress. Since we already have #17034 open, I'm going to close this issue just to consolidate the discussion over there. Thanks for reporting this, and I hope the above workaround will work for you in the meantime. |
Have a quick follow-up on this. resource "local_file" "kubeconfig" {
content = var.kubeconfig
filename = "${path.module}/kubeconfig"
}
data "external" "get_key" {
program = [ "${path.module}/get_flux_key.sh" ]
query = {
kubeconfig = local_file.kubeconfig.filename
null_resource_id = null_resource.deployment.id
}
} So for get_flux_key to run resource local_file "kubeconfig" must have already been created. But I am finding that during the plan stage it tries to refresh the external data source (so run get_flux_key.sh) - which just ends up failing. |
Assuming it runs because filename is known at plan time. What I really need is a way to run only when the file has actually been written to disk. |
@cyrus-mc - I am experiencing a very similar issue (terraform 0.12.3)
flux script:
Error:
I have also tried using the implicit dependency without the Just wanted to share in case you had found a solution. |
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. |
Terraform Version
Terraform Configuration Files
The script get_flux_key.sh simply returns an SSH key (which is stable, calling that function over and over returns the same output.
When I run the above it always reports the following plan.
Expected Behavior
If my understanding of the external data source is correct it should behave just like any other attribute. Only force a replacement when the value changes.
Actual Behavior
As shown above, resource local_file constantly wants to be replaced because the value for ssh_key isn't know until apply.
The text was updated successfully, but these errors were encountered: