无法从Terraform v0.12 +获取输出

时间:2019-07-27 03:53:21

标签: terraform terraform-v12

我正在迁移到Terraform的最新版本,并且无法重现文档概述的有关如何从应用程序获取输出的内容。文档说明

  

data.terraform_remote_state.vpc.vpc_id

因此,将这些内容从模块中删除应该具有

的作用。

data.module_name.remote_state.vpc.vpc_id我会认为吗?

这是我的模块调用

module "vpc" {
  source             = "github.com/terraform-aws-modules/terraform-aws-vpc"
  name               = "apigee"
  cidr               = "10.0.0.0/16"
  azs                = [data.aws_availability_zones.available.names[0], data.aws_availability_zones.available.names[1]]
  private_subnets    = ["10.0.1.0/24", "10.0.2.0/24"]
  public_subnets     = ["10.0.101.0/24", "10.0.102.0/24"]
  enable_nat_gateway = true
  single_nat_gateway = true

  tags = {
    Owner       = "212743998"
    Environment = "sandbox"
  }
}

所以我认为...。

data.vpc.terraform.vpc.vpc_id

这是我的目录的概要,列出了状态文件

○ → tree
.
├── [gabel   45]  data.tf
├── [gabel  529]  modules.tf
├── [gabel  112]  outputs.tf
├── [gabel   41]  providers.tf
├── [gabel  36K]  terraform.tfstate
├── [gabel  157]  terraform.tfstate.backup
├── [gabel   21]  terraform.tfvars
└── [gabel  121]  variables.tf

但是...我也注意到模块中的the way they're calling the id,现在...现在我很困惑。...

在Terraform v0.12 +中调用模块输出的正确方法是什么?

2 个答案:

答案 0 :(得分:0)

是的,这很好...但是仍然无法回答我如何调用那些没有来自模块源的显式输出的东西...

output "vpc_id" {
  description = "The ID of the VPC"
  value       = module.vpc.vpc_id
}

输出

terraform refresh
data.aws_availability_zones.available: Refreshing state...
module.vpc.aws_vpc.this[0]: Refreshing state... [id=vpc-xxxx
module.vpc.aws_eip.nat[0]: Refreshing state... [id=eipalloc-xxxx
module.vpc.aws_internet_gateway.this[0]: Refreshing state... [id=igw-xxxx
module.vpc.aws_route_table.public[0]: Refreshing state... [id=rtb-xxxx
module.vpc.aws_subnet.public[0]: Refreshing state... [id=subnet-xxxx
module.vpc.aws_subnet.private[0]: Refreshing state... [id=subnet-xxxx
module.vpc.aws_subnet.private[1]: Refreshing state... [id=subnet-xxxx
module.vpc.aws_subnet.public[1]: Refreshing state... [id=subnet-xxxx
module.vpc.aws_route_table.private[0]: Refreshing state... [id=rtb-xxxx
module.vpc.aws_route.public_internet_gateway[0]: Refreshing state... [id=r-xxxx
module.vpc.aws_route_table_association.private[0]: Refreshing state... [id=rtbassoc-xxxx
module.vpc.aws_route_table_association.private[1]: Refreshing state... [id=rtbassoc-xxxx
module.vpc.aws_route_table_association.public[1]: Refreshing state... [id=rtbassoc-xxxx
module.vpc.aws_route_table_association.public[0]: Refreshing state... [id=rtbassoc-xxxx
module.vpc.aws_nat_gateway.this[0]: Refreshing state... [id=nat-xxxx
module.vpc.aws_route.private_nat_gateway[0]: Refreshing state... [id=r-xxxx

Outputs:

vpc_id = vpc-xxxx

在这里将答案留给以后的搜索者。

答案 1 :(得分:0)

我不确定您的问题是否正确,因为模块和remote_state文件是不同的东西。

使用模块时,“父级”或“调用方”或任何您想调用的模块都会从module.modulename。中获取值,就像您所说的那样,在这种情况下,您可以直接从module.vpc中获取vpc_id .vpc_id。

当您想从“远程数据源”获取变量的值时,需要先使用“输出”“发布”数据,然后在remote_state文件中使用数据,在这种情况下,TF更改了0.12.x上的输出格式 在新版本中,您需要将输出引用为 data.terraform_remote_state.vpc.outputs.vpc_id

我相信文档不会反映出更改。