-
Notifications
You must be signed in to change notification settings - Fork 10
/
main.tf
62 lines (56 loc) · 2.38 KB
/
main.tf
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
locals {
registry_domain = length(var.registry_domain) > 0 ? var.registry_domain : (
"${data.aws_caller_identity.current.account_id}.dkr.ecr.${data.aws_region.current.name}.amazonaws.com"
)
iam_role_arn = module.lacework_ecr_iam_role.created ? module.lacework_ecr_iam_role.arn : var.iam_role_arn
iam_role_name = module.lacework_ecr_iam_role.created ? module.lacework_ecr_iam_role.name : var.iam_role_name
iam_role_external_id = module.lacework_ecr_iam_role.created ? module.lacework_ecr_iam_role.external_id : var.iam_role_external_id
version_file = "${abspath(path.module)}/VERSION"
module_name = "terraform-aws-ecr"
module_version = fileexists(local.version_file) ? file(local.version_file) : ""
}
data "aws_region" "current" {}
data "aws_caller_identity" "current" {}
module "lacework_ecr_iam_role" {
source = "lacework/iam-role/aws"
version = "~> 0.4"
create = var.use_existing_iam_role ? false : true
iam_role_name = var.iam_role_name
lacework_aws_account_id = var.lacework_aws_account_id
tags = var.tags
}
resource "aws_iam_role_policy_attachment" "ecr_read_only_policy_attachment" {
role = local.iam_role_name
policy_arn = "arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly"
depends_on = [module.lacework_ecr_iam_role]
}
# wait for X seconds for things to settle down in the AWS side
# before trying to create the Lacework external integration
resource "time_sleep" "wait_time" {
create_duration = var.wait_time
depends_on = [aws_iam_role_policy_attachment.ecr_read_only_policy_attachment]
}
resource "lacework_integration_ecr" "iam_role" {
name = var.lacework_integration_name
registry_domain = local.registry_domain
non_os_package_support = var.non_os_package_support
credentials {
role_arn = local.iam_role_arn
external_id = local.iam_role_external_id
}
limit_by_tags = var.limit_by_tags
dynamic "limit_by_label" {
for_each = var.limit_by_labels
content {
key = limit_by_label.value.key
value = limit_by_label.value.value
}
}
limit_by_repositories = var.limit_by_repositories
limit_num_imgs = var.limit_num_imgs
depends_on = [time_sleep.wait_time]
}
data "lacework_metric_module" "lwmetrics" {
name = local.module_name
version = local.module_version
}