-
Notifications
You must be signed in to change notification settings - Fork 189
/
cicd-pipeline.tf
110 lines (97 loc) · 2.77 KB
/
cicd-pipeline.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
resource "aws_codebuild_project" "tf-plan" {
name = "tf-cicd-plan2"
description = "Plan stage for terraform"
service_role = aws_iam_role.tf-codebuild-role.arn
artifacts {
type = "CODEPIPELINE"
}
environment {
compute_type = "BUILD_GENERAL1_SMALL"
image = "hashicorp/terraform:0.14.3"
type = "LINUX_CONTAINER"
image_pull_credentials_type = "SERVICE_ROLE"
registry_credential{
credential = var.dockerhub_credentials
credential_provider = "SECRETS_MANAGER"
}
}
source {
type = "CODEPIPELINE"
buildspec = file("buildspec/plan-buildspec.yml")
}
}
resource "aws_codebuild_project" "tf-apply" {
name = "tf-cicd-apply"
description = "Apply stage for terraform"
service_role = aws_iam_role.tf-codebuild-role.arn
artifacts {
type = "CODEPIPELINE"
}
environment {
compute_type = "BUILD_GENERAL1_SMALL"
image = "hashicorp/terraform:0.14.3"
type = "LINUX_CONTAINER"
image_pull_credentials_type = "SERVICE_ROLE"
registry_credential{
credential = var.dockerhub_credentials
credential_provider = "SECRETS_MANAGER"
}
}
source {
type = "CODEPIPELINE"
buildspec = file("buildspec/apply-buildspec.yml")
}
}
resource "aws_codepipeline" "cicd_pipeline" {
name = "tf-cicd"
role_arn = aws_iam_role.tf-codepipeline-role.arn
artifact_store {
type="S3"
location = aws_s3_bucket.codepipeline_artifacts.id
}
stage {
name = "Source"
action{
name = "Source"
category = "Source"
owner = "AWS"
provider = "CodeStarSourceConnection"
version = "1"
output_artifacts = ["tf-code"]
configuration = {
FullRepositoryId = "davoclock/aws-cicd-pipeline"
BranchName = "master"
ConnectionArn = var.codestar_connector_credentials
OutputArtifactFormat = "CODE_ZIP"
}
}
}
stage {
name ="Plan"
action{
name = "Build"
category = "Build"
provider = "CodeBuild"
version = "1"
owner = "AWS"
input_artifacts = ["tf-code"]
configuration = {
ProjectName = "tf-cicd-plan"
}
}
}
stage {
name ="Deploy"
action{
name = "Deploy"
category = "Build"
provider = "CodeBuild"
version = "1"
owner = "AWS"
input_artifacts = ["tf-code"]
configuration = {
ProjectName = "tf-cicd-apply"
}
}
}
}