-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathecr.tf
34 lines (28 loc) · 902 Bytes
/
ecr.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# ECR Repository
resource "aws_ecr_repository" "ecr" {
name = "${var.project_name}-runtime"
force_delete = true
}
# Build Image
resource "null_resource" "build" {
depends_on = [
aws_ecr_repository.ecr
]
triggers = {
build_number = timestamp()
}
provisioner "local-exec" {
interpreter = [
"/bin/sh",
"-c"
]
command = <<-COMMAND
# Login to ECR (AWS STS AssumeRole)
aws ecr get-login-password --region ${data.aws_region.current.name} | docker login --username AWS --password-stdin ${data.aws_caller_identity.current.account_id}.dkr.ecr.${data.aws_region.current.name}.amazonaws.com
# Build Image
docker build -t ${aws_ecr_repository.ecr.repository_url}:latest . -f Dockerfile --platform linux/arm64 --provenance=false
# Push Image
docker push ${aws_ecr_repository.ecr.repository_url}:latest
COMMAND
}
}