-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added IAC for managing ECR using terraform
Signed-off-by: Akash Singh <[email protected]>
- Loading branch information
1 parent
d076dde
commit 97ef616
Showing
2 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
provider "aws" { | ||
region = var.region | ||
access_key = var.aws_access_key | ||
secret_key = var.aws_secret_key | ||
} | ||
|
||
# VPC setup | ||
resource "aws_vpc" "main" { | ||
cidr_block = var.vpc_cidr | ||
enable_dns_hostnames = true | ||
tags = { | ||
Name = "main" | ||
} | ||
} | ||
|
||
resource "aws_subnet" "subnet_a" { | ||
vpc_id = aws_vpc.main.id | ||
cidr_block = var.subnet_cidrs[0] | ||
map_public_ip_on_launch = true | ||
availability_zone = var.availability_zones[0] | ||
} | ||
|
||
resource "aws_subnet" "subnet_b" { | ||
vpc_id = aws_vpc.main.id | ||
cidr_block = var.subnet_cidrs[1] | ||
map_public_ip_on_launch = true | ||
availability_zone = var.availability_zones[1] | ||
} | ||
|
||
resource "aws_internet_gateway" "internet_gateway" { | ||
vpc_id = aws_vpc.main.id | ||
tags = { | ||
Name = "internet_gateway" | ||
} | ||
} | ||
|
||
resource "aws_route_table" "route_table" { | ||
vpc_id = aws_vpc.main.id | ||
route { | ||
cidr_block = "0.0.0.0/0" | ||
gateway_id = aws_internet_gateway.internet_gateway.id | ||
} | ||
} | ||
|
||
resource "aws_route_table_association" "subnet_a_route" { | ||
subnet_id = aws_subnet.subnet_a.id | ||
route_table_id = aws_route_table.route_table.id | ||
} | ||
|
||
resource "aws_route_table_association" "subnet_b_route" { | ||
subnet_id = aws_subnet.subnet_b.id | ||
route_table_id = aws_route_table.route_table.id | ||
} | ||
|
||
resource "aws_security_group" "security_group" { | ||
name = "ecs-security-group" | ||
vpc_id = aws_vpc.main.id | ||
|
||
ingress { | ||
from_port = 0 | ||
to_port = 0 | ||
protocol = -1 | ||
cidr_blocks = ["0.0.0.0/0"] | ||
} | ||
|
||
egress { | ||
from_port = 0 | ||
to_port = 0 | ||
protocol = -1 | ||
cidr_blocks = ["0.0.0.0/0"] | ||
} | ||
} | ||
|
||
# ECR repositories | ||
resource "aws_ecr_repository" "repositories" { | ||
for_each = toset(var.ecr_repositories) | ||
name = each.key | ||
|
||
image_scanning_configuration { | ||
scan_on_push = true | ||
} | ||
|
||
tags = { | ||
Name = each.key | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
variable "region" { | ||
description = "The AWS region to deploy into" | ||
type = string | ||
default = "ap-south-1" | ||
} | ||
|
||
variable "aws_access_key" { | ||
description = "AWS access key" | ||
type = string | ||
sensitive = true | ||
} | ||
|
||
variable "aws_secret_key" { | ||
description = "AWS secret key" | ||
type = string | ||
sensitive = true | ||
} | ||
|
||
variable "ecr_repositories" { | ||
description = "List of ECR repositories to create" | ||
type = list(string) | ||
default = ["haalsamachar-graphql", "haalsamachar-users", "haalsamachar-blogs", "haalsamachar-auth", "haalsamachar-comments", "haalsamachar-frontend"] | ||
} | ||
variable "vpc_cidr" { | ||
description = "CIDR block for the VPC" | ||
type = string | ||
default = "10.0.0.0/16" | ||
} |