Skip to content

Commit fc481a5

Browse files
committed
update codebuild
1 parent b14d91f commit fc481a5

4 files changed

Lines changed: 36 additions & 20 deletions

File tree

terraform/codebuild/data.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
data "aws_caller_identity" "current" {}
1+
data "aws_caller_identity" "current" {
2+
}
23

terraform/codebuild/main.tf

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
# You can find more options for customizing this resource to your needs
66
# here: https://www.terraform.io/docs/providers/aws/r/codebuild_project.html
77
resource "aws_codebuild_project" "build" {
8-
name = "${var.project_name}"
8+
name = var.project_name
99
description = "CI pipeline for ${var.project_name}"
1010
build_timeout = "60" #In minutes
11-
service_role = "${aws_iam_role.codebuild.arn}"
11+
service_role = aws_iam_role.codebuild.arn
1212

1313
# Valid values for this parameter are: CODEPIPELINE, NO_ARTIFACTS or S3.
1414
# If you are building a Docker container and pushing it to some registry,
@@ -18,34 +18,45 @@ resource "aws_codebuild_project" "build" {
1818
}
1919

2020
environment {
21-
compute_type = "BUILD_GENERAL1_LARGE"
22-
image = "${var.build_image}"
23-
type = "LINUX_CONTAINER"
21+
compute_type = "BUILD_GENERAL1_LARGE"
22+
image = var.build_image
23+
type = "LINUX_CONTAINER"
24+
2425
# You need "true" here to be able to run Docker daemon inside the building container
2526
privileged_mode = "true"
2627

2728
environment_variable {
28-
"name" = "DOCKER_REPO"
29-
"value" = "${aws_ecr_repository.registry.repository_url}"
29+
name = "DOCKER_REPO"
30+
value = aws_ecr_repository.registry.repository_url
3031
}
3132
}
3233

3334
source {
3435
# Choose type "NO_SOURCE" to don't build from Github
3536
type = "GITHUB"
36-
location = "${var.github_repo}"
37-
buildspec = "${var.buildspec_file}"
37+
location = var.github_repo
38+
buildspec = var.buildspec_file
3839
}
3940

40-
tags {
41-
"App" = "${var.project_name}"
41+
tags = {
42+
"App" = var.project_name
4243
}
4344
}
4445

4546
# Unomment this section if you do want to build automatically on push
4647
resource "aws_codebuild_webhook" "webhook" {
47-
project_name = "${aws_codebuild_project.build.name}"
48-
branch_filter = "^master$"
48+
project_name = aws_codebuild_project.build.name
49+
filter_group {
50+
filter {
51+
type = "EVENT"
52+
pattern = "PUSH"
53+
}
54+
55+
filter {
56+
type = "HEAD_REF"
57+
pattern = "(^refs/heads/master$|^refs/tags/.*-(prod|test))"
58+
}
59+
}
4960
}
5061

5162
#---
@@ -69,10 +80,11 @@ resource "aws_iam_role" "codebuild" {
6980
]
7081
}
7182
EOF
83+
7284
}
7385

7486
resource "aws_iam_role_policy" "codebuild" {
75-
role = "${aws_iam_role.codebuild.name}"
87+
role = aws_iam_role.codebuild.name
7688

7789
policy = <<POLICY
7890
{
@@ -107,18 +119,19 @@ resource "aws_iam_role_policy" "codebuild" {
107119
]
108120
}
109121
POLICY
122+
110123
}
111124

112125
#---
113126
# ECR
114127
#---
115128

116129
resource "aws_ecr_repository" "registry" {
117-
name = "${var.project_name}"
130+
name = var.project_name
118131
}
119132

120133
resource "aws_ecr_repository_policy" "registrypolicy" {
121-
repository = "${aws_ecr_repository.registry.name}"
134+
repository = aws_ecr_repository.registry.name
122135

123136
policy = <<EOF
124137
{
@@ -149,5 +162,6 @@ resource "aws_ecr_repository_policy" "registrypolicy" {
149162
]
150163
}
151164
EOF
165+
152166
}
153167

terraform/codebuild/outputs.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
output "iam_role_arn" {
2-
value = "${aws_iam_role.codebuild.arn}"
2+
value = aws_iam_role.codebuild.arn
33
description = "ARN of the codebuild user. Needed by cluster admins to authorize deploying to Kubernetes"
44
}
55

66
output "ecr_url" {
7-
value = "${aws_ecr_repository.registry.repository_url}"
7+
value = aws_ecr_repository.registry.repository_url
88
description = "URL of the new container registry which will host your builds"
99
}
1010

terraform/codebuild/provider.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#---
44

55
provider "aws" {
6-
region = "us-west-2"
6+
region = "us-west-2"
77
}
88

99
terraform {
@@ -15,3 +15,4 @@ terraform {
1515
region = "us-west-2"
1616
}
1717
}
18+

0 commit comments

Comments
 (0)