C2W3: Lab1 Terraform Question

ec2.tf
line 54

referring to modules/network.tf lines 27,28
resource “aws_security_group” “bastion_host” {
vpc_id = data.aws_vpc.main.id
name = “${var.project}-bastion-host-sg”

, should it not be ‘id’ instead of ‘vpc_id’
vpc_security_group_ids = [aws_security_group.bastion_host.vpc_id] # Use the security group you created for the bastion host

solution says it is
vpc_security_group_ids = [aws_security_group.bastion_host.id] # Use the security group you created for the bastion host

Hello @eadgc5
aws_security_group.bastion_host.id is the correct answer. When we create aws_security_group.bastion_host in the network.tf file, we provide vpc_id to assign the security group to a VPC. However, upon using this security group in the declaration of aws_instance.bastion_host in the ec2.tf file, we want to specify to which security groups the bastion host has access to; therefore, we use the self-generated id from aws_security_group.bastion_host in line 54 of the ec2.tf file.