【问题标题】:How to get round Plugin Errors when deploying Azure resources using Terraform?使用 Terraform 部署 Azure 资源时如何解决插件错误?
【发布时间】:2021-10-28 14:23:58
【问题描述】:

我收到以下错误

│ Error: Plugin error
│
│   with provider["registry.terraform.io/hashicorp/azurerm"],
│   on nsg.tf line 13, in provider "azurerm":
│   13: provider "azurerm" {
│
│ The plugin returned an unexpected error from plugin.(*GRPCProvider).ConfigureProvider: rpc error: code = Internal desc = grpc: error while marshaling: string field
│ contains invalid UTF-8

当我尝试对以下代码执行 Terraform 计划时

# Configure the Microsoft Azure Provider
terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "=2.74.0"
    }
  }
}

# Configure the Microsoft Azure Provider
provider "azurerm" {
  features {}
}
resource "azurerm_network_security_group" "nsg" {
    name                                = "TestNSG"
    location                            = "East US"
    resource_group_name                 = "TFResourcegroup"
}

resource "azurerm_network_security_rule" "example1" {
    name                                = "Web80"
    priority                            = 1001
    direction                           = "Inbound"
    access                              = "Allow"
    protocol                            = "Tcp"
    source_port_range                   = "*"
    destination_port_range              = "80"
    source_address_prefix               = "*"
    destination_address_prefix          = "*"
    resource_group_name                 = "TFResourcegroup"
    network_security_group_name         = azurerm_network_security_group.nsg.name          
}

resource "azurerm_network_security_rule" "example2" {
    name                                = "Web8080"
    priority                            = 1000
    direction                           = "Inbound"
    access                              = "Deny"
    protocol                            = "Tcp"
    source_port_range                   = "*"
    destination_port_range              = "8080"
    source_address_prefix               = "*"
    destination_address_prefix          = "*"
    resource_group_name                 = "TFResourcegroup"
    network_security_group_name         = azurerm_network_security_group.nsg.name 
}

resource "azurerm_network_security_rule" "example3" {
    name                                = "WebOUT"
    priority                            = 1000
    direction                           = "Outbound"
    access                              = "Deny"
    protocol                            = "Tcp"
    source_port_range                   = "*"
    destination_port_range              = "80"
    source_address_prefix               = "*"
    destination_address_prefix          = "*"
    resource_group_name                 = "TFResourcegroup"
    network_security_group_name         = azurerm_network_security_group.nsg.name 
}

这些是我的 terraform、provider 和 Azure 版本

PS C:\russ\nsg> terraform --version
Terraform v1.0.4
on windows_amd64
+ provider registry.terraform.io/hashicorp/azurerm v2.74.0
PS C:\russ\nsg> az --version
azure-cli                         2.27.2

我试过的.....

在互联网上进行研究,它说这只发生在 Azure 门户的 Azure CLI 中。我已经在我自己的机器上的 Visual Studio Code 和 Powershell 上尝试过它。但我得到了相同的结果。我甚至尝试将https://registry.terraform.io/providers/hashicorp/azurerm/latest 作为来源而不是通常的“hashicorp/azurerm”,但这也引发了错误

我真的被困住了...任何指导都会很感激... ...

【问题讨论】:

  • 嗨,我有点怀疑了这个..我尝试在 Bash 而不是 Powershell 中运行它,它运行良好...有人知道为什么这可能是案例?
  • 您找到其他解决方案了吗?我也有同样的问题。

标签: azure terraform-provider-azure


【解决方案1】:

这可能是由于您的 Az CLI 会话存在问题,您可能需要使用 az login 再次登录。

您可以通过运行需要与资源交互的 Az CLI 命令(不仅仅是az account show)来确认这是否是问题所在。这就是我发现问题的方式:

$ az vm list -g my-resource-group

AADSTS700082:刷新令牌由于不活动而过期。该令牌于 2021-06-27T00:13:23.1948087Z 发行,并在 90.00:00:00 内处于非活动状态。

【讨论】:

    猜你喜欢
    • 2022-01-25
    • 2019-09-13
    • 2020-11-20
    • 1970-01-01
    • 2021-06-16
    • 1970-01-01
    • 1970-01-01
    • 2018-08-13
    • 2020-10-10
    相关资源
    最近更新 更多