-
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
Data Source template_file causes resource to be recreated each execution. #8316
Comments
Hi @kristjanelias! Sorry for this strange behavior. I think what you've run into here is the issue discussed in #8077. If so, the issue is that your The fix is to escape the interpolations in the template string so that Terraform core won't try to parse them. By the time they get passed to the template data source itself, they will have been unescaped and should work as expected: variable "vpc_cidr_base" { default = "172.30" }
data "template_file" "private_reverse_zone_name" {
template = "$${second}.$${first}.in-addr.arpa"
vars {
first = "${element(split(".", var.vpc_cidr_base), 0)}"
second = "${element(split(".", var.vpc_cidr_base), 1)}"
}
}
resource "aws_route53_zone" "reverse_private" {
name = "${data.template_file.private_reverse_zone_name.rendered}"
comment = "${var.vpc_cidr_base} - Reverse Zone"
vpc_id = "${var.aws_default_vpc_id}"
tags { Name = "${data.template_file.private_reverse_zone_name.rendered}" }
} I'm going to close this issue to consolidate discussion around #8077, but do feel free to re-open it if the above workaround doesn't work or you think that there's more here than what #8077 covers. |
Thanks @apparentlymart, workaround worked like a charm! |
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. |
Hi,
I have upgraded to Terraform v0.7.0 and now refactoring some of my code.
Changed template_file resource to data source but now i am seeing that my resource get regenerated each execution. I will try to illustrate my example the best i can for my concearn to come through.
Use-case: Create a reverse lookup zone in aws route53 using a domain name generated within a template.
Code:
Statefile after apply:
Plan after initial apply:
As you can see the route53 zone resource will not be regenerated with the next apply.
Code:
Statefile after apply:
Plan after initial apply:
So you see after switching to data source my route53 zone gets recreated on every apply.
Is this expected behaviour and i am doing something wrong or is this not supposed to be so?
I hope you can help resolving this conundrum...
The text was updated successfully, but these errors were encountered: