Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

>Solution :

It should be:

output "bastion_sg_id" {
  value = aws_security_group.bastion_sg.id
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading