Skip to content

Commit 151a09a

Browse files
authored
fix: Removed docker provider block from docker-build submodule (#314)
1 parent 19b9f11 commit 151a09a

File tree

6 files changed

+56
-35
lines changed

6 files changed

+56
-35
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/antonbabenko/pre-commit-terraform
3-
rev: v1.69.0
3+
rev: v1.71.0
44
hooks:
55
- id: terraform_fmt
66
- id: terraform_validate

examples/container-image/README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# AWS Lambda launched from Docker Container Image example
1+
# AWS Lambda Function deployed from Docker Container Image example
22

33
Configuration in this directory creates AWS Lambda Function deployed with a Container Image.
44

@@ -21,12 +21,14 @@ Note that this example may create resources which cost money. Run `terraform des
2121
|------|---------|
2222
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 |
2323
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.19 |
24+
| <a name="requirement_docker"></a> [docker](#requirement\_docker) | >= 2.12 |
2425
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 2.0 |
2526

2627
## Providers
2728

2829
| Name | Version |
2930
|------|---------|
31+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.19 |
3032
| <a name="provider_random"></a> [random](#provider\_random) | >= 2.0 |
3133

3234
## Modules
@@ -41,6 +43,9 @@ Note that this example may create resources which cost money. Run `terraform des
4143
| Name | Type |
4244
|------|------|
4345
| [random_pet.this](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet) | resource |
46+
| [aws_caller_identity.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
47+
| [aws_ecr_authorization_token.token](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ecr_authorization_token) | data source |
48+
| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |
4449

4550
## Inputs
4651

examples/container-image/main.tf

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
data "aws_region" "current" {}
2+
3+
data "aws_caller_identity" "this" {}
4+
5+
data "aws_ecr_authorization_token" "token" {}
6+
17
provider "aws" {
28
region = "eu-west-1"
39

@@ -9,8 +15,12 @@ provider "aws" {
915
skip_requesting_account_id = true
1016
}
1117

12-
resource "random_pet" "this" {
13-
length = 2
18+
provider "docker" {
19+
registry_auth {
20+
address = format("%v.dkr.ecr.%v.amazonaws.com", data.aws_caller_identity.this.account_id, data.aws_region.current.name)
21+
username = data.aws_ecr_authorization_token.token.user_name
22+
password = data.aws_ecr_authorization_token.token.password
23+
}
1424
}
1525

1626
module "lambda_function_from_container_image" {
@@ -33,27 +43,30 @@ module "docker_image" {
3343

3444
create_ecr_repo = true
3545
ecr_repo = random_pet.this.id
36-
image_tag = "1.0"
37-
source_path = "context"
46+
ecr_repo_lifecycle_policy = jsonencode({
47+
"rules" : [
48+
{
49+
"rulePriority" : 1,
50+
"description" : "Keep only the last 2 images",
51+
"selection" : {
52+
"tagStatus" : "any",
53+
"countType" : "imageCountMoreThan",
54+
"countNumber" : 2
55+
},
56+
"action" : {
57+
"type" : "expire"
58+
}
59+
}
60+
]
61+
})
62+
63+
image_tag = "2.0"
64+
source_path = "context"
3865
build_args = {
3966
FOO = "bar"
4067
}
41-
ecr_repo_lifecycle_policy = <<EOF
42-
{
43-
"rules": [
44-
{
45-
"rulePriority": 1,
46-
"description": "Keep only the last 2 images",
47-
"selection": {
48-
"tagStatus": "any",
49-
"countType": "imageCountMoreThan",
50-
"countNumber": 2
51-
},
52-
"action": {
53-
"type": "expire"
54-
}
55-
}
56-
]
5768
}
58-
EOF
69+
70+
resource "random_pet" "this" {
71+
length = 2
5972
}

examples/container-image/versions.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ terraform {
66
source = "hashicorp/aws"
77
version = ">= 3.19"
88
}
9+
docker = {
10+
source = "kreuzwerker/docker"
11+
version = ">= 2.12"
12+
}
913
random = {
1014
source = "hashicorp/random"
1115
version = ">= 2.0"

modules/docker-build/README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,19 @@ This Terraform module is the part of [serverless.tf framework](https://github.co
66

77
## Usage
88

9-
### Complete example of Lambda Function deployment via AWS CodeDeploy
9+
### AWS Lambda Function deployed from Docker Container Image
1010

1111
```hcl
12+
data "aws_ecr_authorization_token" "token" {}
13+
14+
provider "docker" {
15+
registry_auth {
16+
address = "835367859852.dkr.ecr.eu-west-1.amazonaws.com"
17+
username = data.aws_ecr_authorization_token.token.user_name
18+
password = data.aws_ecr_authorization_token.token.password
19+
}
20+
}
21+
1222
module "lambda_function" {
1323
source = "terraform-aws-modules/lambda/aws"
1424
@@ -65,7 +75,6 @@ No modules.
6575
| [aws_ecr_repository.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecr_repository) | resource |
6676
| [docker_registry_image.this](https://registry.terraform.io/providers/kreuzwerker/docker/latest/docs/resources/registry_image) | resource |
6777
| [aws_caller_identity.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
68-
| [aws_ecr_authorization_token.token](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ecr_authorization_token) | data source |
6978
| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |
7079

7180
## Inputs

modules/docker-build/main.tf

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,13 @@ data "aws_region" "current" {}
22

33
data "aws_caller_identity" "this" {}
44

5-
data "aws_ecr_authorization_token" "token" {}
6-
75
locals {
86
ecr_address = coalesce(var.ecr_address, format("%v.dkr.ecr.%v.amazonaws.com", data.aws_caller_identity.this.account_id, data.aws_region.current.name))
97
ecr_repo = var.create_ecr_repo ? aws_ecr_repository.this[0].id : var.ecr_repo
108
image_tag = coalesce(var.image_tag, formatdate("YYYYMMDDhhmmss", timestamp()))
119
ecr_image_name = format("%v/%v:%v", local.ecr_address, local.ecr_repo, local.image_tag)
1210
}
1311

14-
provider "docker" {
15-
registry_auth {
16-
address = local.ecr_address
17-
username = data.aws_ecr_authorization_token.token.user_name
18-
password = data.aws_ecr_authorization_token.token.password
19-
}
20-
}
21-
2212
resource "docker_registry_image" "this" {
2313
name = local.ecr_image_name
2414

0 commit comments

Comments
 (0)