· 6 years ago · Nov 15, 2018, 09:58 AM
1resource "aws_codepipeline" "codepipeline" {
2 name = "demo"
3 role_arn = "${aws_iam_role.iam_codepipeline_role.arn}"
4
5 artifact_store {
6 location = "${aws_s3_bucket.default.bucket}"
7 type = "S3"
8 }
9
10 # Configure CodePipeline poll code from Github if there is any commits.
11 stage {
12 name = "Source"
13
14 action {
15 name = "Source"
16 category = "Source"
17 owner = "ThirdParty"
18 provider = "GitHub"
19 version = "1"
20 output_artifacts = ["code"]
21
22 configuration {
23 OAuthToken = "${var.github_oauth_token}"
24 Owner = "${var.repo_owner}"
25 Repo = "${var.repo_name}"
26 Branch = "${var.branch}"
27 PollForSourceChanges = "${var.poll_source_changes}"
28 }
29 }
30 }
31
32 # We use CodeBuild to Build Docker Image.
33 stage {
34 name = "BuildDocker"
35
36 action {
37 name = "Build"
38 category = "Build"
39 owner = "AWS"
40 provider = "CodeBuild"
41 input_artifacts = ["code"]
42 version = "1"
43 configuration {
44 ProjectName = "${aws_codebuild_project.codebuild_docker_image.name}"
45 }
46 }
47 }
48
49 # We use CodeBuild to deploy application.
50 stage {
51 name = "Deploy"
52
53 action {
54 name = "Deploy"
55 category = "Build"
56 owner = "AWS"
57 provider = "CodeBuild"
58 input_artifacts = ["code"]
59 version = "1"
60 configuration {
61 ProjectName = "${aws_codebuild_project.codebuild_deploy_on_ecs.name}"
62 }
63 }
64 }
65}