Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Fetching the details of prod VPC
- data "aws_vpc" "prod" {
- filter {
- name = "tag:Env"
- values = ["Prod"]
- }
- }
- # Fetching the details of the dev VPC
- data "aws_vpc" "dev" {
- filter {
- name = "tag:Env"
- values = ["Dev"]
- }
- }
- # Fetching the details of Zomato-prod public route tables
- data "aws_route_table" "public" {
- filter {
- name = "tag:Name"
- values = ["Zomato-Prod-public"]
- }
- }
- # Fetching the details of Zomato-dev public route tables
- data "aws_route_table" "dev_public" {
- filter {
- name = "tag:Name"
- values = ["Zomato-Dev-public"]
- }
- }
- # Fetching the details Zomato-private prod route tables
- data "aws_route_table" "private" {
- filter {
- name = "tag:Name"
- values = ["Zomato-Prod-private"]
- }
- }
- # Fetching the details Zomato-private dev route tables
- data "aws_route_table" "dev_private" {
- filter {
- name = "tag:Name"
- values = ["Zomato-Dev-private"]
- }
- }
- # Creating the VPC peer connection
- resource "aws_vpc_peering_connection" "dev" {
- peer_vpc_id = data.aws_vpc.dev.id
- vpc_id = data.aws_vpc.prod.id
- auto_accept = true
- tags = {
- "Name" = "Peer connection"
- }
- }
- #Prod Route tables edit
- resource "aws_route" "prod_public" {
- route_table_id = data.aws_route_table.public.route_table_id
- destination_cidr_block = data.aws_vpc.dev.cidr_block
- vpc_peering_connection_id = aws_vpc_peering_connection.dev.id
- }
- resource "aws_route" "prod_private" {
- route_table_id = data.aws_route_table.private.route_table_id
- destination_cidr_block = data.aws_vpc.dev.cidr_block
- vpc_peering_connection_id = aws_vpc_peering_connection.dev.id
- }
- #Dev Route tables edi
- resource "aws_route" "dev_public" {
- route_table_id = data.aws_route_table.dev_public.route_table_id
- destination_cidr_block = data.aws_vpc.prod.cidr_block
- vpc_peering_connection_id = aws_vpc_peering_connection.dev.id
- }
- resource "aws_route" "dev_private" {
- route_table_id = data.aws_route_table.dev_private.route_table_id
- destination_cidr_block = data.aws_vpc.prod.cidr_block
- vpc_peering_connection_id = aws_vpc_peering_connection.dev.id
- }
- # Security group editing for zomato-prod bastion in order to access to zomato dev frontend & backend
- data "aws_subnet" "zomato_prod" {
- filter {
- name = "tag:Name"
- values = ["Zomato-Prod-public1"]
- }
- }
- data "aws_security_group" "frontend" {
- filter {
- name = "tag:Name"
- values = ["Zomato-Dev-frontend"]
- }
- }
- data "aws_security_group" "backend" {
- filter {
- name = "tag:Name"
- values = ["Zomato-Dev-backend"]
- }
- }
- resource "aws_security_group_rule" "dev_frontend" {
- type = "ingress"
- from_port = 22
- to_port = 22
- protocol = "tcp"
- cidr_blocks = [data.aws_subnet.zomato_prod.cidr_block]
- security_group_id = data.aws_security_group.frontend.id
- }
- resource "aws_security_group_rule" "dev_backend" {
- type = "ingress"
- from_port = 22
- to_port = 22
- protocol = "tcp"
- cidr_blocks = [data.aws_subnet.zomato_prod.cidr_block]
- security_group_id = data.aws_security_group.backend.id
- }
Advertisement
Add Comment
Please, Sign In to add comment