akshaykarle / terraform-provider-mongodbatlas

Terraform provider for MongoDB Atlas
Mozilla Public License 2.0
122 stars 54 forks source link

No auto accept VPC peering connection #1

Closed surjsingh closed 6 years ago

surjsingh commented 6 years ago

Hi,

Just wanted to check if we can auto-accept the VPC peering connection in this provider? or is it already there and I am missing something. Plus, the 'region' parameter is not getting accepted as 'eu-west-1' rather getting accepted as 'EU_WEST_1'. This doesn't go well with aws region terminology.

akshaykarle commented 6 years ago

Hey @singhsurjeet, to auto-accept the VPC peering connection you should use the aws_vpc_peering_connection_accepter resource which is part of the terraform AWS provider. So something like the following should do it:

# Create a MongoDB Atlas VPC
resource "mongodbatlas_container" "test" {
  group = "${var.mongodb_atlas_group_id}"
  atlas_cidr_block = "10.0.0.0/21"
  provider_name = "AWS"
  region = "US_EAST_1"
}

# Initiate a Peering connection
resource "mongodbatlas_vpc_peering_connection" "test" {
  group = "${var.mongodb_atlas_group_id}"
  aws_account_id = "${var.aws_account_id}"
  vpc_id = "${var.vpc_id}"
  route_table_cidr_block = "${var.vpc_cidr_block}"
  container_id = "${mongodbatlas_container.test.id}"
}

# Auto-Accept the Peering connection to your VPC
resource "aws_vpc_peering_connection_accepter" "your_vpc_to_mongodb_atlas" {
  vpc_peering_connection_id = "${mongodbatlas_vpc_peering_connection.test.connection_id}"
  auto_accept = true
}

As or the region parameter naming, I'm just following the MongoDB Atlas API's region names under the Provider Settings. Note that it also supports creating clusters in GCP and Azure so using AWS region terminology won't work with the other providers. Hope this answers your questions and sorry for the delay in response.