如何使用Terraform连接到Azure?

已经从Azure门户检索了多个值,并将其复制到以下文件,例如A,B,C和D:

main.tf

provider "azurerm" { subscription_id = "A" client_id = "B" client_secret = "C" tenant_id = "D" } 

运行terraform apply ,导致:

 Error refreshing state: 1 error(s) occurred: * Credentials for acessing the Azure Resource Manager API are likely to be incorrect, or the service principal does not have permission to use the Azure Service Management API. 

试图解决这个问题

尽pipeselect了Windows Azure Management API ,随后将Access Azure Service Management as organization users (preview)添加,但在运行terraform apply后再次terraform apply问题仍然存在。

第二次尝试

遵循本教程中的步骤导致在Classic Portal中创build虚拟networking,而不是新build。

publish_settings文件已下载并用于以下configuration代码片段中:

 provider "azure" { publish_settings = "${file("file.publishsettings")}" } resource "azure_virtual_network" "default" { name = "vNet01" address_space = ["10.0.0.1/24"] location = "North Europe" subnet { name = "Subnet1" address_prefix = "10.0.0.1/25" } }