RDS DB instance and EC2 security group are in different VPCs

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 }}” (Parameter does not exist error)

subnet: “{{ subnet.id }}” (in different VPCs error)

vpc_security_groups: “{{ 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 }}”

subnet: “{{ subnet.id }}”

vpc_security_groups: “{{ sgid }}”

vpc_security_group_ids: “{{ sgid }}”

region: “{{ ec2_region }}”

username: admin

password: xyz123

tags:

Environment: testing

Application: cms