How to get round Plugin Errors when deploying Azure resources using Terraform?

Viewed 1369

I'm getting the following error

│ 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

when I try to do Terraform plan on the following code

# 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 
}

these are my terraform, provider and Azure versions

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

what I've tried.....

Researching on the internet,.it says that this only happens in Azure CLI in the Azure Portal..I've tried it on Visual Studio Code and Powershell on my own machine..but I get the same results..I even tried putting https://registry.terraform.io/providers/hashicorp/azurerm/latest as the source instead of the usual "hashicorp/azurerm" but that threw errros as well

I'm really stuck...any guidance would be gratefully received ..I've been happily deploying Azure resources all day using the same method...but for some reason..it just doesn't like this one...

1 Answers

This is likely due to an issue with your Az CLI session and you probably need to login again using az login.

You can confirm if this is the issue by running an Az CLI command that needs to interact with resources (not just az account show). This is how I identified the issue:

$ az vm list -g my-resource-group

AADSTS700082: The refresh token has expired due to inactivity. The token was issued on 2021-06-27T00:13:23.1948087Z and was inactive for 90.00:00:00.

Related