我愿在现有的资源小组中增加一个新的证书,该小组已经包含3个证书。 虽然使用拖拉机,但它留下了一个错误,表明资源组已经存在。
If you want to create a VM in an existing resource group
instead of creating a new resource, you can use a data block to import the existing resource group
.
Here is the updated Terraform
code for creating 3 resources in an existing Resource Group.
provider "azurerm" {
features {}
}
data "azurerm_resource_group" "example" {
name = "Existing-RG-Name"
}
resource "azurerm_virtual_network" "vnet" {
name = "venkat-vnet"
address_space = ["10.0.0.0/16"]
location = data.azurerm_resource_group.example.location
resource_group_name = data.azurerm_resource_group.example.name
}
resource "azurerm_subnet" "subnet" {
name = "vm-subnet"
resource_group_name = data.azurerm_resource_group.example.name
virtual_network_name = azurerm_virtual_network.vnet.name
address_prefixes = ["10.0.1.0/24"]
}
resource "azurerm_network_interface" "samplenic" {
name = "VM-nic"
location = data.azurerm_resource_group.example.location
resource_group_name = data.azurerm_resource_group.example.name
ip_configuration {
name = "internal"
subnet_id = azurerm_subnet.subnet.id
private_ip_address_allocation = "Dynamic"
}
}
resource "azurerm_windows_virtual_machine" "myvm" {
name = "venkat-vm"
location = data.azurerm_resource_group.example.location
resource_group_name = data.azurerm_resource_group.example.name
network_interface_ids = [azurerm_network_interface.samplenic.id]
size = "Standard_B1ls"
admin_username = "Venkat"
admin_password = "Password1234!"
os_disk {
name = "VM-osdisk"
caching = "ReadWrite"
storage_account_type = "Standard_LRS"
}
source_image_reference {
publisher = "MicrosoftWindowsServer"
offer = "WindowsServer"
sku = "2019-Datacenter"
version = "latest"
}
}
Terraform Apply:
Reference: Data Source: azurerm_resource_group