I want to create a new WebApp resource into existing resource group. this question and this post explains how we can import existing resource ( instead of creating new one every time)
I was able to import my existing resource group using below command
terraform import azurerm_resource_group.rg-myResourceGroup /subscriptions/00000-my-subscription-id-0000000/resourceGroups/rg-myResourceGroup
After executing this command I can see new file is created named 'terraform.tfstate'
Below is content of the file.
{
"version": 3,
"terraform_version": "0.11.11",
"serial": 1,
"lineage": "-----------------------------",
"modules": [
{
"path": [
"root"
],
"outputs": {},
"resources": {
"azurerm_resource_group.rg-ResourceGroupName": {
"type": "azurerm_resource_group",
"depends_on": [],
"primary": {
"id": "/subscriptions/subscription-id-00000000000/resourceGroups/rg-hemant",
"attributes": {
"id": "/subscriptions/subscription-id-00000000000/resourceGroups/rg-hemant",
"location": "australiaeast",
"name": "rg-ResourceGroupName",
"tags.%": "0"
},
"meta": {},
"tainted": false
},
"deposed": [],
"provider": "provider.azurerm"
}
},
"depends_on": []
}
]
}
Now my question is how can I access/refer/include terraform.tfstate
in my main.tf
resource "azurerm_resource_group" "rg-hemant" {
#name = it should be rg-ResourceGroupName
#location = it should be australiaeast
}
UPDATE 1
- Assume that in my subscription '
mysubscription1
' there is a resource group 'rg-exising
' - This resource group already have few resources e.g.
webapp1
,storageaccount1
- Now I want to write a terraform script which will add new resource ( e.g. newWebapp1 ) to existing resource group 'rg-existing'
so after
terraform apply
operationrg-exising
should have below resources- webapp1
- storageaccount1
- newWebapp1 ( added by new
terraform apply
script )
4) Note that I don't want terraform to create ( in case of apply
) OR delete ( in case of destroy
) my existing resources which belongs to rg-exising