2017-01-31 49 views
0

我在terraform中有模塊根級別輸出的一些奇怪問題。Terraform根級別輸出問題

我們有在outputs.tf在根級以下:

output "vpc_id" { 
    value = "${aws_vpc.vpc.id}" 
} 

和模塊本身運行的計劃terraform錯誤出在解析輸出塊時,我們有

resource "aws_vpc" "vpc" { 
    cidr_block = "${var.vpc_cidr}" 
    enable_dns_hostnames = true 
    tags { 
     Name = "${upper(var.env)}-TF" 
     env = "${var.env}" 
     managed = "Terraform" 
    } 
} 

然而並跟蹤說:

2017/01/31 17:56:54 [INFO] Terraform version: 0.8.0 142dd256ad48ab17b6019fe9cd18712167fcf4b4 
2017/01/31 17:56:54 [INFO] CLI args: []string{"/usr/local/bin/terraform", "get"} 
2017/01/31 17:56:54 [DEBUG] Detected home directory from env var: /root 
2017/01/31 17:56:54 [DEBUG] Detected home directory from env var: /root 
2017/01/31 17:56:54 [DEBUG] Attempting to open CLI config file: /root/.terraformrc 
2017/01/31 17:56:54 [DEBUG] File doesn't exist, but doesn't need to. Ignoring. 
Get: file:///srv/terraform/modules/networking/ 
2017/01/31 17:56:54 [DEBUG] Detected home directory from env var: /root 
Error loading Terraform: module root: 1 error(s) occurred: 

* output 'vpc_id': unknown resource 'aws_vpc.vpc' referenced in variable aws_vpc.vpc.id 
2017/01/31 17:56:54 [DEBUG] plugin: waiting for all plugin processes to complete... 

我在這個點上虧本。我到處尋找,而且我找不到任何事情甚至發生,爲什麼我們會得到這個錯誤。

回答

1

啊,這裏的問題是這樣的:

output "vpc_id" { 
    value = "${aws_vpc.vpc.id}" 
} 

當定義根級別的輸出,你需要做的是這樣的:

output "vpc_id_root" { 
    value = "${module.networking.vpc_id}" 
} 
+0

您還需要模塊中的'vpc_id'輸出將它傳遞給根上下文。 – ydaetskcoR