-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
83 lines (66 loc) · 2.16 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
locals{
build_name = "codebuild-${var.codebuild_name}-${var.env_name}"
}
resource "aws_codebuild_project" "codebuild" {
name = "${local.build_name}"
description = "Build spec for ${local.build_name}"
build_timeout = "120"
service_role = aws_iam_role.codebuild_role.arn
artifacts {
packaging = "NONE"
override_artifact_name = false
type = "CODEPIPELINE"
}
environment {
compute_type = "BUILD_GENERAL1_SMALL"
image = "aws/codebuild/amazonlinux2-x86_64-standard:3.0"
type = "LINUX_CONTAINER"
image_pull_credentials_type = "CODEBUILD"
dynamic "environment_variable" {
for_each = var.environment_variables
content {
name = environment_variable.key
value = environment_variable.value
}
}
dynamic "environment_variable" {
for_each = var.environment_variables_parameter_store
content {
name = environment_variable.key
value = environment_variable.value
type = "PARAMETER_STORE"
}
}
privileged_mode = var.privileged_mode
}
logs_config {
cloudwatch_logs {
group_name = "/${local.build_name}/log-group"
stream_name = "/${local.build_name}/stream"
}
}
source {
type = "CODEPIPELINE"
#location = var.source_repository_url
# git_clone_depth = 1
buildspec = var.buildspec_file
# git_submodules_config {
# fetch_submodules = false
# }
}
source_version = var.source_branch
tags = tomap({
Name="codebuild-${local.build_name}",
environment=var.env_name,
created_by="terraform"
})
}
resource "aws_iam_role" "codebuild_role" {
name = "role-${local.build_name}"
assume_role_policy = data.aws_iam_policy_document.codebuild_assume_role_policy.json
}
resource "aws_iam_role_policy" "cloudWatch_policy" {
name = "policy-${local.build_name}"
role = aws_iam_role.codebuild_role.id
policy = data.aws_iam_policy_document.codebuild_role_policy.json
}