Terraform error - Error: Argument or block definition required
Terraform error - Error: Argument or block definition required
我的terraform代码如下:
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
}
不幸的是,我收到如下错误:
Error: Argument or block definition required
on main.tf line 52, in variable "listener":
52: [
An argument or block definition is required here.
稍后我将创建一个单独的变量文件。目前我想让基本的骨架工作。
variable listener
必须是 variable "listener"
。您缺少双引号
- 地图应该如下所示
variable "amis" {
type = "map"
default = {
"us-east-1" = "ami-b374d5a5"
"us-west-2" = "ami-4b32be2b"
}
}
- 最后,变量 listener 缺少它的定义。你有一个键值对数组,但你没有指定变量的类型或描述。
我的terraform代码如下:
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
}
不幸的是,我收到如下错误:
Error: Argument or block definition required
on main.tf line 52, in variable "listener":
52: [
An argument or block definition is required here.
稍后我将创建一个单独的变量文件。目前我想让基本的骨架工作。
variable listener
必须是variable "listener"
。您缺少双引号- 地图应该如下所示
variable "amis" {
type = "map"
default = {
"us-east-1" = "ami-b374d5a5"
"us-west-2" = "ami-4b32be2b"
}
}
- 最后,变量 listener 缺少它的定义。你有一个键值对数组,但你没有指定变量的类型或描述。