amazon-web-servicesamazon-cloudwatchterraform

Using one terraform inventory into another terraform script


I am trying to write a separate Terraform script for AWS CloudWatch alerts apart from creating AWS instances, I want to use the inventory of a different Terraform script which builds AWS instances. How do I access the inventory of one script and use it in the CloudWatch alerts script?


Solution

  • This is possible if you are using remote state. You will have to use root-level outputs to expose the values you want to be able to access from the second Terraform state (in your example, the aws_instance ids, most likely). You can then use the terraform_remote_state data source in your second terraform configuration to access those outputs.