diff --git a/examples/lambda/providers.tf b/examples/lambda/providers.tf index 5721691..274639b 100644 --- a/examples/lambda/providers.tf +++ b/examples/lambda/providers.tf @@ -15,9 +15,26 @@ terraform { source = "hashicorp/tls" version = "4.0.3" } + + docker = { + source = "kreuzwerker/docker" + version = "3.0.2" + } } } provider "aws" { region = var.region } + +# Equivalent of aws ecr get-login +data "aws_ecr_authorization_token" "ecr_auth" {} + +provider "docker" { + host = "unix:///var/run/docker.sock" # Use the appropriate Docker socket for your system + registry_auth { + username = data.aws_ecr_authorization_token.ecr_auth.user_name + password = data.aws_ecr_authorization_token.ecr_auth.password + address = "${data.aws_caller_identity.current.account_id}.dkr.ecr.${var.region}.amazonaws.com" + } +} diff --git a/modules/lambda-registrator/main.tf b/modules/lambda-registrator/main.tf index 80d0226..3e16f07 100644 --- a/modules/lambda-registrator/main.tf +++ b/modules/lambda-registrator/main.tf @@ -1,19 +1,5 @@ # Copyright (c) HashiCorp, Inc. # SPDX-License-Identifier: MPL-2.0 - -terraform { - required_providers { - docker = { - source = "kreuzwerker/docker" - version = "3.0.2" - } - aws = { - source = "hashicorp/aws" - version = "~> 5.0" - } - } -} - locals { on_vpc = length(var.subnet_ids) > 0 && length(var.security_group_ids) > 0 vpc_config = local.on_vpc ? [{ @@ -29,9 +15,6 @@ locals { data "aws_caller_identity" "current" {} -provider "aws" { - region = var.region -} resource "aws_iam_role" "registration" { name = var.name @@ -154,18 +137,6 @@ resource "aws_ecr_repository" "lambda-registrator" { force_delete = true } -# Equivalent of aws ecr get-login -data "aws_ecr_authorization_token" "ecr_auth" {} - -provider "docker" { - host = "unix:///var/run/docker.sock" # Use the appropriate Docker socket for your system - registry_auth { - username = data.aws_ecr_authorization_token.ecr_auth.user_name - password = data.aws_ecr_authorization_token.ecr_auth.password - address = "${data.aws_caller_identity.current.account_id}.dkr.ecr.${var.region}.amazonaws.com" - } -} - resource "aws_ecr_pull_through_cache_rule" "pull_through_cache_rule" { count = var.pull_through ? 1 : 0