-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcodepipeline-artifacts.tf
117 lines (110 loc) · 3.93 KB
/
codepipeline-artifacts.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
111
112
113
114
115
116
117
### This uploads the task definition and appspec as a zip
resource "aws_s3_object" "artifacts_s3" {
bucket = var.codepipeline_source_bucket_id
key = var.codepipeline_source_object_key
source = data.archive_file.artifacts.output_path
source_hash = md5(jsonencode(data.archive_file.artifacts.source))
acl = "bucket-owner-full-control"
kms_key_id = var.codepipeline_source_bucket_kms_key_arn
}
locals {
artifact_taskdef_file_name = "taskdef.json"
artifact_appspec_file_name = "appspec.yaml"
}
data "archive_file" "artifacts" {
type = "zip"
output_path = "${path.module}/dist/${var.service_name}-artifacts.zip"
source {
filename = local.artifact_taskdef_file_name
content = <<EOF
{
"family": "${var.taskdef_family}",
"cpu": "${var.taskdef_cpu}",
"memory": "${var.taskdef_memory}",
"executionRoleArn": "${var.taskdef_execution_role_arn}",
"taskRoleArn": "${var.taskdef_task_role_arn}",
"compatibilities": [
"EC2",
"FARGATE"
],
"requiresCompatibilities": ${jsonencode(var.taskdef_requires_compatibilities)},
"networkMode": "${var.taskdef_network_mode}",
"containerDefinitions": ${var.codepipeline_container_definitions}
}
EOF
}
dynamic "source" {
for_each = var.use_custom_capacity_provider_strategy == true ? [1] : []
content {
filename = local.artifact_appspec_file_name
content = <<-EOF
version: 0.0
Resources:
- TargetService:
Type: AWS::ECS::Service
Properties:
TaskDefinition: <TASK_DEFINITION>
LoadBalancerInfo:
ContainerName: "${var.lb_container_name}"
ContainerPort: "${var.lb_container_port}"
PlatformVersion: "${var.platform_version}"
CapacityProviderStrategy:
- Base: "${lookup(var.custom_capacity_provider_strategy, "primary_capacity_provider_base")}"
CapacityProvider: "${lookup(var.custom_capacity_provider_strategy, "primary_capacity_provider")}"
Weight: "${lookup(var.custom_capacity_provider_strategy, "primary_capacity_provider_weight")}"
- CapacityProvider: "${lookup(var.custom_capacity_provider_strategy, "secondary_capacity_provider")}"
Weight: "${lookup(var.custom_capacity_provider_strategy, "secondary_capacity_provider_weight")}"
Hooks:
%{if var.appspec_hook_before_install != ""~}
- BeforeInstall: "${var.appspec_hook_before_install}"
%{endif~}
%{if var.appspec_hook_after_install != ""~}
- AfterInstall: "${var.appspec_hook_after_install}"
%{endif~}
%{if var.appspec_hook_after_allow_test_traffic != ""~}
- AfterInstall: "${var.appspec_hook_after_allow_test_traffic}"
%{endif~}
%{if var.appspec_hook_before_allow_traffic != ""~}
- AfterInstall: "${var.appspec_hook_before_allow_traffic}"
%{endif~}
%{if var.appspec_hook_after_allow_traffic != ""~}
- AfterInstall: "${var.appspec_hook_after_allow_traffic}"
%{endif~}
EOF
}
}
dynamic "source" {
for_each = var.use_custom_capacity_provider_strategy == false ? [1] : []
content {
filename = local.artifact_appspec_file_name
content = <<-EOF
version: 0.0
Resources:
- TargetService:
Type: AWS::ECS::Service
Properties:
TaskDefinition: <TASK_DEFINITION>
LoadBalancerInfo:
ContainerName: "${var.lb_container_name}"
ContainerPort: "${var.lb_container_port}"
PlatformVersion: "${var.platform_version}"
Hooks:
%{if var.appspec_hook_before_install != ""~}
- BeforeInstall: "${var.appspec_hook_before_install}"
%{endif~}
%{if var.appspec_hook_after_install != ""~}
- AfterInstall: "${var.appspec_hook_after_install}"
%{endif~}
%{if var.appspec_hook_after_allow_test_traffic != ""~}
- AfterInstall: "${var.appspec_hook_after_allow_test_traffic}"
%{endif~}
%{if var.appspec_hook_before_allow_traffic != ""~}
- AfterInstall: "${var.appspec_hook_before_allow_traffic}"
%{endif~}
%{if var.appspec_hook_after_allow_traffic != ""~}
- AfterInstall: "${var.appspec_hook_after_allow_traffic}"
%{endif~}
EOF
}
}
}