Skip to content

Commit dbfdcfe

Browse files
committed
Add terraform scripts
1 parent 7881d41 commit dbfdcfe

File tree

4 files changed

+83
-0
lines changed

4 files changed

+83
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
locals {
2+
region = "us-east-1"
3+
}
4+
5+
terraform {
6+
backend "s3" {
7+
bucket = "terraform-tasks-dependencies"
8+
key = "dependencies"
9+
region = "us-east-1"
10+
}
11+
12+
required_providers {
13+
aws = {
14+
source = "hashicorp/aws"
15+
version = "~> 5.53"
16+
}
17+
}
18+
}
19+
20+
provider "aws" {
21+
region = local.region
22+
23+
default_tags {
24+
tags = {
25+
app = var.app
26+
environment = var.environment
27+
owner = "felipe"
28+
url = "https://github.com/felipeoriani"
29+
}
30+
}
31+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
output "task_service_repository_url" {
2+
value = aws_ecr_repository.task_service_repository.repository_url
3+
description = "AWS ECR task service repository URL"
4+
}
5+
6+
output "task_service_repository_name" {
7+
value = aws_ecr_repository.task_service_repository.name
8+
description = "AWS ECR task service repository name"
9+
}
10+
11+
output "task_service_repository_arn" {
12+
value = aws_ecr_repository.task_service_repository.arn
13+
description = "AWS ECR task service repository ARN"
14+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
locals {
2+
imageCountMoreThan = 3
3+
}
4+
5+
resource "aws_ecr_repository" "task_service_repository" {
6+
name = "${var.app}-service-${var.environment}"
7+
}
8+
9+
resource "aws_ecr_lifecycle_policy" "task_service_repository_policy" {
10+
repository = aws_ecr_repository.task_service_repository.name
11+
policy = <<EOF
12+
{
13+
"rules": [
14+
{
15+
"rulePriority": 1,
16+
"description": "Retain only the last ${local.imageCountMoreThan} images.",
17+
"selection": {
18+
"tagStatus": "any",
19+
"countType": "imageCountMoreThan",
20+
"countNumber": ${local.imageCountMoreThan}
21+
},
22+
"action": {
23+
"type": "expire"
24+
}
25+
}
26+
]
27+
}
28+
EOF
29+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
variable "app" {
2+
default = "task"
3+
description = "App name used across the resources."
4+
}
5+
6+
variable "environment" {
7+
default = "staging"
8+
description = "Environment to work on."
9+
}

0 commit comments

Comments
 (0)