Skip to content

Commit 5b828b9

Browse files
authored
Revert "Ajsanon/ux updates (#80)" (#81)
This reverts commit db2b43a.
1 parent db2b43a commit 5b828b9

File tree

7 files changed

+64
-145
lines changed

7 files changed

+64
-145
lines changed

CHANGELOG.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ FEATURES
44
* Add support for storing parameter values greater than 4 KB. The `lambda-registrator` module and source code have been updated to accept a configurable value for the [SSM parameter tier](https://docs.aws.amazon.com/systems-manager/latest/userguide/parameter-store-advanced-parameters.html). This allows users to choose if they want to use the `Advanced` tier feature. Charges apply for the `Advanved` tier so if the tier is not expressly set to `Advanced`, then the `Standard` tier will be used. Using the `Advanced` tier allows for parameter values up to 8 KB. The Lambda-registrator Terraform module can be configured using the new `consul_extension_data_tier` variable.
55
[[GH-78]](https://github.com/hashicorp/terraform-aws-consul-lambda/pull/78)
66

7-
* Add support for pushing `consul-lambda-registrator` public image to private ecr repo through terraform.
8-
[[GH-80]](https://github.com/hashicorp/terraform-aws-consul-lambda/pull/80)
9-
107
## 0.1.0-beta4 (Apr 28, 2023)
118

129
IMPROVEMENTS

examples/lambda/README.md

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,57 @@ cd terraform-aws-consul-lambda/examples/lambda
5151
git checkout v${VERSION}
5252
```
5353

54-
## Set your AWS region
54+
## Set your AWS account ID and region
5555

56-
Subsequent steps require knowledge of the AWS region that you want to deploy the example resources to.
56+
Subsequent steps require knowledge of your AWS account ID and the AWS region that you want to deploy the example resources to.
5757
Export these values to environment variables using the commands below.
58-
Replace `<region>` with your AWS region.
58+
Replace `<account_id>` and `<region>` with your AWS account ID and region, respectively.
5959

6060
```shell
61+
export AWS_ACCOUNT_ID=<account_id>
6162
export AWS_REGION=<region>
6263
```
6364

65+
## Publish `consul-lambda-registrator`
66+
67+
In this section you will pull the `consul-lambda-registrator` image from the AWS Public ECR Gallery and publish it to a private ECR repository using `docker`. This is required because AWS Lambda functions must use images from a private ECR repository. They are not able to use images from the Public ECR Gallery.
68+
69+
### Pull `consul-lambda-registrator`
70+
71+
Use the following command to pull the `consul-lambda-registrator` from the AWS Public ECR to your local machine.
72+
73+
```shell
74+
docker pull public.ecr.aws/hashicorp/consul-lambda-registrator:${VERSION}
75+
```
76+
77+
### Log in to AWS ECR
78+
79+
```shell
80+
aws ecr get-login-password --region ${AWS_REGION} | docker login --username AWS --password-stdin ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com
81+
```
82+
83+
### Create a private ECR repository
84+
85+
Use the following command to create a private ECR repository for `consul-lambda-registrator`.
86+
87+
```shell
88+
aws ecr create-repository \
89+
--repository-name consul-lambda-registrator \
90+
--image-scanning-configuration scanOnPush=true \
91+
--region ${AWS_REGION}
92+
```
93+
94+
### Push `consul-lambda-registrator`
95+
96+
Use the following commands to push the `consul-lambda-registrator` image to the private ECR repository you created in the previous step.
97+
98+
```shell
99+
docker tag \
100+
public.ecr.aws/hashicorp/consul-lambda-registrator:${VERSION} \
101+
${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/consul-lambda-registrator:${VERSION}
102+
103+
docker push ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/consul-lambda-registrator:${VERSION}
104+
```
64105

65106
## Download the `consul-lambda-extension`
66107

@@ -69,7 +110,7 @@ This example Terraform workspace will use the zip package to deploy the `consul-
69110
add it to the `lambda-app-2` function so that it can call services within the Consul service mesh.
70111

71112
```shell
72-
curl -o consul-lambda-extension.zip "https://releases.hashicorp.com/consul-lambda-extension/${VERSION}/consul-lambda-extension_${VERSION}-beta4_linux_amd64.zip"
113+
curl -o consul-lambda-extension.zip https://releases.hashicorp.com/consul-lambda-extension/${VERSION}/consul-lambda-extension_${VERSION}_linux_amd64.zip
73114
```
74115

75116
## Build the example Lambda function
@@ -98,6 +139,7 @@ terraform init
98139
terraform apply \
99140
-var "name=${USER}" \
100141
-var "region=${AWS_REGION}" \
142+
-var "ecr_image_uri=${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/consul-lambda-registrator:${VERSION}" \
101143
-var "ingress_cidrs=[\"${MY_IP}\"]"
102144
```
103145

@@ -219,6 +261,7 @@ Use the following command to clean up the resources managed by Terraform.
219261
terraform destroy \
220262
-var "name=${USER}" \
221263
-var "region=${AWS_REGION}" \
264+
-var "ecr_image_uri=${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/consul-lambda-registrator:${VERSION}" \
222265
-var "ingress_cidrs=[\"${MY_IP}\"]"
223266
```
224267

examples/lambda/lambda/variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ variable "invocation_mode" {
9494
default = "SYNCHRONOUS"
9595
validation {
9696
condition = contains(["SYNCHRONOUS", "ASYNCHRONOUS"], var.invocation_mode)
97-
error_message = "Variable invocation_mode must be one of SYNCHRONOUS or ASYNCHRONOUS."
97+
error_message = "invocation_mode must be one of SYNCHRONOUS or ASYNCHRONOUS"
9898
}
9999
}
100100

examples/lambda/registrator.tf

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44
module "consul_lambda_registrator" {
55
source = "../../modules/lambda-registrator"
66
name = "${var.name}-lambda-registrator"
7+
ecr_image_uri = var.ecr_image_uri
78
consul_http_addr = "http://${module.dev_consul_server.server_dns}:8500"
89
consul_extension_data_prefix = "/${var.name}"
910
subnet_ids = module.vpc.private_subnets
1011
security_group_ids = [module.vpc.default_security_group_id]
1112
sync_frequency_in_minutes = 1
12-
enable_pull_through_cache = var.enable_pull_through_cache
13-
region = var.region
1413
}

examples/lambda/variables.tf

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ variable "name" {
66
type = string
77
}
88

9-
variable "lambda_registrator_image" {
10-
description = "The Consul Lambda Registrator image for consul-lambda-registrator."
9+
variable "ecr_image_uri" {
10+
description = "The private ECR image URI for consul-lambda-registrator."
1111
type = string
12-
default = "public.ecr.aws/hashicorp/consul-lambda-registrator:0.1.0-beta4"
1312
}
1413

1514
variable "region" {
@@ -39,9 +38,3 @@ variable "consul_lambda_extension_arn" {
3938
type = string
4039
default = ""
4140
}
42-
43-
variable "enable_pull_through_cache" {
44-
description = "Flag to determine if a pull-through cache method will be used to obtain the appropriate ECR image"
45-
type = bool
46-
default = false
47-
}

modules/lambda-registrator/main.tf

Lines changed: 3 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,16 @@
11
# Copyright (c) HashiCorp, Inc.
22
# SPDX-License-Identifier: MPL-2.0
33

4-
terraform {
5-
required_providers {
6-
docker = {
7-
source = "kreuzwerker/docker"
8-
version = "3.0.2"
9-
}
10-
}
11-
}
124
locals {
135
on_vpc = length(var.subnet_ids) > 0 && length(var.security_group_ids) > 0
146
vpc_config = local.on_vpc ? [{
157
subnet_ids = var.subnet_ids
168
security_group_ids = var.security_group_ids
179
}] : []
18-
cron_key = "${var.name}-cron"
19-
lambda_events_key = "${var.name}-lambda_events"
20-
image_parts = split(":", var.consul_lambda_registrator_image)
21-
image_tag = local.image_parts[1]
22-
image_path_parts = split("/", local.image_parts[0])
23-
image_username = local.image_path_parts[1]
24-
image_name = local.image_path_parts[2]
25-
ecr_image_uri = "${data.aws_caller_identity.current.account_id}.dkr.ecr.${var.region}.amazonaws.com/${var.private_ecr_repo_name}:${local.image_tag}"
26-
ecr_image_uri_pull_through = "${data.aws_caller_identity.current.account_id}.dkr.ecr.${var.region}.amazonaws.com/${var.ecr_repository_prefix}/${local.image_username}/${local.image_name}:${local.image_tag}"
27-
}
28-
29-
# Equivalent of aws ecr get-login
30-
data "aws_ecr_authorization_token" "ecr_auth" {}
31-
32-
provider "docker" {
33-
host = var.docker_host
34-
registry_auth {
35-
username = data.aws_ecr_authorization_token.ecr_auth.user_name
36-
password = data.aws_ecr_authorization_token.ecr_auth.password
37-
address = "${data.aws_caller_identity.current.account_id}.dkr.ecr.${var.region}.amazonaws.com"
38-
}
10+
cron_key = "${var.name}-cron"
11+
lambda_events_key = "${var.name}-lambda_events"
3912
}
4013

41-
data "aws_caller_identity" "current" {}
42-
4314
resource "aws_iam_role" "registration" {
4415
name = var.name
4516

@@ -156,51 +127,8 @@ resource "aws_iam_role_policy_attachment" "lambda_logs" {
156127
policy_arn = aws_iam_policy.policy.arn
157128
}
158129

159-
resource "aws_ecr_repository" "lambda-registrator" {
160-
count = var.enable_pull_through_cache ? 0 : 1
161-
name = var.private_ecr_repo_name
162-
force_delete = true
163-
}
164-
165-
166-
resource "aws_ecr_pull_through_cache_rule" "pull_through_cache_rule" {
167-
count = var.enable_pull_through_cache ? 1 : 0
168-
ecr_repository_prefix = var.ecr_repository_prefix
169-
upstream_registry_url = var.upstream_registry_url
170-
}
171-
172-
resource "docker_image" "lambda_registrator" {
173-
name = var.enable_pull_through_cache ? local.ecr_image_uri_pull_through : var.consul_lambda_registrator_image
174-
depends_on = [
175-
aws_ecr_pull_through_cache_rule.pull_through_cache_rule
176-
]
177-
}
178-
179-
resource "docker_tag" "lambda_registrator_tag" {
180-
count = var.enable_pull_through_cache ? 0 : 1
181-
source_image = docker_image.lambda_registrator.name
182-
target_image = local.ecr_image_uri
183-
}
184-
185-
resource "null_resource" "push_image" {
186-
count = var.enable_pull_through_cache ? 0 : 1
187-
188-
provisioner "local-exec" {
189-
command = "docker push ${local.ecr_image_uri}"
190-
}
191-
192-
depends_on = [
193-
docker_tag.lambda_registrator_tag
194-
]
195-
}
196-
resource "time_sleep" "wait_30_seconds" {
197-
count = var.enable_pull_through_cache ? 1 : 0
198-
depends_on = [docker_image.lambda_registrator]
199-
200-
create_duration = "30s"
201-
}
202130
resource "aws_lambda_function" "registration" {
203-
image_uri = var.enable_pull_through_cache ? local.ecr_image_uri_pull_through : local.ecr_image_uri
131+
image_uri = var.ecr_image_uri
204132
package_type = "Image"
205133
function_name = var.name
206134
role = aws_iam_role.registration.arn
@@ -240,11 +168,6 @@ resource "aws_lambda_function" "registration" {
240168
security_group_ids = vpc_config.value["security_group_ids"]
241169
}
242170
}
243-
depends_on = [
244-
null_resource.push_image,
245-
time_sleep.wait_30_seconds,
246-
]
247-
248171
}
249172

250173
module "eventbridge" {

modules/lambda-registrator/variables.tf

Lines changed: 10 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,16 @@ variable "reserved_concurrent_executions" {
7575
default = -1
7676
}
7777

78+
variable "ecr_image_uri" {
79+
description = <<-EOT
80+
The ECR image URI for consul-lambda-registrator. The image must be in the
81+
same AWS region and in a private ECR repository. Due to these constraints,
82+
the public ECR images (https://gallery.ecr.aws/hashicorp/consul-lambda-registrator)
83+
cannot be used directly. We recommend either creating and using a new ECR
84+
repository or configuring pull through cache rules (https://docs.aws.amazon.com/AmazonECR/latest/userguide/pull-through-cache.html).
85+
EOT
86+
type = string
87+
}
7888

7989
variable "sync_frequency_in_minutes" {
8090
description = "The interval EventBridge is configured to trigger full synchronizations."
@@ -99,49 +109,3 @@ variable "tags" {
99109
type = map(string)
100110
default = {}
101111
}
102-
variable "region" {
103-
type = string
104-
description = "AWS region to deploy Lambda registrator."
105-
}
106-
107-
variable "private_ecr_repo_name" {
108-
description = "The name of the repository to republish the ECR image if one exists. If no name is passed, it is assumed that no repository exists and one needs to be created. Note :- If 'enable_pull_through_cache' is true this variable is ignored."
109-
type = string
110-
default = "consul-lambda-registrator"
111-
}
112-
113-
variable "enable_pull_through_cache" {
114-
description = "Flag to determine if a pull-through cache method will be used to obtain the appropriate ECR image"
115-
type = bool
116-
default = false
117-
}
118-
119-
120-
variable "consul_lambda_registrator_image" {
121-
description = "The Lambda registrator image to use. Must be provided as <registry/repository:tag>"
122-
type = string
123-
default = "public.ecr.aws/hashicorp/consul-lambda-registrator:0.1.0-beta4"
124-
125-
validation {
126-
condition = can(regex("^[a-zA-Z0-9_.-]+/[a-z0-9_.-]+/[a-z0-9_.-]+:[a-zA-Z0-9_.-]+$", var.consul_lambda_registrator_image))
127-
error_message = "Image format of 'consul_lambda_registrator_image' is invalid. It should be in the format 'registry/repository:tag'."
128-
}
129-
}
130-
131-
variable "docker_host" {
132-
description = "The docker socket for your system"
133-
type = string
134-
default = "unix:///var/run/docker.sock"
135-
}
136-
137-
variable "ecr_repository_prefix" {
138-
description = "The repository namespace to use when caching images from the source registry"
139-
type = string
140-
default = "ecr-public"
141-
}
142-
143-
variable "upstream_registry_url" {
144-
description = "The public registry url"
145-
type = string
146-
default = "public.ecr.aws"
147-
}

0 commit comments

Comments
 (0)