Description
Terraform 0.9.8
Background: Terraform likes to fully manage the resources it creates, and goes somewhat to trying to reconcile their latest state by doing a refresh/fact-find before issuing a plan or applying a plan. This is great behaviour. Its also great that terraform can easily spin up an environment in its entirety, and this is very useful for creating dev, prod environments very easily.
However certain development workflows involve subsequent changes to these resources which terraform is not necessarily good at handling itself, maybe because its current api support isnt good enough, or maybe because some things are complex to manage.
An example of this (but not limited to the AWS provider) is the aws_rds_cluster resource. We regularly restore a snapshot (which creates a different aws rds cluster, as you can never restore over the top of an existing cluster in aws), and then update dns and/or apps to point to the new cluster for a seamless db upgrade. Then we delete the old database, but not the dns records. Putting aside the fact that terraform's aws_rds_cluster resource for doing this has bugs preventing a successful restore from a snapshot anyway, assuming it would work, this is very unwieldy in terraform, and perhaps even impossible currently.
Suppose then the initial aws_route53_record sensibly looks like this:
resource "aws_route53_record" "dbreader" {
...
records = ["${aws_rds_cluster.foo.reader_endpoint}"]
...
lifecycle = {
ignore_changes = ["*"]
}
}
The dns records managed by terraform point originally to aws_rds_cluster.foo.reader_endpoint - but now that database has been removed one of the following happens:
-
terraform needs to create the aws_rds_cluster again for it to be able to supply the aws_route53_record resource with the record field, despite ignore_changes being present.
-
if count=0 is set on the aws_rds_cluster (now deleted), then terraform will complain that aws_rds_cluster is no longer found wrt to the records field in aws_route53_record.
-
if count=0 is set on both aws_rds_cluster and aws_route53_record, terraform will attempt to delete the record resource, resulting in downtime within the system
In short, ignore_changes ignores changes in the apply phase, but not during the validate phase.
I believe this workflow would be solved if it is possible to add a lifecycle flag which would refuse to refresh resources. That way terraform would always rely on the statefile and not need to make any changes at all, regardless of what had happened to the actual resources. A kind of refresh=false
flag, which affected a resource, and all its dependencies.
I would welcome any comments - perhaps you can already do what I am after..