From b851684a78a9aff492bd6f0dafaccd1ee0f59f07 Mon Sep 17 00:00:00 2001 From: Guy Hannay Date: Thu, 4 Apr 2024 11:37:42 +0100 Subject: [PATCH] fix: ecr universal --- Makefile | 8 ++++++-- infrastructure/batch.tf | 2 +- infrastructure/data.tf | 5 ++--- infrastructure/universal/ecr.tf | 10 +++++----- infrastructure/universal/provider.tf | 26 ++++++++++++++++++++++++++ infrastructure/universal/variables.tf | 1 - 6 files changed, 40 insertions(+), 12 deletions(-) create mode 100644 infrastructure/universal/provider.tf diff --git a/Makefile b/Makefile index 8014a807..19406c9e 100644 --- a/Makefile +++ b/Makefile @@ -138,10 +138,14 @@ tf_apply: ## Apply terraform make tf_set_workspace && \ terraform -chdir=./infrastructure apply -var-file=$(CONFIG_DIR)/${env}-input-params.tfvars ${tf_build_args} +.PHONY: tf_init_universal +tf_init_universal: ## Initialise terraform + terraform -chdir=./infrastructure/universal init -backend-config=../$(TF_BACKEND_CONFIG) + .PHONY: tf_apply_universal tf_apply_universal: ## Apply terraform - make tf_set_workspace && \ - terraform -chdir=./infrastructure/universal apply -var-file=../$(CONFIG_DIR)/prod-input-params.tfvars ${tf_build_args} + terraform -chdir=./infrastructure workspace select prod && \ + terraform -chdir=./infrastructure/universal apply -var-file=../$(CONFIG_DIR)/prod-input-params.tfvars .PHONY: tf_auto_apply tf_auto_apply: ## Auto apply terraform diff --git a/infrastructure/batch.tf b/infrastructure/batch.tf index bb0c537a..a113c548 100644 --- a/infrastructure/batch.tf +++ b/infrastructure/batch.tf @@ -1,6 +1,6 @@ locals { - batch_image_ecr_url = data.aws_ecr_repository.existing[0].repository_url != null ? data.aws_ecr_repository.existing[0].repository_url : module.ecr.ecr_repository_url + batch_image_ecr_url = var.ecr_repository_uri } module "batch_compute" { diff --git a/infrastructure/data.tf b/infrastructure/data.tf index 8b32d85e..06f713c5 100644 --- a/infrastructure/data.tf +++ b/infrastructure/data.tf @@ -1,6 +1,6 @@ locals { - record_prefix = var.env == "prod" ? var.project_name : "${var.project_name}-${var.env}" - host = terraform.workspace == "prod" ? "${var.project_name}.ai.cabinetoffice.gov.uk" : "${var.project_name}-${terraform.workspace}.ai.cabinetoffice.gov.uk" + record_prefix = var.env == "prod" ? var.project_name : "${var.project_name}-${var.env}" + host = terraform.workspace == "prod" ? "${var.project_name}.ai.cabinetoffice.gov.uk" : "${var.project_name}-${terraform.workspace}.ai.cabinetoffice.gov.uk" } data "terraform_remote_state" "vpc" { @@ -25,7 +25,6 @@ data "terraform_remote_state" "platform" { } - data "terraform_remote_state" "universal" { backend = "s3" config = { diff --git a/infrastructure/universal/ecr.tf b/infrastructure/universal/ecr.tf index 274d26fe..f8bfe8e4 100644 --- a/infrastructure/universal/ecr.tf +++ b/infrastructure/universal/ecr.tf @@ -1,10 +1,10 @@ -module "ecr" { - source = "../../../i-ai-core-infrastructure//modules/ecr" - project_name = var.project_name +locals { container_name_suffix = null + ecr_name = local.container_name_suffix != null ? "${var.project_name}-${local.container_name_suffix}" : var.project_name } -locals { +module "ecr" { + source = "../../../i-ai-core-infrastructure//modules/ecr" + project_name = var.project_name container_name_suffix = null - ecr_name = local.container_name_suffix != null ? "${var.project_name}-${local.container_name_suffix}" : var.project_name } diff --git a/infrastructure/universal/provider.tf b/infrastructure/universal/provider.tf new file mode 100644 index 00000000..cec188c5 --- /dev/null +++ b/infrastructure/universal/provider.tf @@ -0,0 +1,26 @@ +terraform { + required_providers { + aws = { + source = "hashicorp/aws" + version = ">= 4.53.0" + } + } + required_version = ">= 1.3.5" + + backend "s3" { + key = "consultation-analyser/universal-terraform.tfstate" + } + +} + +provider "random" { + +} + +provider "aws" { + default_tags { + tags = { + Environment = "prod" + } + } +} diff --git a/infrastructure/universal/variables.tf b/infrastructure/universal/variables.tf index af8823fa..dd616a28 100644 --- a/infrastructure/universal/variables.tf +++ b/infrastructure/universal/variables.tf @@ -1,4 +1,3 @@ - variable "project_name" { type = string description = "Name of project"