Why can't add tags into terraform modules

7.3k views Asked by At

I got some problem to provision with tags on Azure database for PostgreSQL services, My code be like

module "postgresql" {
  source = "./modules/postgresql"
  service               = var.service
  .
  .
  .
  tags = { test = "test" }

And error happend

53:  tags = {

An argument named "tags" is not expected here.

Why always happened like this, Actually in the Resource_Group module has tags but It doesn't error at all , I'm kinda confused about this Does anyone knows about this please help me and Thank you for your kind help

1

There are 1 answers

0
Nancy On

As the error stated: "An argument named "tags" is not expected here.", you should define the variable tags in your child module when you're calling a child module because most of the arguments correspond to input variables defined by the module. Alternatively, if the resources does not support tags arguments, you can not use tags under that resource.

For example, you will have input variable tags in your modules configuration file if the resources support tags.

variable "tags" {

}
...

resource "azurerm_virtual_network" "myterraformnetwork" {
  name                = var.vnetname
  address_space       = var.address_space
  location            = var.location
  resource_group_name = var.rgname
  tags = var.tags
}