forked from moritzzimmer/terraform-aws-lambda
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.tf
More file actions
67 lines (55 loc) · 2.2 KB
/
Copy pathmain.tf
File metadata and controls
67 lines (55 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
locals {
environment = "production"
function_name = "ecr-deployment"
}
module "lambda" {
source = "../../../"
depends_on = [null_resource.initial_image]
description = "Example usage for a containerized AWS Lambda deployed using CodePipeline and CodeDeploy."
function_name = local.function_name
ignore_external_function_updates = true
image_uri = "${aws_ecr_repository.this.repository_url}:${local.environment}"
package_type = "Image"
publish = true
}
# ---------------------------------------------------------------------------------------------------------------------
# Deployment resources
# ---------------------------------------------------------------------------------------------------------------------
resource "aws_lambda_alias" "this" {
function_name = module.lambda.function_name
function_version = module.lambda.version
name = local.environment
lifecycle {
ignore_changes = [function_version]
}
}
module "deployment" {
source = "../../../modules/deployment"
alias_name = aws_lambda_alias.this.name
ecr_image_tag = local.environment
ecr_repository_name = aws_ecr_repository.this.name
function_name = local.function_name
}
#trivy:ignore:AVD-AWS-0031
resource "aws_ecr_repository" "this" {
force_delete = true
name = local.function_name
image_scanning_configuration {
scan_on_push = true
}
}
// this resource is only used for the initial `terraform apply` - all further
// deployments are running on CodePipeline
resource "null_resource" "initial_image" {
provisioner "local-exec" {
command = "aws ecr get-login-password --region ${var.region} | docker login --username AWS --password-stdin ${aws_ecr_repository.this.repository_url}"
}
provisioner "local-exec" {
command = "docker build --tag ${aws_ecr_repository.this.repository_url}:${local.environment} ."
working_dir = "${path.module}/../../fixtures/context"
}
provisioner "local-exec" {
command = "docker push --all-tags ${aws_ecr_repository.this.repository_url}"
working_dir = "${path.module}/../../fixtures/context"
}
}