Search code examples
templatesterraformfile-copyingterraform-provider-aws

Manipulate a file before provisioning in terraform


So I have created a terraform script that does the following:

  1. Spins up an EC2 instance
  2. Copies over some files
  3. Run some remote commands to install stuff from repos
  4. Creates an elasticsearch service domain

Now I need to configure the ec2 instance with the endpoint I get back from elasticsearch domain, so the application are using the right endpoint (currently it has some default value).

How can I pass the endpoint value into the file and then copy it over to the ec2 instance. What would be the recommended approach?

Thanks in advance.


Solution

  • Terraform will derive the order automatically, when you refer to the output of a certain resource. You can use the file provisioner to create files on the EC2 instance.