forked from DataTalksClub/mlops-zoomcamp
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.tf
42 lines (35 loc) · 1.31 KB
/
main.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
35
36
37
38
39
40
41
42
resource "aws_ecr_repository" "ecr_repo" {
name = var.repo_name
image_tag_mutability = "MUTABLE"
image_scanning_configuration {
scan_on_push = false
}
force_delete = true
}
resource "null_resource" "ecr_image" {
triggers = {
python_file = md5(file(var.lambda_function_local_path))
docker_file = md5(file(var.docker_image_local_path))
}
provisioner "local-exec" {
command = <<EOF
aws ecr get-login-password --region ${var.region} | docker login --username AWS --password-stdin ${var.account_id}.dkr.ecr.${var.region}.amazonaws.com
cd ../
docker build --build-arg STREAM_NAME_ARG=${var.stream_name} --build-arg RUN_ID_ARG=${var.run_id} --build-arg TEST_RUN_ARG=${var.test_run} --build-arg MODEL_BUCKET_ARG=${var.model_bucket} -t ${aws_ecr_repository.ecr_repo.repository_url}:${var.ecr_image_tag} .
docker push ${aws_ecr_repository.ecr_repo.repository_url}:${var.ecr_image_tag}
EOF
}
depends_on = [
aws_ecr_repository.ecr_repo
]
}
data aws_ecr_image lambda_image{
depends_on = [
null_resource.ecr_image
]
repository_name = var.repo_name
image_tag = var.ecr_image_tag
}
output "image_uri" {
value = "${aws_ecr_repository.ecr_repo.repository_url}:${data.aws_ecr_image.lambda_image.image_tag}"
}