/
main.tf
65 lines (55 loc) · 1.95 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
#This solution, non-production-ready template describes AWS Codepipeline based CICD Pipeline for terraform code deployment.
#© 2023 Amazon Web Services, Inc. or its affiliates. All Rights Reserved.
#This AWS Content is provided subject to the terms of the AWS Customer Agreement available at
#http://aws.amazon.com/agreement or other written agreement between Customer and either
#Amazon Web Services, Inc. or Amazon Web Services EMEA SARL or both.
resource "aws_codepipeline" "terraform_pipeline" {
name = "${var.project_name}-pipeline"
role_arn = var.codepipeline_role_arn
tags = var.tags
artifact_store {
location = var.s3_bucket_name
type = "S3"
encryption_key {
id = var.kms_key_arn
type = "KMS"
}
}
stage {
name = "Source"
action {
name = "Download-Source"
category = "Source"
owner = "AWS"
version = "1"
provider = "CodeCommit"
namespace = "SourceVariables"
output_artifacts = ["SourceOutput"]
run_order = 1
configuration = {
RepositoryName = var.source_repo_name
BranchName = var.source_repo_branch
PollForSourceChanges = "true"
}
}
}
dynamic "stage" {
for_each = var.stages
content {
name = "Stage-${stage.value["name"]}"
action {
category = stage.value["category"]
name = "Action-${stage.value["name"]}"
owner = stage.value["owner"]
provider = stage.value["provider"]
input_artifacts = [stage.value["input_artifacts"]]
output_artifacts = [stage.value["output_artifacts"]]
version = "1"
run_order = index(var.stages, stage.value) + 2
configuration = {
ProjectName = stage.value["provider"] == "CodeBuild" ? "${var.project_name}-${stage.value["name"]}" : null
}
}
}
}
}