|
1 | 1 | # Copyright (c) HashiCorp, Inc.
|
2 | 2 | # SPDX-License-Identifier: MPL-2.0
|
3 | 3 |
|
4 |
| -terraform { |
5 |
| - required_providers { |
6 |
| - docker = { |
7 |
| - source = "kreuzwerker/docker" |
8 |
| - version = "3.0.2" |
9 |
| - } |
10 |
| - } |
11 |
| -} |
12 | 4 | locals {
|
13 | 5 | on_vpc = length(var.subnet_ids) > 0 && length(var.security_group_ids) > 0
|
14 | 6 | vpc_config = local.on_vpc ? [{
|
15 | 7 | subnet_ids = var.subnet_ids
|
16 | 8 | security_group_ids = var.security_group_ids
|
17 | 9 | }] : []
|
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" |
39 | 12 | }
|
40 | 13 |
|
41 |
| -data "aws_caller_identity" "current" {} |
42 |
| - |
43 | 14 | resource "aws_iam_role" "registration" {
|
44 | 15 | name = var.name
|
45 | 16 |
|
@@ -156,51 +127,8 @@ resource "aws_iam_role_policy_attachment" "lambda_logs" {
|
156 | 127 | policy_arn = aws_iam_policy.policy.arn
|
157 | 128 | }
|
158 | 129 |
|
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 |
| -} |
202 | 130 | 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 |
204 | 132 | package_type = "Image"
|
205 | 133 | function_name = var.name
|
206 | 134 | role = aws_iam_role.registration.arn
|
@@ -240,11 +168,6 @@ resource "aws_lambda_function" "registration" {
|
240 | 168 | security_group_ids = vpc_config.value["security_group_ids"]
|
241 | 169 | }
|
242 | 170 | }
|
243 |
| - depends_on = [ |
244 |
| - null_resource.push_image, |
245 |
| - time_sleep.wait_30_seconds, |
246 |
| - ] |
247 |
| - |
248 | 171 | }
|
249 | 172 |
|
250 | 173 | module "eventbridge" {
|
|
0 commit comments