Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Argument or block definition required

My terraform code is as below:

terraform {
  backend "remote" {
    hostname     = "hostname.com"
    organization = "companyname"
    workspaces {
      name = "GIT-TIO-DEV"
    }
  }
} 


provider "aws" {
  region = "us-east-1"
  version = "~> 2.22"
}

locals {
  aws_region                      = "us-east-1"
  ami_id                          = "ami-000db10762d0c4c05"
  appid_tag                       = "S00012"
  env_tag                         = "dev"
  name_tag                        = "TESTINSTANCE"
  awsaccount_tag                  = "myaccount"
  createdby_tag                   = "testuser"
  keyName                         = "tst-cloudservices-portal-dev"
  securityGroup                   = "sg-wwwwwwwww"
  vpc_id                          = "vpc-aaaaaaaaaaaaa"
  patchgroup_tag                  = "GroupA"
  iam_role                        = "tst-SR-ServiceRole"
  division_tag                    = "TIO"
  application_segment_tag         = "DEV"
  notes_tag                       = "link to notes 2"
  function_tag                    = "portal server"
  os_tag                          = "RHEL76"
  platform_tag                    = "Linux"
  instance_type                   = "t2.micro"
  automation_server_count         = 2
}

variable "health_check" {
  description = "A health check block"
  type        = map(string)
  default = {
  "enabled" = "true",
  "port" = "443", 
  "protocol" = "https"
  }

 }

variable listener {
[
    {
        instance_port = "80"
        instance_protocol = "tcp"
    },
    {
        instance_port = "443"
        instance_protocol = "tcp"
    }
]



}
# Adding EC2 afer Security Group

module "tst-security-group-ec2" {
  source                          = "hostname.com/companyname/tst-security-group/aws"
  version                         = "1.0.2"
  group_name                      = "tst-myaccount-portal-dev"
  group_description               = "security group for portal dev"
  vpc_id                          = local.vpc_id
  appid_tag                       = local.appid_tag
  env_tag                         = local.env_tag
  awsaccount_tag                  = local.awsaccount_tag
  createdby_tag                   = local.createdby_tag
  function_tag                    = "Security group for portal dev"
  ingress = [{
    from_port   = 22
    to_port     = 22
    protocol    = "TCP"
    cidr_blocks = ["10.0.0.0/8"]
  },{
    from_port   = 3389
    to_port     = 3389
    protocol    = "TCP"
    cidr_blocks = ["10.0.0.0/8"]
    },{
    from_port   = -1
    to_port     = -1
    protocol    = "icmp"
    cidr_blocks = ["10.0.0.0/8"]
  }]
  egress =[ {
    from_port   = 0
    to_port     = 0
    protocol    = "-1"
    cidr_blocks = ["0.0.0.0/0"]
  }]
}
module "ec2-rhel-automation-server" {
  source                          = "hostname.com/companyname/tst-ec2-instance-rhel/aws"
  version                         = "1.2.6"
  aws_region                      = local.aws_region
  vpc_id                          = local.vpc_id
  ami_id                          = local.ami_id
  appid_tag                       = local.appid_tag
  application_segment_tag         = local.application_segment_tag
  awsaccount_tag                  = local.awsaccount_tag
  createdby_tag                   = local.createdby_tag
  default_security_group_id       = module.tst-security-group-ec2.id
  division_tag                    = local.division_tag
  env_tag                         = local.env_tag
  function_tag                    = local.function_tag
  keyName                         = local.keyName
  name_tag                        = "RHEL-AS${local.env_tag}"
  notes_tag                       = local.notes_tag
  os_tag                          = local.os_tag
  platform_tag                    = local.platform_tag
  ec2_server_count                = local.automation_server_count
  instance_type                   = local.instance_type
  hostname_tag                    = "ERNST${local.env_tag}WEB"
  iam_role                        = "tst-SR-ServiceRole"
  bootstrap_instance              = "false"
    }

// Adding ALB Security Group
module "tst-security-group-alb" {
  source                          = "hostname.com/companyname/tst-security-group/aws"
  version                         = "1.0.2"
  group_name                      = "tst-myaccount-portal-dev"
  group_description               = "security group for ALB"
  vpc_id                          = local.vpc_id
  appid_tag                       = local.appid_tag
  env_tag                         = local.env_tag
  awsaccount_tag                  = local.awsaccount_tag
  createdby_tag                   = local.createdby_tag
  function_tag                    = "Security group for ALB"
  ingress = [{
    from_port   = 443
    to_port     = 443
    protocol    = "TCP"
    cidr_blocks = ["10.0.0.0/8"]

   }]
  egress =[ {
    from_port   = 0
    to_port     = 0
    protocol    = "-1"
    cidr_blocks = ["0.0.0.0/0"]
  }]
}
// Creating a ALB
module "tst-alb" {
  source                          = "hostname.com/companyname/tst-alb/aws"
  version                         = "1.0.5"
  subnets                         = ["subnet-xxxxxxxxxxxxx","subnet-yyyyyyyyyyy","subnet-zzzzzzzzzzzzz"]
  listener                        = var.listener
  createdby_tag                   = local.createdby_tag
  function_tag                    = "Terraform created ALB"
  vpc_id                          = local.vpc_id
  awsaccount_tag                  = local.awsaccount_tag
  appid_tag                       = local.appid_tag
  security_groups                 = module.tst-security-group-alb.id
  env_tag                         = local.env_tag
  health_check                    = var.health_check
}

Unfortunately, I am getting an error like below:

Error: Argument or block definition required

  on main.tf line 52, in variable "listener":
  52: [

An argument or block definition is required here.

I am going to create a separate variable file later. At the moment I want to get basic skeleton working.

like image 766
learner Avatar asked May 27 '26 23:05

learner


1 Answers

  1. variable listener must be variable "listener". You are missing double quotes
  2. a map should look like the below
variable "amis" {
 type = "map"
 default = {
   "us-east-1" = "ami-b374d5a5"
   "us-west-2" = "ami-4b32be2b"
 }
}
  1. Finally, the variable listener is missing its definition. You have an array of key value pairs, but you are not specifying what type or description of the variable.
like image 100
Mo Ziauddin Avatar answered May 31 '26 10:05

Mo Ziauddin