baynezy
baynezy

Reputation: 7036

Error authorizing security group egress rules: InvalidGroup.NotFound

I am trying to get the following Terraform script to run:-


provider "aws" {
  region = "us-west-2"
}

provider "random" {}

resource "random_pet" "name" {}

resource "aws_instance" "web" {
  ami                     = "ami-a0cfeed8"
  instance_type           = "t2.micro"
  user_data               = file("init-script.sh")
  subnet_id               = "subnet-0422e48590002d10d"
  vpc_security_group_ids  = [aws_security_group.web-sg.id]

  tags = {
    Name = random_pet.name.id
  }
}

resource "aws_security_group" "web-sg" {
  name = "${random_pet.name.id}-sg"
  ingress {
    from_port   = 80
    to_port     = 80
    protocol    = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
  }
  egress {
    from_port   = 0
    to_port     = 0
    protocol    = "-1"
    cidr_blocks = ["0.0.0.0/0"]
  }
}

output "domain-name" {
  value = aws_instance.web.public_dns
}

output "application-url" {
  value = "${aws_instance.web.public_dns}/index.php"
}

However it errors with the following:-

Error: Error authorizing security group egress rules: InvalidGroup.NotFound: The security group 'sg-0c181b93d98173b0f' does not exist status code: 400, request id: 6cd8681b-ee70-4ec0-8509-6239c56169a1

The SG gets created with the correct name, but it claims it does not exist.

I am am unsure how to resolve this.

Upvotes: 2

Views: 3872

Answers (1)

baynezy
baynezy

Reputation: 7036

Typically I worked it out straight after posting. I had neglected to add the vpc_id property to the aws_security_group which meant it was an EC2 Classic SG which cannot have egress rules.

Upvotes: 3

Related Questions