-
Notifications
You must be signed in to change notification settings - Fork 0
/
codebuild-new.tf
46 lines (37 loc) · 1.33 KB
/
codebuild-new.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
# To build the container, we need the following components:
# 1. An ECR repository to store the built image in.
# 2. A CodeBuild job to build and push the container. The build steps are defined in the buildspec.yml file.
# 3. An IAM policy that the build runs as with access to create images and push to ECR.
# 4. A webhook to receive notifications when commits are pushed to GitHub.
resource "aws_ecr_repository" "webinar_repo_new" {
provider = aws.new
name = "${var.container_name}"
}
data "template_file" "buildspec_new" {
template = "${file("templates/buildspec.yml")}"
vars = {
container_name = "${var.container_name}"
repository_url = "${aws_ecr_repository.webinar_repo_new.repository_url}"
region = "${var.aws_region_new}"
}
}
resource "aws_codebuild_project" "build_image_new" {
provider = aws.new
name = "${var.container_name}-docker-build"
build_timeout = "60"
service_role = "${aws_iam_role.codebuild_role.arn}"
artifacts {
type = "CODEPIPELINE"
}
environment {
compute_type = "BUILD_GENERAL1_SMALL"
image = "aws/codebuild/standard:1.0"
type = "LINUX_CONTAINER"
# This is needed to allow building container images.
privileged_mode = true
}
source {
type = "CODEPIPELINE"
buildspec = "${data.template_file.buildspec_new.rendered}"
}
}