Skip to content

Commit

Permalink
Merge pull request #65 from ghrcdaac/mlh0079-private-ecr
Browse files Browse the repository at this point in the history
Mlh0079 private ecr
  • Loading branch information
sflynn-itsc authored Apr 30, 2024
2 parents 95aa106 + 8b3b62e commit 60a7e1d
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 35 deletions.
36 changes: 4 additions & 32 deletions modules/dmrpp_lambda/main.tf
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
locals {
image_version = regex("v\\d+.\\d+.\\d+", var.docker_image)
deploy_lambda = length(var.cumulus_lambda_role_arn) > 0 ? true : false
deploy_lambda = length(var.cumulus_lambda_role_arn) > 0
}

resource "aws_lambda_function" "ghrc_dmrpp" {
resource "aws_lambda_function" "dmrpp_generator" {
count = local.deploy_lambda ? 1 : 0
depends_on = [terraform_data.build_image, aws_ecr_repository.ghrc_dmrpp_lambda]

function_name = "${var.prefix}-ghrc-dmrpp"
function_name = "${var.prefix}-dmrpp-generator"
package_type = "Image"
image_uri = "${aws_ecr_repository.ghrc_dmrpp_lambda[0].repository_url}:${local.image_version}"
image_uri = var.docker_image
role = var.cumulus_lambda_role_arn
timeout = var.timeout
memory_size = var.memory_size
Expand All @@ -31,29 +29,3 @@ resource "aws_lambda_function" "ghrc_dmrpp" {
}
}
}

resource "aws_ecr_repository" "ghrc_dmrpp_lambda" {
count = local.deploy_lambda ? 1 : 0
name = "${var.prefix}_ghrc_dmrpp_lambda"
image_tag_mutability = "MUTABLE"
force_delete = true

image_scanning_configuration {
scan_on_push = true
}
}

resource "terraform_data" "build_image" {
count = local.deploy_lambda ? 1 : 0
depends_on = [aws_ecr_repository.ghrc_dmrpp_lambda]
triggers_replace = [var.docker_image]

provisioner "local-exec" {
command = <<-EOT
docker pull ${var.docker_image}
aws ecr get-login-password --region ${var.region} | docker login --username AWS --password-stdin ${var.account_id}.dkr.ecr.${var.region}.amazonaws.com
docker tag ${var.docker_image} ${aws_ecr_repository.ghrc_dmrpp_lambda[0].repository_url}:${local.image_version}
docker push ${aws_ecr_repository.ghrc_dmrpp_lambda[0].repository_url}:${local.image_version}
EOT
}
}
2 changes: 1 addition & 1 deletion modules/dmrpp_lambda/output.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
output "dmrpp_lambda_arn" {
value = join("", aws_lambda_function.ghrc_dmrpp.*.arn)
value = join("", aws_lambda_function.dmrpp_generator.*.arn)
}
2 changes: 1 addition & 1 deletion modules/dmrpp_lambda/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ variable "prefix" {

variable "cumulus_lambda_role_arn" {
type = string
nullable = true
default = ""
}

variable "timeout" {
Expand Down
2 changes: 1 addition & 1 deletion modules/dmrpp_service/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module "dmrpp_service" {
source = "https://github.com/nasa/cumulus/releases/download/v18.2.0/terraform-aws-cumulus-ecs-service.zip"

prefix = var.prefix
name = "${var.prefix}_dmrpp_generator"
name = "dmrpp_generator"
tags = local.default_tags
cluster_arn = var.cluster_arn
desired_count = var.desired_count
Expand Down

0 comments on commit 60a7e1d

Please sign in to comment.