provider "aws" { region = data.terraform_remote_state.infra.outputs.region default_tags { tags = { Project = "semantic-search-aws-docs" } } } provider "docker" { registry_auth { address = local.aws_ecr_url username = data.aws_ecr_authorization_token.token.user_name password = data.aws_ecr_authorization_token.token.password } } terraform { required_providers { docker = { source = "kreuzwerker/docker" version = ">=2.16.0" } } } data "aws_caller_identity" "current" {} data "aws_ecr_authorization_token" "token" {} locals { aws_ecr_url = "${data.aws_caller_identity.current.account_id}.dkr.ecr.${data.terraform_remote_state.infra.outputs.region}.amazonaws.com" build_environment = length(regexall(".*local.*", var.script_name)) > 0 ? "local" : "amazonlinux:2" # if the documents are local then we use the Docker container that can handle local documents } resource "aws_ecr_repository" "ingestion_job" { name = "ingestion-job" force_delete = true } resource "docker_registry_image" "ingestion_job" { name = docker_image.ingestion_job_image.name } resource "docker_image" "ingestion_job_image" { name = "${local.aws_ecr_url}/${aws_ecr_repository.ingestion_job.name}:latest" build { context = "${path.cwd}/" dockerfile = "Dockerfile" build_args = { DOCS_SRC = var.docs_src SCRIPT_NAME = var.script_name BUILD_ENV = local.build_environment } } } data "terraform_remote_state" "infra" { backend = "s3" config = { bucket = var.infra_tf_state_s3_bucket key = var.infra_tf_state_s3_key region = var.infra_region } } resource "aws_ecs_task_definition" "ingestion_job" { family = "ingestion-job" container_definitions = <