English 中文(简体)
Terrafom——经理人。
原标题:Terrafom - manager providers.tf for multiple subscriptions

我正在使用地形图管理订阅(子1)。

我有这个档案:

散射供应商。 tf

terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = ">= 2.25"
    }
  }

  required_version = ">= 0.16.8"

  backend "azurerm" {
    resource_group_name  = "my.resource_group"
    storage_account_name = "my.storage_account_name "
    container_name       = "my.container_name"
    key                  = "my.terraform.tfstate"
  }
}

provider "azurerm" {
  features {}
}

Inside my subscription (sub1) I have the resource group "my.resource_group" where I have my storage account "my.storage_account_name ", container "my.container_name" and where I keep my tfstates.

我想管理新的订阅(第2款),可能也做同样的事来保存这些笔记。 也就是说,在本次级2内设立一个新的资源小组,一个新的储存账户,一个新集装箱,并存放在该账户内。

我希望能够利用梯田在子1或次2内创造资源,并在我使用的订阅中保留斜线。

How can I achieve this and how do I have to change my providers.tf file to accomplish this?

问题回答

you can create an alias for the desired subscription and then create a reference in the desired resource using a provider reference. I hope that help you

# This is the "Default" provider
provider "azurerm" {
  subscription_id = var.dev_sub_id
  tenant_id       = var.dev_tenant_id
  client_id       = var.dev_client_id
  client_secret   = var.dev_client_secret

  features {}
}

# This provider uses the "prod" alias
provider "azurerm" {
  alias = "prod"

  subscription_id = var.prod_sub_id
  tenant_id       = var.prod_tenant_id
  client_id       = var.prod_client_id
  client_secret   = var.prod_client_secret

  features {}
}


resource "azurerm_resource_group" "dev" {
  name     = "resource-group-dev"
  location = var.location
}
 
resource "azurerm_resource_group" "prod" {
  name     = "resource-group-prod"
  location = var.location
 
  provider = azurerm.prod
}




相关问题
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 ...

热门标签