Answers: <p>Using a remote state file and referencing the state from a different state template would be the way I would go. Would need to add an output to resource that needs to be shared as well as configuring remote state storage, access controls, and security. 
  This URL has example of setting up the remote backend in azureRM.
  <a href="https://www.terraform.io/docs/backends/types/azurerm.html" rel="nofollow noreferrer">https://www.terraform.io/docs/backends/types/azurerm.html</a></p>
  
Answers: CC BY-SA 4.0
Answers: 2020-01-13T21:51:51.003Z
Answers: 2020-01-13T21:51:51.003Z
Answers: bbergvt
Body: <p>I need to reference my VNET Gateway residing in an infrastructure folder, in a VPN folder in order to connect a VPN utilising a Local Network Gateway, but these could be any object in Azure for the sake of argument. These folders both use seperate state files hosted in Azure blob storage.  </p>
  
  <p>What would be the best way to go about calling this VNET Gateway's ID in another folder? The usual methods of using e.g "module.vnet_gateway.id" or e.g "data.azurerm_vnet_gateway.id" won't work in this scenario. </p>
  
  <p>I've considered some way of referencing it by name, which I know, and pulling the id as an output, but I'm not certain this is the best method.  </p>
  
  <p>I've read about using remote-state, which I assume as per the guides on Google would involve creating a data-source pointed to my specific state file for "inf", and then pulling the data back, but I've yet to find a good example on Azure of how to achieve this. </p>
  
  <p>Any pointers or examples StackExchange could provide to get me in the right direction?</p>
  
Tags: <terraform><azure-devops><azure>
Title: Calling a Terraform object in seperate folder
UserDisplayName: Giles
ThreadText: # Calling a Terraform object in seperate folder
  
  (Asked by: username_0 on 2020-01-13)
  
  I need to reference my VNET Gateway residing in an infrastructure folder, in a VPN folder in order to connect a VPN utilising a Local Network Gateway, but these could be any object in Azure for the sake of argument. These folders both use seperate state files hosted in Azure blob storage.
  
  What would be the best way to go about calling this VNET Gateway's ID in another folder? The usual methods of using e.g "module.vnet\_gateway.id" or e.g "data.azurerm\_vnet\_gateway.id" won't work in this scenario.
  
  I've considered some way of referencing it by name, which I know, and pulling the id as an output, but I'm not certain this is the best method.
  
  I've read about using remote-state, which I assume as per the guides on Google would involve creating a data-source pointed to my specific state file for "inf", and then pulling the data back, but I've yet to find a good example on Azure of how to achieve this.
  
  Any pointers or examples StackExchange could provide to get me in the right direction?
  
  **Tags:** terraform, azure-devops, azure
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-01-13. Score: 2
  
  Using a remote state file and referencing the state from a different state template would be the way I would go. Would need to add an output to resource that needs to be shared as well as configuring remote state storage, access controls, and security.
  This URL has example of setting up the remote backend in azureRM.
  <https://www.terraform.io/docs/backends/types/azurerm.html>
  
  
  ---
  
  