From 151a09a9b64a10cc8898becef245b7cdf96ee943 Mon Sep 17 00:00:00 2001 From: Anton Babenko Date: Mon, 23 May 2022 21:19:12 +0200 Subject: [PATCH] fix: Removed docker provider block from docker-build submodule (#314) --- .pre-commit-config.yaml | 2 +- examples/container-image/README.md | 7 +++- examples/container-image/main.tf | 55 +++++++++++++++++----------- examples/container-image/versions.tf | 4 ++ modules/docker-build/README.md | 13 ++++++- modules/docker-build/main.tf | 10 ----- 6 files changed, 56 insertions(+), 35 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index be3cc7aa..19dda01a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/antonbabenko/pre-commit-terraform - rev: v1.69.0 + rev: v1.71.0 hooks: - id: terraform_fmt - id: terraform_validate diff --git a/examples/container-image/README.md b/examples/container-image/README.md index 83ba91b5..238f018d 100644 --- a/examples/container-image/README.md +++ b/examples/container-image/README.md @@ -1,4 +1,4 @@ -# AWS Lambda launched from Docker Container Image example +# AWS Lambda Function deployed from Docker Container Image example Configuration in this directory creates AWS Lambda Function deployed with a Container Image. @@ -21,12 +21,14 @@ Note that this example may create resources which cost money. Run `terraform des |------|---------| | [terraform](#requirement\_terraform) | >= 0.13.1 | | [aws](#requirement\_aws) | >= 3.19 | +| [docker](#requirement\_docker) | >= 2.12 | | [random](#requirement\_random) | >= 2.0 | ## Providers | Name | Version | |------|---------| +| [aws](#provider\_aws) | >= 3.19 | | [random](#provider\_random) | >= 2.0 | ## Modules @@ -41,6 +43,9 @@ Note that this example may create resources which cost money. Run `terraform des | Name | Type | |------|------| | [random_pet.this](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet) | resource | +| [aws_caller_identity.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source | +| [aws_ecr_authorization_token.token](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ecr_authorization_token) | data source | +| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source | ## Inputs diff --git a/examples/container-image/main.tf b/examples/container-image/main.tf index 44928873..4f8928f5 100644 --- a/examples/container-image/main.tf +++ b/examples/container-image/main.tf @@ -1,3 +1,9 @@ +data "aws_region" "current" {} + +data "aws_caller_identity" "this" {} + +data "aws_ecr_authorization_token" "token" {} + provider "aws" { region = "eu-west-1" @@ -9,8 +15,12 @@ provider "aws" { skip_requesting_account_id = true } -resource "random_pet" "this" { - length = 2 +provider "docker" { + registry_auth { + address = format("%v.dkr.ecr.%v.amazonaws.com", data.aws_caller_identity.this.account_id, data.aws_region.current.name) + username = data.aws_ecr_authorization_token.token.user_name + password = data.aws_ecr_authorization_token.token.password + } } module "lambda_function_from_container_image" { @@ -33,27 +43,30 @@ module "docker_image" { create_ecr_repo = true ecr_repo = random_pet.this.id - image_tag = "1.0" - source_path = "context" + ecr_repo_lifecycle_policy = jsonencode({ + "rules" : [ + { + "rulePriority" : 1, + "description" : "Keep only the last 2 images", + "selection" : { + "tagStatus" : "any", + "countType" : "imageCountMoreThan", + "countNumber" : 2 + }, + "action" : { + "type" : "expire" + } + } + ] + }) + + image_tag = "2.0" + source_path = "context" build_args = { FOO = "bar" } - ecr_repo_lifecycle_policy = <