为我的 Terraform 模块编写示例时,出现错误:“模块包含提供程序配置”“无法使用 count、for_each 或 dependent_on 在模块内配置提供程序。”
当我尝试depends_on向模块声明添加一个块以避免在创建部署模块内资源所需的资源组之前尝试运行模块计划时,出现此错误。
如果我不添加该depends_on块,它也会中断,因为它找不到在模块运行以填充所需资源组数据源之前应创建的声明的资源组。
我发现要求删除块providers或删除所有数据源至少让人感到不舒服。
我找不到有关此错误或如何修复它的任何详细信息。
我正在尝试在我的 Terraform 代码中使用模块作为依赖项。但即使在提到模块中的特定源路径之后,它也会给出错误 \xe2\x80\x9c 模块目录不存在或无法读取。” 和 \xe2\x80\x9cUnable tovaluing directory \xe2\x80\x93 系统找不到指定的文件。” 谁能告诉我这可能是什么原因。
\n\n我必须管理 3 个不同的环境,每个环境有 3 个不同的后端状态文件。这里每个主文件都调用各自的模块文件。主文件夹由后端配置、资源组的创建和调用模块文件组成
\n\n root\n |\n |-- main \n | |--prod \n | |--dev \n | |--staging\n |-- modules\n | |--prod \n | |--dev \n | |--staging\nRun Code Online (Sandbox Code Playgroud)\n\n- - - - - - 代码 - - - - - - - - -
\n\n provider "azurerm" {\n version = "=2.2.0"\n features {}\n }\n\n #--- CREATING RESOURCE GROUP PER ENVIRONEMENT\n terraform {\n backend "azurerm" {\n …Run Code Online (Sandbox Code Playgroud) 如果我通过门户手动创建 Azure 函数,则会创建应用程序密钥:

