简体   繁体   English

Terraform 11 附加安全组错误

[英]Terraform 11 Additional Security Group Error

I'm adding additional security groups in Terraform 11, using AWS Provider 2.70.0 to an EFS Mount Target.我在 Terraform 11 中添加额外的安全组,使用 AWS Provider 2.70.0 到 EFS 挂载目标。

The code block is:代码块是:

resource "aws_efs_mount_target" "default" {
  count          = "${length(split(",",var.backend_subnets)) > 0 ? length(split(",",var.backend_subnets)) : 0}"
  file_system_id = "${aws_efs_file_system.default.id}"
  ip_address     = "${var.mount_target_ip_address}"
  subnet_id      = "${element(split(",", var.backend_subnets), count.index)}"
  security_groups = ["${var.additional_security_groups == "" ? aws_security_group.efs_default_sg.id : format("%s,%s",var.additional_security_groups,aws_security_group.efs_default_sg.id)}"]
}

The variable definition is:变量定义为:

variable "additional_security_groups" {
  description = "Comma separated string of security group ID's"
  default     = ""
}

But the following errors are occurring:但是会出现以下错误:

* module.efs.aws_efs_mount_target.default[1]: 1 error(s) occurred:

* aws_efs_mount_target.default.1: ValidationException:
status code: 400, request id: 5ee48121-27c3-432b-98e9-e2ffdc6e0fdd

plugin.terraform-provider-aws_v2.70.0_x4: 2021/03/26 17:49:50 [ERR] plugin: plugin server: accept unix /tmp/plugin935042092: use of closed network connection

There is no issue when run without the additional security group.在没有附加安全组的情况下运行没有问题。

Any ideas or tips would be much appreciated!任何想法或提示将不胜感激!

So the issue was not with the plugin but was with the compare statement for the security groups.所以问题不在于插件,而在于安全组的比较语句。

The working compare:工作比较:

security_groups = ["${split(",", length(var.additional_security_groups) > 0 ? join(",", concat(list(aws_security_group.efs_default_sg.id), var.additional_security_groups)) : join(",", list(aws_security_group.efs_default_sg.id)))}"]

And to support this, the variable type had to be changed to list:为了支持这一点,必须将变量类型更改为列表:

variable "additional_security_groups" {
  description = "Comma separated list of security group ID's"
  default     = ["sg-123","sg-789"]
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM