forked from genstackio/terraform-aws-codepipeline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
66 lines (57 loc) · 1.93 KB
/
main.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
data "aws_iam_role" "role" {
name = var.role_pipeline_name
}
module "artifacts-policy" {
count = var.create_s3_artifact ? 1 : 0
source = "./modules/artifacts-policy"
role_name = data.aws_iam_role.role.name
pipeline_bucket = var.create_s3_artifact ? aws_s3_bucket.artifacts[*].arn!=null : data.aws_s3_bucket.datartifact.arn
policy_statements = local.statements
}
resource "aws_s3_bucket" "artifacts" {
count = var.create_s3_artifact ? 1 : 0
bucket = "${var.name}-${var.env}"
}
data "aws_s3_bucket" "datartifact" {
bucket = var.s3_artifact_Id
}
resource "aws_codepipeline" "pipeline" {
name = "${var.name}-${var.env}"
role_arn = data.aws_iam_role.role.arn
artifact_store {
location = var.create_s3_artifact ? aws_s3_bucket.artifacts[*].id!=null : data.aws_s3_bucket.datartifact.id
type = "S3"
}
dynamic "stage" {
for_each = var.stages
content {
name = stage.value.name
action {
name = stage.value.name
category = stage.value.type
configuration = stage.value.config
owner = "AWS"
provider = stage.value.provider
run_order = stage.key + 1
version = "1"
input_artifacts = stage.value.inputs
output_artifacts = stage.value.outputs
}
}
}
}
resource "aws_codestarnotifications_notification_rule" "aws_codestarnotifications_notification_rule_codepipeline" {
count = var.slack_notifications_enabled ? 1 : 0
detail_type = "BASIC"
event_type_ids = [
"codepipeline-pipeline-pipeline-execution-failed",
"codepipeline-pipeline-pipeline-execution-started",
"codepipeline-pipeline-pipeline-execution-succeeded"
]
name = var.slack-notification-rule-codepipeline-name
resource = aws_codepipeline.pipeline.arn
target {
address = var.alerts_ci_slack_notifications_arn
type = var.alerts_ci_slack_notifications_type
}
}