2

I have created two Terraform modules, each creating a simple AWS instance and then provisioning some software on it with an Ansible playbook. Each module works correctly when running terraform apply in the module directory.

How would you combine these two modules in a shell script to create both instances, run some tests and then destroy the ressources.

In my mind the shell script would be like this :

terraform apply --reference=module1-dir --state=module1-state
terraform apply --reference=module2-dir --state=module2-state
<run some other scripts ...>
terraform destroy --reference=module1-dir --state=module1-state
terraform destroy --reference=module2-dir --state=module2-state

Is this the correct way to do it ? Does Terraform support referencing another directory to fetch the files to run ?

JohnLoopM
  • 151
  • 6

1 Answers1

3

You can use terraform to target a certain module in a directory. So if you know I need two modules

module "one" {}
module "two" {}

You can run terraform apply -target module.one -target module.two

It can source the same module with different inputs.

Mike
  • 21,910
  • 7
  • 55
  • 79