【发布时间】:2019-05-16 09:45:05
【问题描述】:
我想在现有资源组中创建一个新的 WebApp 资源。 this question 和 this post 解释了我们如何导入现有资源(而不是每次都创建新资源)
我可以使用以下命令导入我现有的资源组
terraform import azurerm_resource_group.rg-myResourceGroup /subscriptions/00000-my-subscription-id-0000000/resourceGroups/rg-myResourceGroup
执行此命令后,我可以看到创建了名为'terraform.tfstate' 的新文件。下面是文件的内容。
{
"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": []
}
]
}
现在我的问题是如何在我的main.tf 中访问/引用/包含terraform.tfstate
resource "azurerm_resource_group" "rg-hemant" {
#name = it should be rg-ResourceGroupName
#location = it should be australiaeast
}
更新 1
- 假设在我的订阅“
mysubscription1”中有一个 资源组“rg-exising” - 此资源组已经有很少的资源,例如
webapp1,storageaccount1 - 现在我想写一个 terraform 脚本来添加新的 资源(例如 newWebapp1 )到现有资源组 'rg-现有'
-
所以
terraform apply操作后rg-exising应该有 以下资源- webapp1
- storageaccount1
- newWebapp1(由新的
terraform apply脚本添加)
4) 请注意,我不希望 terraform 创建(在apply 的情况下)或删除(在destroy 的情况下)我属于rg-exising 的现有资源
【问题讨论】:
-
访问是什么意思?你是说你想让 Terraform 开始管理资源组,以便它可以修改和删除它?还是因为您希望能够与其他资源一起引用它?
-
@ydaetskcoR,请查看更新1