<p>I'll go out on a limb here and assume that the issue is actually in your "aws_instance" block and is likely the result of how you are assigning the security groups in the "aws_instance".</p>

<p>Copied from the first linked article, in the resolution: </p>

<pre><code>change 

security_groups = ["cloud9Test"]

to

vpc_security_group_ids = ["${aws_security_group.cloud9Test.id}"]
</code></pre>

<p>Two related articles:</p>

<p><a href="https://github.com/KainosSoftwareLtd/aws-api-gateway-demo/issues/3" rel="nofollow noreferrer">https://github.com/KainosSoftwareLtd/aws-api-gateway-demo/issues/3</a></p>

<p><a href="https://stackoverflow.com/questions/31569910/terraform-throws-groupname-cannot-be-used-with-the-parameter-subnet-or-vpc-se/34586893#34586893">https://stackoverflow.com/questions/31569910/terraform-throws-groupname-cannot-be-used-with-the-parameter-subnet-or-vpc-se/34586893#34586893</a></p>

<p>If this is not on track, please post the "aws_instance" declaration. </p>

<p>For your own sanity I'd also recommend giving the resources names that are more specific to their role, and not identical, for example "cloud9Test_vpc". </p>

CC BY-SA 4.0
2019-01-08T03:12:15.700Z
2019-01-08T03:12:15.700Z
Absurdly
<p>I am working on setting up a Cloud9 environment using Terraform, I ran into an issue when it comes to my Terraform apply and specifically:</p>

<pre><code>Error: Error applying plan:

1 error(s) occurred:

* aws_instance.cloud9Test: 1 error(s) occurred:

* aws_instance.cloud9Test: 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
</code></pre>

<p>Here is my Terraform code that seems to be related and causing the issue. </p>

<pre><code>resource "aws_vpc" "cloud9Test" {
  cidr_block       = "10.0.0.0/16"
  instance_tenancy = "dedicated"

  tags = {
    Name = "cloud9Test"
  }
}

resource "aws_security_group" "cloud9Test" {
    name = "cloud9Test-sg"
    description = "Cloud9 Group"
    vpc_id      = "${aws_vpc.cloud9Test.id}"
}
</code></pre>

<p>When I comment out the vpc_id in the security group I don't have the issue anymore but I do want the security group inside my VPC.</p>

<p>How do I fix this?</p>

<p>Note I do not have anything that should overlap causing an issue, this is a fairly new account with only 3 ec2 instances and 1 cloud9 instance all created manually</p>

<amazon-web-services><terraform>
Terraform | AWS | vpc_id causing apply to fail
joshk132
# Terraform | AWS | vpc_id causing apply to fail

(Asked by: username_0 on 2019-01-07)

I am working on setting up a Cloud9 environment using Terraform, I ran into an issue when it comes to my Terraform apply and specifically:
Error: Error applying plan:

1 error(s) occurred:

* aws_instance.cloud9Test: 1 error(s) occurred:

* aws_instance.cloud9Test: 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

Here is my Terraform code that seems to be related and causing the issue. 
resource "aws_vpc" "cloud9Test" {
  cidr_block       = "10.0.0.0/16"
  instance_tenancy = "dedicated"

  tags = {
    Name = "cloud9Test"
  }
}

resource "aws_security_group" "cloud9Test" {
    name = "cloud9Test-sg"
    description = "Cloud9 Group"
    vpc_id      = "${aws_vpc.cloud9Test.id}"
}

When I comment out the vpc_id in the security group I don't have the issue anymore but I do want the security group inside my VPC.
How do I fix this?
Note I do not have anything that should overlap causing an issue, this is a fairly new account with only 3 ec2 instances and 1 cloud9 instance all created manually

**Tags:** amazon-web-services, terraform


---

## 1 answers

### Answer by username_1 on 2019-01-08. Score: 2

I'll go out on a limb here and assume that the issue is actually in your "aws_instance" block and is likely the result of how you are assigning the security groups in the "aws_instance".
Copied from the first linked article, in the resolution: 
change 

security_groups = ["cloud9Test"]

to

vpc_security_group_ids = ["${aws_security_group.cloud9Test.id}"]

Two related articles:
https://github.com/KainosSoftwareLtd/aws-api-gateway-demo/issues/3
https://stackoverflow.com/questions/31569910/terraform-throws-groupname-cannot-be-used-with-the-parameter-subnet-or-vpc-se/34586893#34586893
If this is not on track, please post the "aws_instance" declaration. 
For your own sanity I'd also recommend giving the resources names that are more specific to their role, and not identical, for example "cloud9Test_vpc".


---

