data "aws_region" "current" {} data "aws_caller_identity" "this" {} data "aws_ecr_authorization_token" "token" {} locals { account_id = data.aws_caller_identity.this.account_id ecr_address = format("%v.dkr.ecr.%v.amazonaws.com", local.account_id, data.aws_region.current.name) ecr_repo = aws_ecr_repository.compute_image.id image_tag = coalesce(var.image_tag, formatdate("YYYYMMDDhhmmss", timestamp())) ecr_image_name = format("%v/%v:%v", local.ecr_address, local.ecr_repo, local.image_tag) } provider "docker" { registry_auth { address = local.ecr_address username = data.aws_ecr_authorization_token.token.user_name password = data.aws_ecr_authorization_token.token.password } } resource "docker_registry_image" "build_image" { name = local.ecr_image_name build { context = var.docker_source_path dockerfile = var.docker_file_path build_args = var.docker_build_args } } resource "aws_ecr_repository" "compute_image" { name = var.ecr_repository_name image_tag_mutability = var.ecr_image_tag_mutability image_scanning_configuration { scan_on_push = var.ecr_scan_on_push } encryption_configuration { encryption_type = var.ecr_encryption_type } tags = { app = var.app component = var.component environment = var.environment } } resource "aws_ecr_lifecycle_policy" "ecr_lifecycle_policy" { repository = aws_ecr_repository.compute_image.name policy = <