【发布时间】:2019-07-05 23:56:47
【问题描述】:
我在执行Terraform plan 时遇到错误。我在这里关注模块概念。
下面是我的资源 aws_efs_mount_target 和 aws_subnet 块。
efs.tf:-
resource "aws_efs_file_system" "master_efs" {
creation_token = "master"
performance_mode = "generalPurpose"
kms_key_id = "${data.terraform_remote_state.kms_ebs.outputs.key_arn}"
encrypted = "true"
tags = {
Name = "master"
Environment = "${var.environment}"
Terraform = "true"
}
}
resource "aws_efs_mount_target" "master_mt" {
file_system_id = "${aws_efs_file_system.master_efs.id}"
count = "${length(var.availability_zones)}"
subnet_id = "${data.aws_subnet.app_subnet_0.*.id[count.index]}"
security_groups = [ "${aws_security_group.sg.id}" ]
}
data "aws_subnet" "app_subnet_0" {
vpc_id = "${data.aws_vpc.cng.id}"
filter {
name = "tag:Name"
values = ["${var.search_pattern_app}-0"]
}
}
错误:无效索引
on ../../modules/efs.tf line 16, in resource "aws_efs_mount_target" "master_mt":
16: subnet_id = "${data.aws_subnet.app_subnet_0.*.id[count.index]}"
|----------------
| count.index is 2
| data.aws_subnet.app_subnet_0 is object with 15 attributes
The given key does not identify an element in this collection value.
Error: Invalid index
on ../../modules/efs.tf line 16, in resource "aws_efs_mount_target" "master_mt":
16: subnet_id = "${data.aws_subnet.app_subnet_0.*.id[count.index]}"
|----------------
| count.index is 1
| data.aws_subnet.app_subnet_0 is object with 15 attributes
The given key does not identify an element in this collection value.
Error: Invalid index
on ../../modules/efs.tf line 35, in resource "aws_efs_mount_target" "worker_mt":
35: subnet_id = "${data.aws_subnet.app_subnet_0.*.id[count.index]}"
|----------------
| count.index is 1
| data.aws_subnet.app_subnet_0 is object with 15 attributes
The given key does not identify an element in this collection value.
Error: Invalid index
on ../../modules/efs.tf line 35, in resource "aws_efs_mount_target" "worker_mt":
35: subnet_id = "${data.aws_subnet.app_subnet_0.*.id[count.index]}"
|----------------
| count.index is 2
| data.aws_subnet.app_subnet_0 is object with 15 attributes
The given key does not identify an element in this collection value.
【问题讨论】:
标签: amazon-web-services terraform terraform-provider-aws