# RDS DB instance and EC2 security group are in different VPCs

**URL:** <https://forum.ansible.com/t/rds-db-instance-and-ec2-security-group-are-in-different-vpcs/30080>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [April 9, 2019, 12:36am UTC](https://forum.ansible.com/t/rds-db-instance-and-ec2-security-group-are-in-different-vpcs/30080 "2019-04-09T00:36:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ian\_Williamson](https://avatars.discourse-cdn.com/v4/letter/i/96bed5/32.png) [@Ian\_Williamson](https://forum.ansible.com/u/Ian_Williamson)\
**Post date:** [April 9, 2019, 12:36am UTC](https://forum.ansible.com/t/rds-db-instance-and-ec2-security-group-are-in-different-vpcs/30080/1 "2019-04-09T00:36:43Z")

</div>

I am trying to create an RDS MySQL instance in AWS using the Ansible rds module.

It works fine if I do not provide subnet or SG parameters. it will deploys into the default VPC. However I need to be able to define the VPC for the instance to install into.

It seams that the rds module does not suport a “vpc\_id” parameter. it has got “subnet” and “vpc\_security\_groups” parameters, but when I specify values for those I get

“msg”: “Failed to create instance: The DB instance and EC2 [security group | subnet] are in different VPCs. The DB instance is in vpc- and the EC2 [security group | subnet] is in vpc-”

Is the rds module only capable of deploying to the default VPC?

Example play:

- name: Create RDS MySQL

rds:

command: create

instance\_name: mydb

db\_engine: MySQL

size: 10

instance\_type: db.t2.micro

publicly\_accessible: no

# vpc\_id: “{{ [vpc.id](https://vpc.id/) }}” (Parameter does not exist error)

# subnet: “{{ [subnet.id](https://subnet.id/) }}” (in different VPCs error)

# vpc\_security\_groups: “{{ [sg.id](https://sg.id/) }}” (in different VPCs error)

region: “{{ ec2\_region }}”

username: admin

password: xyz123

I have tried making modifications to use “rds\_instance” instead of “rds” module. I ended up in the same place. The play will create an instance in the default VPC but I don’t know how to create the instance in the target VPC, so that the instance will connects to the correct subset and SG. Is this a bug? Should I log it to the Ansible project?

Error: “EC2 security group are in different VPCs. The DB instance is in vpc- and the EC2 security group is in vpc-”

- name: Create RDS MySQL

#rds

rds\_instance:

# command: create

# instance\_name: mydb

db\_name: mydb

db\_instance\_identifier: mydb

# db\_engine: MySQL

engine: MySQL

# size: 10

allocated\_storage: 10

instance\_type: db.t2.micro

publicly\_accessible: no

# db\_subnet\_groups vpc\_id: “{{ [vpc.id](https://vpc.id/) }}”

# subnet: “{{ [subnet.id](https://subnet.id/) }}”

# vpc\_security\_groups: “{{ sgid }}”

vpc\_security\_group\_ids: “{{ sgid }}”

region: “{{ ec2\_region }}”

username: admin

password: xyz123

tags:

Environment: testing

Application: cms
