Home > Blockchain >  An argument named "resource_group_name" is not expected here
An argument named "resource_group_name" is not expected here

Time:01-11

I was looking at a GitHub project ibm-cloud-architecture/terraform-openshift4-azure to install OpenShift using Terraform.

Using Terraform 1.3.7 this project fails on the following code

resource "azurerm_lb_backend_address_pool" "internal_lb_controlplane_pool_v4" {
  count = var.use_ipv4 ? 1 : 0

  resource_group_name  = var.resource_group_name
  loadbalancer_id     = azurerm_lb.internal.id
  name                = var.cluster_id
}

with the message

Error: Unsupported argument on vnet/internal-lb.tf line 40, in resource "azurerm_lb_backend_address_pool" internal_lb_controlplane_pool_v4": 40: resource_group_name = var.resource_group_name

An argument named "resource_group_name" is not expected here.

Why is this code failing? How can we specify the name of a resource group with the current version of Terraform and Azure?

CodePudding user response:

If you check docs for azurerm_lb_backend_address_pool you will see that it does not take resource_group_name argument. So it should be:

resource "azurerm_lb_backend_address_pool" "internal_lb_controlplane_pool_v4" {
  count = var.use_ipv4 ? 1 : 0
  loadbalancer_id     = azurerm_lb.internal.id
  name                = var.cluster_id
}

CodePudding user response:

Issue was caused because of syntax error. There resource_group_name is not required.

resource "azurerm_lb_backend_address_pool" "example" {
  loadbalancer_id = azurerm_lb.example.id
  name            = "BackEndAddressPool"
}

here is the code reference and replicated the same

main tf as follow:

data "azurerm_client_config" "current" {}

resource "azurerm_resource_group" "example" {
  name     = "********"
  location = "West Europe"
}
resource "azurerm_public_ip" "example" {
  name                = "swarnaPublicIPForLB"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
  allocation_method   = "Static"
}

resource "azurerm_lb" "example" {
  name                = "swarnaTestLoadBalancer"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name

  frontend_ip_configuration {
    name                 = "swanraPublicIPAddress"
    public_ip_address_id = azurerm_public_ip.example.id
  }
}

resource "azurerm_lb_backend_address_pool" "example" {
  loadbalancer_id = azurerm_lb.example.id
  name            = "BackEndAddressPool"
}

upon plan and apply enter image description here

enter image description here

From Portal enter image description here

  • Related