2
votes

Is there a way to create multiple resources in terraform?

if i want to create 3 resource groups and call them rg1, rg2, rg3 what is the syntax to do this?

I have tried the below but it doesn't work

  resource "azurerm_resource_group" "rg" {
  name = "rg",count
  location = "west europe"
  count = "3"
}
1
What error do you get? I think you just need name = "rg${count.index + 1}".ydaetskcoR

1 Answers

2
votes

I worked it out myself. You need to use count,index as below

resource "azurerm_resource_group" "rg" {
  name = "rg${count.index}"
  location = "west europe"
  count = "3"
}