Skip to content

Commit

Permalink
added fixes and fixed acceptance test
Browse files Browse the repository at this point in the history
  • Loading branch information
aahel committed Sep 15, 2023
1 parent e99d763 commit c2308c6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
7 changes: 3 additions & 4 deletions modules/lambda-registrator/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ locals {
lambda_events_key = "${var.name}-lambda_events"
image_parts = split(":", var.consul_lambda_registrator_image)
image_tag = local.image_parts[1]
ecr_repo_name = var.private_ecr_repo_name == "" ? "consul-lambda-registrator-${random_id.repo_id.hex}" : var.private_ecr_repo_name
# generated_ecr_image_uri is used when we want to automatically push the public image to a private ecr repo using docker.
generated_ecr_image_uri = "${data.aws_caller_identity.current_identity.account_id}.dkr.ecr.${data.aws_region.current_region.name}.amazonaws.com/${var.private_ecr_repo_name}:${local.image_tag}"
generated_ecr_image_uri = "${data.aws_caller_identity.current_identity.account_id}.dkr.ecr.${data.aws_region.current_region.name}.amazonaws.com/${local.ecr_repo_name}:${local.image_tag}"
}

# Equivalent of aws ecr get-login
Expand Down Expand Up @@ -153,14 +154,12 @@ resource "aws_iam_role_policy_attachment" "lambda_logs" {
role = aws_iam_role.registration.name
policy_arn = aws_iam_policy.policy.arn
}

resource "random_id" "repo_id" {
count = var.ecr_image_uri != "" ? 0 : 1
byte_length = 8
}
resource "aws_ecr_repository" "lambda-registrator" {
count = var.ecr_image_uri != "" ? 0 : 1
name = var.private_ecr_repo_name == "" ? "consul-lambda-registrator-${random_id.repo_id[count.index].hex}" : var.private_ecr_repo_name
name = local.ecr_repo_name
force_delete = true
}

Expand Down
13 changes: 10 additions & 3 deletions test/acceptance/tests/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ type SetupConfig struct {

func TestBasic(t *testing.T) {
cases := map[string]struct {
secure bool
enterprise bool
secure bool
enterprise bool
autoPublishRegistrator bool
}{
"secure": {
secure: true,
Expand All @@ -44,6 +45,10 @@ func TestBasic(t *testing.T) {
secure: true,
enterprise: true,
},
"secure auto publish": {
secure: true,
autoPublishRegistrator: true,
},
}

for name, c := range cases {
Expand All @@ -55,7 +60,9 @@ func TestBasic(t *testing.T) {
partition := ""
queryString := ""
tfVars["consul_image"] = "public.ecr.aws/hashicorp/consul:1.15.1"

if c.autoPublishRegistrator {
tfVars["ecr_image_uri"] = ""
}
if c.enterprise {
tfVars["consul_license"] = os.Getenv("CONSUL_LICENSE")
require.NotEmpty(t, tfVars["consul_license"], "CONSUL_LICENSE environment variable is required for enterprise tests")
Expand Down

0 comments on commit c2308c6

Please sign in to comment.