I have the following configuration:
resource "aws_security_group" "allow_ssh" {
name = "allow_ssh"
vpc_id = "${aws_default_vpc.default.id}"
description = "Allow ssh connections on port 22"
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_instance" "your-app" {
ami = "ami-2757f631"
instance_type = "t2.micro"
security_groups = ["${aws_security_group.allow_ssh.id}"]
key_name = "${aws_key_pair.twilio_key.key_name}"
}
When I do terraform apply, I get this error:
* aws_instance.your-app: Error launching instance, possible mismatch of Security Group IDs and Names. See AWS Instance docs here: https://terraform.io/docs/providers/aws/r/instance.html.
AWS Error: Value () for parameter groupId is invalid. The value cannot be empty
What should I do to solve the above error ?
You have to change id to name for it to work:
resource "aws_instance" "twilio-app" {
ami = "ami-2757f631"
instance_type = "t2.micro"
key_name = "${aws_key_pair.twilio_key.key_name}"
security_groups = [ "${aws_security_group.allow_ssh.name}" ]
}
It accepts group name and not the id parameter.
I'm Adding another solution here because I encountered the same issue and changing the security group id to the name didn't solve the problem.
Checking on Terraform docs under the instance resource we can see the usage of the security_groups argument:
security_groups - (Optional, EC2-Classic and default VPC only) A list of security group names (EC2-Classic) or IDs (default VPC) to associate with.
Under that we can see the following note:
NOTE: If you are creating Instances in a VPC, use vpc_security_group_ids instead.
And the description of the vpc_security_group_ids argument:
vpc_security_group_ids - (Optional, VPC only) A list of security group IDs to associate with.
So for me changing from security_groups to vpc_security_group_ids solved the issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With