azure - 将 Terraform 连接到 Azure Gov
问题描述
所以我正在尝试将 Terraform 连接到 Azure Gov,但似乎没有读取代码中的环境。或者我离这个很远,任何帮助都将不胜感激。
这是代码,非常基本的只是试图让它连接并在状态文件中存储一些东西。
terraform {
backend "azurerm" {
#resource_group_name = "terraform-test"
storage_account_name = "terraformstate01"
container_name = "tstate01"
key = "terraform.tfstate"
access_key = "ACCESS_KEY_GOES_HERE"
}
}
# Configure the Azure provider
provider "azurerm" {
# The "feature" block is required for AzureRM provider 2.x.
# If you are using version 1.x, the "features" block is not allowed.
version = "2.76.0"
environment = "usgovernment"
features {}
}
resource "azurerm_resource_group" "state-demo-secure" {
name = "state-demo"
location = "usgovvirginia"
}
这里还附上了我在运行 Terraform init 时遇到的错误。
Initializing the backend...
╷
│ Error: Failed to get existing workspaces: containers.Client#ListBlobs: Failure responding to request: StatusCode=403 -- Original Error: autorest/azure: Service returned an error. Status=403 Code="AuthenticationFailed" Message="Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.\nRequestId:c5022f4e-c01e-0002-51f4-74a3d7000000\nTime:2021-07-09T18:55:41.1228617Z"```
解决方案
正如Ken W MSFT在评论部分中提到的,您需要在调用 .tf 文件之前设置云环境,而不是在 azurerm 提供程序中调用它。
如果它是公开的,则不需要这样做,但是当您尝试使用私有的专有云时,您需要在使用该云之前使用 azure CLI 或 azure powershell 根据需要设置环境。
CLI 的命令:
$ az cloud set --name AzureChinaCloud|AzureGermanCloud|AzureUSGovernment
Powershell 的命令:
Connect-AzAccount -EnvironmentName AzureChinaCloud|AzureGermanCloud|AzureUSGovernment
参考:
Azure 提供程序:通过 Azure CLI 进行身份验证 | 指南 | 哈希公司/azurerm | Terraform 注册表
推荐阅读
- r - R将不同的功能映射到嵌套列表
- python - 组合python非常大的数字列表
- java - 如何在 GUI 中编写 Eclipse BUILT
- c# - Telerik:.Net Core 的搜索栏组件未显示/未定位
- excel - 比较不是真的;但发送到 MsgBox 的值显示它应该是
- python - 无法从外部访问应用程序时处理 Microsoft 身份验证响应
- python - 向量化将 2D numpy 数组中的列转换为字节字符串
- python-3.x - 在简单的 SysTray PyQt5 应用程序中使用 While 循环
- html - 我正在尝试从原始 servlet 的 html 调用 servlet
- sql - 如何在 Access 中进行查询将 tempvar 识别为有效字段(参数)