-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpipeline.tf
104 lines (97 loc) · 2.66 KB
/
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
resource "aws_codebuild_project" "tf-plan" {
name = "tf-cicd-plan"
description = "TF plan stage"
service_role = aws_iam_role.tf-codebuild-role.arn
artifacts {
type = "CODEPIPELINE"
}
environment {
compute_type = "BUILD_GENERAL1_SMALL"
image = "hashicorp/terraform:${var.tf-version}"
type = "LINUX_CONTAINER"
image_pull_credentials_type = "SERVICE_ROLE"
registry_credential {
credential = var.dockerhub_creds
credential_provider = "SECRETS_MANAGER"
}
}
source {
type = "CODEPIPELINE"
buildspec = file("buildspec/plan-buildspec.yml")
}
}
resource "aws_codebuild_project" "tf-apply" {
name = "tf-cicd-apply"
description = "TF apply stage"
service_role = aws_iam_role.tf-codebuild-role.arn
artifacts {
type = "CODEPIPELINE"
}
environment {
compute_type = "BUILD_GENERAL1_SMALL"
image = "hashicorp/terraform:${var.tf-version}"
type = "LINUX_CONTAINER"
image_pull_credentials_type = "SERVICE_ROLE"
registry_credential {
credential = var.dockerhub_creds
credential_provider = "SECRETS_MANAGER"
}
}
source {
type = "CODEPIPELINE"
buildspec = file("buildspec/apply-buildspec.yml")
}
}
resource "aws_codepipeline" "tf-pipeline" {
name = "tf-pipeline"
role_arn = aws_iam_role.tf-codebuild-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"
output_artifacts = ["tf-code"]
version = "1"
configuration = {
FullRepositoryId = "isewise/tf-aws-pipeline"
BranchName = "master"
ConnectionArn = var.codestar_creds
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"
}
}
}
}