Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Amazon web services 将输出变量从一个模块传递到另一个模块时出错_Amazon Web Services_Terraform_Terraform Provider Aws_Terraform Output - Fatal编程技术网

Amazon web services 将输出变量从一个模块传递到另一个模块时出错

Amazon web services 将输出变量从一个模块传递到另一个模块时出错,amazon-web-services,terraform,terraform-provider-aws,terraform-output,Amazon Web Services,Terraform,Terraform Provider Aws,Terraform Output,我使用两个模块vpc和lb,并将vcp模块中的输出变量传递给lb模块,如下代码所示。但我有以下错误- Error: Unsupported attribute on main.tf line 35, in module "lb": 35: vpc-id = module.vpc.vpc-id This value does not have any attributes. 这是代码- main.tf /模块/vpc/vpc.tf resource "

我使用两个模块vpc和lb,并将vcp模块中的输出变量传递给lb模块,如下代码所示。但我有以下错误-

Error: Unsupported attribute

  on main.tf line 35, in module "lb":
  35:   vpc-id = module.vpc.vpc-id

This value does not have any attributes.
这是代码- main.tf

/模块/vpc/vpc.tf

resource "aws_vpc" "xcloud-vpc" {
  cidr_block       = "10.0.0.0/16"
  enable_dns_hostnames = true

  tags = {
    Name = "xcloud-vpc"
  }
}
./modules/vpc/vpc-output.tf

output "vpc-id" {
  value = aws_vpc.xcloud-vpc.id
}
/模块/lb/lb.tf

resource "aws_security_group" "allow_http" {
  name        = "xcloud-sg-allow-http"
  description = "Allow HTTP & ICMP inbound connections"
  vpc_id = var.vpc-id
  # vpc_id = module.vpc.vpc-id
  <some more ingress, egress code>

虽然我在main.tf中包含“lb”模块时传递了vpc id=module.vpc.vpc-id,但这行代码给出了上述错误。欢迎使用任何指针。

由于您在
模块中使用
count
,因此您应该参考模块的各个实例,即使您只有一个。因此,在您的情况下,它将是:

vpc_id = module.vpc[0].vpc-id

您在lb模块中也定义了变量“vpc id”吗?谢谢@Marcin,解决了这个问题。
variable image {}
variable instance_type {}
variable vpc-id{}
vpc_id = module.vpc[0].vpc-id