xeet
xeet

Reputation: 163

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.

Upvotes: 0

Views: 642

Answers (2)

Nathan Smith
Nathan Smith

Reputation: 8347

If the EC2 instances don't need to be created prior to the Elasticsearch domain, you can use the template provider and render the file based on the values of the Elasticsearch resource, render and copy up to the EC2 instances.

Upvotes: 0

StephenKing
StephenKing

Reputation: 37630

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.

Upvotes: 1

Related Questions