I am using AWS provider to create an Elasticsearch domain. I am calling terraform from a Lambda function and I don’t want to wait for 12 extra minutes for the domain to be completed. Is there a way to set the resource ID or otherwise tell terraform that resource is creation is complete? (hopefully without having to customize my provider).
I plan to do a terraform refresh for that resource after I it had completed creation, but I am trying to save Lambda processing time while keeping all my resources in the same state file.
Hi @jmalachoCTP,
There is no way built in to Terraform to ask it to exit without waiting for a remote object to be confirmed created, because in common Terraform usage there will tend to be other operations depending on the result of that operation and thus no further work would be possible.
Unfortunately I think the closest you could get to what you are trying for with current Terraform is to create the elasticsearch domain some other way – via the AWS CLI, perhaps – and then use terraform import
to connect that object id with the resource declared in your Terraform configuration. That rather seems to defeat the object though, since Terraform won’t really be doing anything with the elasticsearch domain in that case.
My answer above is trying to accommodate your requirement that everything be in the same state file, but honestly in situations like yours where there are multiple “phases” to deal with my instinct would be to write a separate configuration with a separate state for each one, because then it’s easier to orchestrate the steps knowing that each step is isolated from the others, and we can use data sources to pass data between the steps… we can just use normal terraform apply
for each one, rather than developing a non-standard workflow.
I’d also like to note that Lambda isn’t really an ideal environment for Terraform to run in because if Terraform is interrupted before it runs to completion that could result in an inconsistent state: Terraform current commits a snapshot of the current state to the backend only at completion or if it’s explicitly interrupted with SIGINT
. It’s been a while since I tried running Terraform in Lambda so perhaps things have changed in the meantime, but in my earlier experiments I found that Lambda could potentially just issue Terraform a SIGKILL
with no prior signals, giving it no opportunity to commit a snapshot of the in-memory state.
Thank you Martin for your reply. The answer is what I expected.