如果我通过 terraform 尝试相同的操作:
resource "azurerm_function_app" "resize_images" {
name = format("%s%s%s%s", module.subscription_prefix.prefix, "pfunctionapp", lower(local.environment), "0001")
location = azurerm_resource_group.azure_functions.location
resource_group_name = azurerm_resource_group.azure_functions.name
app_service_plan_id = module.app_service_plan.id
# AzureRM 1.x needs this
#storage_connection_string = local.azure_functions_storage_account_primary_connection_string
# AzureRM 2.x needs this
storage_account_name = data.azurerm_storage_account.resize_storage.name
storage_account_access_key = data.azurerm_storage_account.resize_storage.primary_access_key
app_settings = {
AzureWebJobsDashboard = data.azurerm_storage_account.resize_storage.primary_connection_string
AzureWebJobsStorage = data.azurerm_storage_account.resize_storage.primary_connection_string
BLOB_STORAGE_CONNECTION_STRING = data.azurerm_storage_account.resize_storage.primary_connection_string
CONTAINER_NAME = "images"
FUNCTIONS_EXTENSION_VERSION = "~3"
WEBSITE_HTTPLOGGING_RETENTION_DAYS = "3"
WEBSITE_RUN_FROM_PACKAGE = "1"
}
version = "~3"
tags = local.tags
}
Run Code Online (Sandbox Code Playgroud)
在 …
我正在 azurerm_virtual_machine 中通过计数创建 4 个虚拟机,但我只想创建一个公共 IP 并将其与第一个虚拟机关联?这可能吗?如果可以的话怎么办?
下面是我的模板文件
resource "azurerm_network_interface" "nics" {
count = 4
name = ...
location = ...
resource_group_name = ...
ip_configuration {
subnet_id = ...
private_ip_address_allocation = "Static"
private_ip_address = ...
}
}
resource "azurerm_public_ip" "public_ip" {
name = ...
location = ...
resource_group_name = ...
}
resource "azurerm_virtual_machine" "vms" {
count = 4
network_interface_ids = [element(azurerm_network_interface.nics.*.id, count.index)]
}
Run Code Online (Sandbox Code Playgroud)
我已经解决了以下问题,但它们创建了多个公共 IP 并将它们添加到所有虚拟机中。
azure azure-virtual-machine terraform terraform-provider-azure azure-public-ip
我尝试应用 terraform plan 与terraform apply. 但是当我运行命令时出现以下错误
Error: Error building AzureRM Client: Error populating Client ID from the Azure CLI:
No Authorization Tokens were found -
please ensure the Azure CLI is installed and then log-in with `az login`.
Run Code Online (Sandbox Code Playgroud)
我确实安装了 Azure CLI,并且使用az login. 当我运行时,az login我会被重定向到登录页面,在那里我可以正常登录。
也terraform init可以毫无问题地工作。
在我的地形文件下面:
provider "azurerm" {
version = "1.38.0"
}
Run Code Online (Sandbox Code Playgroud)
我还尝试提供订阅和租户 ID,但没有帮助:
provider "azurerm" {
version = "1.38.0"
subscription_id = "00000000-0000-0000-0000-000000000000"
tenant_id = "00000000-0000-0000-0000-000000000001"
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试通过 Terraform 创建一个 Web 应用程序,新的 azurerm 提供程序 3.0 已经发布,因此新的模块 azurerm_windows_web_app 已推出。文档指出 application_stack 块支持以下内容:current_stack、docker、Java 等。
azurerm 版本 =“=3.0.0”
Terraform 文档链接:https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/windows_web_app#example-usage
一旦我尝试运行为此创建的模块,它就会抛出错误:
错误:不支持的块类型
这是我的代码片段,我不确定发生了什么。尝试用谷歌搜索它,但从其他用户那里获得文档似乎很新。有什么见解吗?
resource "azurerm_windows_web_app" "web_app_resource" {
name = var.resource_name
resource_group_name = var.resource_group_name
location = var.location
service_plan_id = var.app_service_plan_id
https_only = true
tags = var.tags
count = var.create
site_config {}
application_stack {
current_stack = var.current_stack
dotnet_version = var.dotnet_version
}
}
Run Code Online (Sandbox Code Playgroud) 使用提供者块
provider "azurerm" {
subscription_id = var.subscription_id
version = "=1.44"
}
Run Code Online (Sandbox Code Playgroud)
并成功登录后
az login
Run Code Online (Sandbox Code Playgroud)
跑步
terraform plan
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
Error: Error building account: Error getting authenticated object ID: Error parsing json result from the Azure CLI: Error waiting for the Azure CLI: exit status 2
on main.tf line 21, in provider "azurerm":
21: provider "azurerm" {
Run Code Online (Sandbox Code Playgroud)
更新:
如果我将提供程序块更改为:
provider "azurerm" {
version = "~> 1.43"
}
Run Code Online (Sandbox Code Playgroud)
并设置环境变量
ARM_USE_MSI=true
ARM_SUBSCRIPTION_ID=<...>
ARM_TENANT_ID=<...>
HTTP_PROXY=<...>
HTTPS_PROXY=<...>
http_proxy=<...>
https_proxy=<...>
Run Code Online (Sandbox Code Playgroud)
比执行 terraform 计划后,我收到以下错误:
与 169.254.169.254 的连接失败。没有到主机的路由。
在我看来,这很奇怪,服务端点 …
我在 Windows 上执行terraform.exe apply并收到错误:
azurerm_subnet.subnet: Refreshing state... [id=<...>]\nazurerm_app_service_plan.service_plan: Refreshing state... [id=<...>]\nazurerm_app_service.app: Refreshing state... [id=<...>]\nazurerm_app_service_virtual_network_swift_connection.test: Refreshing state... [id=<...>]\nazurerm_app_service_slot.production: Refreshing state... [id=<...>]\nazurerm_app_service_slot.staging: Refreshing state... [id=<...>]\n\nError: ID was missing the `slots` element\nRun Code Online (Sandbox Code Playgroud)\n我正在尝试使用 terraform 构建具有不同插槽和 docker 图像的 Azure WebApp。它应该根据 Dockerfile 映像部署具有不同插槽的 Azure WebApp。
\n第一次运行没有错误。当我刷新资源时收到错误消息。
\n我正在使用 azurerm 提供程序版本 2.1.0 和 azurerm 后端。
\n请参阅以下 terraform 文件:
\nterraform {\n backend "azurerm" {\n resource_group_name = "..."\n storage_account_name = "..."\n container_name = "..."\n key = "..."\n\n subscription_id = "..."\n tenant_id …Run Code Online (Sandbox Code Playgroud) runtime-error azure terraform azure-web-app-service terraform-provider-azure
我想使用 terraform 创建服务主体,并为此编写了 terraform 脚本。我有 Azure DevOps pipeline,我可以在其中运行该管道。我用来运行 terraform 脚本的服务主体具有订阅的所有者访问权限。我在创建天蓝色广告应用程序时遇到以下错误
\n\xe2\x94\x82 \n\xe2\x94\x82 with module.appregister.azuread_application.auth,\n\xe2\x94\x82 on modules/appregister/main.tf line 6, in resource "azuread_application" "auth":\n\xe2\x94\x82 6: resource "azuread_application" "auth" {\n\xe2\x94\x82 \n\xe2\x94\x82 ApplicationsClient.BaseClient.Post(): unexpected status 403 with OData\n\xe2\x94\x82 error: Authorization_RequestDenied: Insufficient privileges to complete the\n\xe2\x94\x82 operation.\n\xe2\x95\xb5\n##[error]Error: The process '/agent/_work/_tool/terraform/1.0.3/x64/terraform' failed with exit code\nRun Code Online (Sandbox Code Playgroud)\n运行它需要什么样的权限?
\nazure azure-active-directory terraform azure-devops terraform-provider-azure
我的地形片段:
\nvariable "machine_details" {\n type = object({\n name = string\n size = string\n username = string\n password = string\n })\n\n default = [\n {\n name = "example-vm"\n size = "Standard_F2"\n username = "adminuser"\n password = "Notallowed1!"\n }\n ]\n}\nRun Code Online (Sandbox Code Playgroud)\n我收到如下错误。
\n Error: Invalid default value for variable\n \xe2\x94\x82\n \xe2\x94\x82 on variables.tf line 38, in variable "machine_details":\n \xe2\x94\x82 38: default = [\n \xe2\x94\x82 39: {\n \xe2\x94\x82 40: name = "example-vm"\n \xe2\x94\x82 41: size = "Standard_F2"\n \xe2\x94\x82 42: username = "adminuser"\n …Run Code Online (Sandbox Code Playgroud)