English 中文(简体)
如何通过Terraform增加现有资源小组的新事例?
原标题:How to add new instances in existing resource group in Azure via Terraform?

我愿在现有的资源小组中增加一个新的证书,该小组已经包含3个证书。 虽然使用拖拉机,但它留下了一个错误,表明资源组已经存在。

问题回答

https://github.com/Azure/terraform-azurerm-compute”rel=“nofollow noreferer”

provider  "azurerm"  {
  features  {}
}
data "azurerm_resource_group" "example" {
  name = "Existing-RG-Name" 
}
module "linuxservers" {
  source              = "Azure/compute/azurerm"
  resource_group_name = data.azurerm_resource_group.example.name
  vm_os_simple        = "UbuntuServer"
  public_ip_dns       = ["linsimplevmips"]
  vnet_subnet_id      = module.network.vnet_subnets[0]
}
    

我愿在现有的资源小组中增加一个新的证书,该小组已经包含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: enter image description here

Reference: Data Source: azurerm_resource_group





相关问题
Windows Azure WorkerRole response

I am working on an Azure demo to run Powershell in a worker role. In my web role I add the name of the Powershell script which is to be run to a CloudQueue object. I can print the script output to ...

Windows Azure WebRole stuck in a deployment loop

I ve been struggling with this one for a couple of days now. My current Windows Azure WebRole is stuck in a loop where the status keeps changing between Initializing, Busy, Stopping and Stopped. It ...

Getting a token for Windows Azure

We are looking at Windows Azure, but getting a token appears to be hard now, at least that s what I m seeing in web searches. Anyone tried it or know how to accelerate that process? Any idea how long ...

Developing Azure .Net 4.0 Applications

Presently .Net 4.0 is not supported on Azure. This thread indicates that you will not be able to use .Net 4.0 with VS 2010 until it is supported in the cloud. http://social.msdn.microsoft.com I d ...

.NET 4.0 on Windows Azure?

My google-fu is failing me on this one. As a possible solution to Unit Testing .NET 3.5 projects using MStest in VS2010 (but I ve put this in a seperate question because it s kind of unrelated): Is ...

热门标签