From 0704393838cd382440bc47819b56ef4d0499190e Mon Sep 17 00:00:00 2001 From: Cristian Magherusan-Stanciu Date: Thu, 16 Feb 2023 00:28:59 +0100 Subject: [PATCH] Update provider dependencies - Major update of the kreuzwerker/docker dependency. - That was a breaking change which required some changes, but all in all the Docker image handling code looks much better now. --- modules/lambda/docker.tf | 39 +++++++++++++++--------------- modules/lambda/docker/Dockerfile | 1 - modules/lambda/main.tf | 2 +- modules/regional/resources/main.tf | 2 +- 4 files changed, 22 insertions(+), 22 deletions(-) delete mode 100755 modules/lambda/docker/Dockerfile diff --git a/modules/lambda/docker.tf b/modules/lambda/docker.tf index 92d8073..2c7b925 100644 --- a/modules/lambda/docker.tf +++ b/modules/lambda/docker.tf @@ -1,4 +1,7 @@ - +locals { + src_image = "${var.lambda_source_ecr}/${var.lambda_source_image}:${var.lambda_source_image_tag}" + dst_image = "${aws_ecr_repository.autospotting.repository_url}:${var.lambda_source_image_tag}" +} resource "aws_ecr_repository" "autospotting" { name = "autospotting-${module.label.id}" image_tag_mutability = "MUTABLE" @@ -13,11 +16,16 @@ resource "aws_ecr_repository" "autospotting" { data "aws_ecr_authorization_token" "source" { registry_id = split(".", var.lambda_source_ecr)[0] - } + data "aws_ecr_authorization_token" "destination" {} provider "docker" { + registry_auth { + address = var.lambda_source_ecr + username = data.aws_ecr_authorization_token.source.user_name + password = data.aws_ecr_authorization_token.source.password + } registry_auth { address = split("/", aws_ecr_repository.autospotting.repository_url)[0] username = data.aws_ecr_authorization_token.destination.user_name @@ -25,24 +33,17 @@ provider "docker" { } } -resource "local_file" "Dockerfile" { - content = "FROM ${var.lambda_source_ecr}/${var.lambda_source_image}:${var.lambda_source_image_tag}" - filename = "${path.module}/docker/Dockerfile" +resource "docker_image" "base_image" { + name = local.src_image +} + +resource "docker_tag" "image" { + source_image = docker_image.base_image.name + target_image = local.dst_image } resource "docker_registry_image" "destination" { - name = "${aws_ecr_repository.autospotting.repository_url}:${var.lambda_source_image_tag}" + name = local.dst_image keep_remotely = false - build { - context = "${path.module}/docker" - - auth_config { - host_name = var.lambda_source_ecr - user_name = data.aws_ecr_authorization_token.source.user_name - password = data.aws_ecr_authorization_token.source.password - } - } - depends_on = [ - local_file.Dockerfile, - ] -} \ No newline at end of file + depends_on = [docker_tag.image] +} diff --git a/modules/lambda/docker/Dockerfile b/modules/lambda/docker/Dockerfile deleted file mode 100755 index 25d37b7..0000000 --- a/modules/lambda/docker/Dockerfile +++ /dev/null @@ -1 +0,0 @@ -FROM 709825985650.dkr.ecr.us-east-1.amazonaws.com/cloudutil/autospotting:1.0.8-rc3 diff --git a/modules/lambda/main.tf b/modules/lambda/main.tf index 92e5dcb..18b8cdd 100644 --- a/modules/lambda/main.tf +++ b/modules/lambda/main.tf @@ -2,7 +2,7 @@ terraform { required_providers { docker = { source = "kreuzwerker/docker" - version = "~> 2.15.0" + version = "~> 3.0" } } } diff --git a/modules/regional/resources/main.tf b/modules/regional/resources/main.tf index 2b8c04d..47a53bc 100644 --- a/modules/regional/resources/main.tf +++ b/modules/regional/resources/main.tf @@ -2,7 +2,7 @@ terraform { required_providers { aws = { source = "hashicorp/aws" - version = "~> 3.0" + version = "~> 4.0" } } }