-
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
template_file data always read during plan/apply if resource inside module #26290
Comments
Hi @kostiukolex, thanks for reporting this. I'm not able to reproduce the issue you're seeing. Here's the configuration I'm using: main.tf: module "hello-alisdair" {
source = "./hello"
name = "alisdair"
}
output "hello" {
value = module.hello-alisdair.greeting
} hello/main.tf: variable "name" {
type = string
}
data "template_file" "hello" {
template = file("${path.module}/hello.tpl")
vars = {
name = var.name
}
}
output "greeting" {
value = data.template_file.hello.rendered
} hello/hello.tpl:
Applying the configuration creates the correct output: $ terraform-0.13.3 apply -auto-approve
module.hello-alisdair.data.template_file.hello: Refreshing state...
Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
Outputs:
hello = Hello, alisdair! Plan does not reread the $ terraform-0.13.3 plan
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.
module.hello-alisdair.data.template_file.hello: Refreshing state... [id=d0c1be373e8b11ba8f69ded55954fcfba70daae3c8f59512267e590ca4d9b546]
------------------------------------------------------------------------
No changes. Infrastructure is up-to-date.
This means that Terraform did not detect any differences between your
configuration and real physical resources that exist. As a result, no
actions need to be performed. Can you adjust this simple configuration to cause the problem to reappear, so that we can see what is causing the issue? |
Hi @alisdair, thanks for answer I found some points, why it's happens in my side. So, i have some module, which creates ECS task definition with some variables - outputs from another terraform modules (db endpoint, for example). main.tf
rds.tf
test/main.tf
test/templates/container-definition.tmpl
$ terraform plan
$ terraform apply -auto-approve
Besides, i use Data Source: aws_acm_certificate, which in terraform 0.13 change itself id during every plan/apply. This leads to reread template file in some modules
|
While I still can't reproduce this with incomplete configuration, I think I understand what's happening now. I think that Terraform is detecting possible changes in the template file data source's configuration due to depending on the module output. If any input to the template resource changes, this causes it to be refreshed. Does this make sense in your case? For a similar issue, which we believe will be addressed as part of the 0.14 release, see #26316. I also want to point out that the |
hi @alisdair I rewrote my modules to use the |
We made some changes as part of 0.13 regarding refresh during plan, which results in more data sources being refreshed than in 0.12. This would normally be a non-issue, but for some data sources which always result in changes on read, it has caused some understandable confusion. As I alluded to earlier, refresh and plan are being worked on as part of 0.14, which should improve this for many situations. Since it seems like you're unblocked with the |
@alisdair I am not using the template data source, just the AWS data provider, but getting a very similar issue after upgrading to 0.13. It seems like the issue occurs when the data provider gives a transient id field. Input inside module definition:
Output:
If I'm doing something suboptimal or there's a better wayto get the list of AZ's that doesn't cause the issue I'm happy to use it. |
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
outside module resource
inside module resources
Expected Behavior
terraform plan/apply
should not displaytemplate_file
data if nothing to changeActual Behavior
Steps to Reproduce
terraform init
terraform plan
Additional Context
I recently upgraded terraform to
0.13.2
. Previously I used0.12.28
, but thetemplate
provider version was the same.With flag
-refresh=false
template_file data not reading.template_file data resource not read during plan if it outside module
References
I sow similar issue(#26100), but there data sources depends on count.
The text was updated successfully, but these errors were encountered: