Creating module - azure-nsg

working on creating a module, getting this error:

Error: Argument or block definition required
│
│ On .terraform/modules/nsg-main/nsg-main/main.tf line 43: An argument or block definition is required here.

here is the module code:
main.tf:

 resource "azurerm_network_security_group" "NSG1" {
  name                = var.name        #"testNSG1"                     #name of the NSG
  location            = var.location    #"westus2"                      #azurerm_resource_group.example.location #what region
  resource_group_name = var.rgname      #azurerm_resource_group.rg.name #this assigns to the RG thats created above

  ##### security rules go below
  ##  priority max is 4096

  security_rule {
    name                       = "test123" #name of the rule
    priority                   = 100
    direction                  = "Inbound"
    access                     = "Allow"
    protocol                   = "Tcp"
    source_port_range          = "*"
    destination_port_range     = "22"          #add your ports here
    source_address_prefix      = "10.2.2.0/24" #add inbound address range or IPs 
    destination_address_prefix = "*"           #add local, IPs or ranges that this rule effects "*" for everything in NSG 
  }
  security_rule {

    name                       = "denyall-rule" #name of the rule
    priority                   = 4000
    direction                  = "Inbound"
    access                     = "Deny"
    protocol                   = "Tcp"
    source_port_range          = "*"
    destination_port_range     = "*"         #add your ports here
    source_address_prefix      = "0.0.0.0/0" #add inbound address range or IPs 
    destination_address_prefix = "*"         #add local, IPs or ranges that this rule effects "*" for everything in NSG
  }
  
tags = var.tags
}

and variables:

variable "name" {

Desscription = "test here"

type = string

}

variable "location" {

Desscription = "test here"

type = string

}

variable "rgname" {

Desscription = "test here"

type = string

}

variable "tags" {

Desscription = "test here"

type = map(string)

default = {}

}

and here is the TF project to use said module:

# Configure the Azure provider
terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = ">= 2.58"

    }
  }
}


#provider
provider "azurerm" {
  features {}
 
}



module "nsg-main" {
source = "git::git@blahblah.git//nsg-main"
name = "modtest"
location = "westus"
rgname   = "tftesting"

tags {
testtag = "true"
thistag = "yes"
}

}

wow that formatted badly

Hi @ghost6shell,

This seems to be reporting a syntax error in one of your files, but I guess you edited out the part of the error message that would’ve shown which part it was talking about! Can you share the entire error message Terraform returned, including the source code snippet, so that we can see which of the lines you shared is nsg-main/main.tf line 43?

You can use the “Preformatted text” icon in the editor toolbar to ensure that the forum takes what you entered literally, rather than trying to parse it as forum markup.

Thanks!

here is the actual error which is posted above but it got badly mangled.

orc@DESKTOP-LV094LS:~/code_repos/azure.terraform.dev.vnet/dev.mod.working$ terraform get
╷
│ Error: Argument or block definition required
│
│ On .terraform/modules/nsg-main/nsg-main/main.tf line 43: An argument or block definition is required here.
╵

╷
│ Error: Argument or block definition required
│
│ On .terraform/modules/nsg-main/nsg-main/main.tf line 43: An argument or block definition is required here.
resource "azurerm_network_security_group" "NSG1" {
  name                = var.name        #"testNSG1"                     #name of the NSG
  location            = var.location    #"westus2"                      #azurerm_resource_group.example.location #what region
  resource_group_name = var.rgname      #azurerm_resource_group.rg.name #this assigns to the RG thats created above

  ##### security rules go below
  ##  priority max is 4096

  security_rule {
    name                       = "test123" #name of the rule
    priority                   = 100
    direction                  = "Inbound"
    access                     = "Allow"
    protocol                   = "Tcp"
    source_port_range          = "*"
    destination_port_range     = "22"          #add your ports here
    source_address_prefix      = "10.2.2.0/24" #add inbound address range or IPs 
    destination_address_prefix = "*"           #add local, IPs or ranges that this rule effects "*" for everything in NSG 
  }
  security_rule {

    name                       = "denyall-rule" #name of the rule
    priority                   = 4000
    direction                  = "Inbound"
    access                     = "Deny"
    protocol                   = "Tcp"
    source_port_range          = "*"
    destination_port_range     = "*"         #add your ports here
    source_address_prefix      = "0.0.0.0/0" #add inbound address range or IPs 
    destination_address_prefix = "*"         #add local, IPs or ranges that this rule effects "*" for everything in NSG
  }
  
tags = var.tags
}

Thanks @ghost6shell!

Those error messages still seem to be missing a portion… normally the line starting with On <filename> line <n> is followed by a configuration snippet showing the content of the relevant line:

 On .terraform/modules/nsg-main/nsg-main/main.tf line 43:
 43:   tags = var.tags

(the snippet above is just for example; I don’t know which of the lines you showed is actually line 43)

If Terraform isn’t printing out a line like that for some reason, perhaps you could refer to your text editor to see which of the lines you shared is line 43 in your real file, and that would allow me to focus on trying to understand what’s wrong with that particular line rather than trying to scan the entire snippet for errors. (It seems like there are fewer than 43 lines in what you shared – I count ~32 lines – so I assume there’s more to your file than you’ve illustrated here.)