属性的不适当值“ security_groups”:element 0:需要字符串

发布于 2025-02-12 19:47:54 字数 1938 浏览 1 评论 0原文

我不确定为什么要获得这个价值。

我在 bastion/main.tf 中拥有此资源。

resource "aws_security_group" "bastion_sg" {
  name   = "${var.name}-bastion-security-group"
  vpc_id = var.vpc_id

  ingress {
    protocol    = "tcp"
    from_port   = 22
    to_port     = 22
    cidr_blocks = ["0.0.0.0/0"]
  }

  egress {
    protocol    = -1
    from_port   = 0
    to_port     = 0
    cidr_blocks = ["0.0.0.0/0"]
  }

  tags = {
    Name = "${var.name}-bastion-sg"
  }
}

这是我的输出 bastion/outputs.tf

output "bastion_sg_id" {
  value = aws_security_group.bastion_sg
}

我的EKS模块 main.tf

module "eks" {
  source = "./eks"
  name   = var.name
  key_name = module.bastion.key_name
  bastion_sg = module.bastion.bastion_sg_id
  vpc_id = module.networking.vpc_id
  private_subnets = module.networking.vpc_private_subnets
}

我的变量在我的 eks/variables.tf

variable "bastion_sg" {
  description = "bastion sg to add to ingress rule of node sg"
}

最后,我的 eks/main.tf 在发生错误的

esource "aws_security_group" "node-sg" {
  name   = "${var.name}-node-security-group"
  vpc_id = var.vpc_id

  ingress {
    protocol        = "tcp"
    from_port       = 22
    to_port         = 22
    security_groups = [var.bastion_sg]
  }

  egress {
    protocol    = -1
    from_port   = 0
    to_port     = 0
    cidr_blocks = ["0.0.0.0/0"]
  }
}

情况[] for Security_groups参数,当我这样做时,我没有得到所需的字符串错误,当我添加[]时,我得到了这个错误

on eks\main.tf line 95, in resource "aws_security_group" "node-sg":
│   95:     security_groups = [var.bastion_sg]
│     ├────────────────
│     │ var.bastion_sg is object with 13 attributes
│
│ Inappropriate value for attribute "security_groups": element 0: string required.

I'm not sure why I'm getting this value.

I have this resource in bastion/main.tf

resource "aws_security_group" "bastion_sg" {
  name   = "${var.name}-bastion-security-group"
  vpc_id = var.vpc_id

  ingress {
    protocol    = "tcp"
    from_port   = 22
    to_port     = 22
    cidr_blocks = ["0.0.0.0/0"]
  }

  egress {
    protocol    = -1
    from_port   = 0
    to_port     = 0
    cidr_blocks = ["0.0.0.0/0"]
  }

  tags = {
    Name = "${var.name}-bastion-sg"
  }
}

here is my output for that bastion/outputs.tf

output "bastion_sg_id" {
  value = aws_security_group.bastion_sg
}

My eks module in my root directory main.tf

module "eks" {
  source = "./eks"
  name   = var.name
  key_name = module.bastion.key_name
  bastion_sg = module.bastion.bastion_sg_id
  vpc_id = module.networking.vpc_id
  private_subnets = module.networking.vpc_private_subnets
}

my variables in my eks/variables.tf

variable "bastion_sg" {
  description = "bastion sg to add to ingress rule of node sg"
}

lastly, my eks/main.tf where the error is occuring

esource "aws_security_group" "node-sg" {
  name   = "${var.name}-node-security-group"
  vpc_id = var.vpc_id

  ingress {
    protocol        = "tcp"
    from_port       = 22
    to_port         = 22
    security_groups = [var.bastion_sg]
  }

  egress {
    protocol    = -1
    from_port   = 0
    to_port     = 0
    cidr_blocks = ["0.0.0.0/0"]
  }
}

I tried it with and without the [] for the security_groups argument and when I did it without I got the set of strings required error and when I added the [] I got this error

on eks\main.tf line 95, in resource "aws_security_group" "node-sg":
│   95:     security_groups = [var.bastion_sg]
│     ├────────────────
│     │ var.bastion_sg is object with 13 attributes
│
│ Inappropriate value for attribute "security_groups": element 0: string required.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

橪书 2025-02-19 19:47:54

应该是:

output "bastion_sg_id" {
  value = aws_security_group.bastion_sg.id
}

It should be:

output "bastion_sg_id" {
  value = aws_security_group.bastion_sg.id
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文