简体   繁体   中英

How to manage existing resource group in azure with terraform

I am having my azure infrastructure created using terraform.

Now I want to add few resources to existing resource group.

When I did same it is giving error like resources group is already exists.

How can I refer existing resource and no changes to existing resources and tfstate file.

There is a couple of ways to refer existing resource in Azure without making changes.

Terraform import example :

resource "azurerm_resource_group" "example" {
    # ...instance configuration...
    name = "MyResourceGroup"    
}

Run command: terraform import azurerm_resource_group.example \ /subscriptions/MySubscriptionNumber/resourceGroups/MyResourceGroup

Terraform data resource example :

data "azurerm_resource_group" "example" {
  name = "MyResourceGroup"
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM