Azure - Terraform - Sharing/using existing resources (not importing)


I’m fairly new to Terraform and I’ve been working through various guides and tutorials.

I’m at the stage where I can build resource groups with resources, but I would like to know how to add to the existing resources I’ve built with Terraform. Where I’m struggling is to understand how I add new resource groups, with resources such as a virtual machines, but use existing resources in another resource group, such as network resources. Can anyone point me in the direct of the specific documentation or video clips that could help me, please?

I’ve been doing net searches to try and find more information, but I feel I’m not using the correct terms as the results tend to be about importing existing Azure resources, which isn’t what I’m looking for.

Any guidance most welcome.


I posted this a few days ago and since then I think I worked this out using modules.

It can be closed, if that’s done on here.

Is the following document helpful?

You can refer to the existing resource by data as shown below.

$ cat
provider "azurerm" {
  version = "~>2.0"
  features {}

data "azuread_application" "example" {
  name = "example"

output "app_id" {
  value = data.azuread_application.example.application_id

terraform apply, you can get the information of existing resources as shown below.

$ terraform apply
$ terraform output
app_id = *****-*****-****