-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
226 lines (213 loc) · 7.82 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
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
module "iam" {
source = "github.com/makeen-project/terraform-templates-infra/modules/iam"
iam_role = [{
name = "${var.project_name}-${var.environment}-${var.codebuild_iam_role_name}"
assume_role_policy = "${file("roles_and_policies/codebuild_project_assume_role.json")}"
},
{
name = "${var.project_name}-${var.environment}-${var.codepipeline_iam_role_name}"
assume_role_policy = "${file("roles_and_policies/codepipeline_assume_role.json")}"
}]
iam_role_policy = [{
name = "${var.project_name}-${var.environment}-${var.codebuild_iam_role_name}"
role_id = "${module.iam.iam_role_id["${var.project_name}-${var.environment}-${var.codebuild_iam_role_name}"]}"
policy = "${file("roles_and_policies/codebuild_project_policy.json")}"
},
{
name = "${var.project_name}-${var.environment}-${var.codepipeline_iam_role_name}"
role_id = "${module.iam.iam_role_id["${var.project_name}-${var.environment}-${var.codepipeline_iam_role_name}"]}"
policy = "${file("roles_and_policies/codepipeline_policy.json")}"
}]
environment = var.environment
project_name = var.project_name
}
module "codepipeline_s3" {
source = "github.com/makeen-project/terraform-templates-infra/modules/s3"
s3_bucket_name = ["${var.codepipeline_bucket_name}"]
environment = var.environment
project_name = var.project_name
}
module "tapin_admin_ui_config_s3" {
source = "github.com/makeen-project/terraform-templates-infra/modules/s3"
s3_bucket_name = ["${var.tapin_admin_ui_config_bucket_name}"]
environment = var.environment
project_name = var.project_name
}
data "template_file" "s3_bucket_policy" {
template = "${file("roles_and_policies/s3_bucket_policy.json")}"
vars = {
bucket_name = "${var.project_name}-${var.environment}-${var.tapin_admin_web_bucket_name}"
aws_cloudfront_origin_access_identity_iam_arn = "${module.cdn.cloudfront_origin_access_identity_iam_arn}"
environment = var.environment
project_name = "${var.project_name}"
}
}
module "tapin_admin_web_s3" {
source = "github.com/makeen-project/terraform-templates-infra/modules/s3"
s3_bucket_name = ["${var.tapin_admin_web_bucket_name}"]
s3_policy_document = "${data.template_file.s3_bucket_policy.rendered}"
s3_static_website_vars = {
index_document = "index.html"
error_document = null
redirect_all_requests_to = null
routing_rules = null
}
s3_versioning = {
enabled = true
mfa_delete = null
}
environment = var.environment
project_name = var.project_name
}
data "template_file" "buildspec" {
template = "${file("buildspec.yaml")}"
vars = {
bucket_name = "${module.tapin_admin_web_s3.bucket_id["${var.tapin_admin_web_bucket_name}"]}"
distribuition_id = "${module.cdn.cloudfront_id}"
environment = var.environment
config_bucket = "${module.tapin_admin_ui_config_s3.bucket_id["${var.tapin_admin_ui_config_bucket_name}"]}"
}
}
module "cicd"{
source = "github.com/makeen-project/terraform-templates-infra/modules/cicd"
codebuild_project = ["${var.codebuild_project_name}"]
environment = var.environment
project_name = var.project_name
service_role = module.iam.iam_role_arn["${var.project_name}-${var.environment}-${var.codebuild_iam_role_name}"]
artifacts = [{
type = "CODEPIPELINE"
artifact_identifier = null
encryption_disabled = null
override_artifact_name = null
location = null
name = null
namespace_type = null
packaging = null
path = null
}]
codebuild_environment = [{
compute_type = "BUILD_GENERAL1_MEDIUM"
image = "aws/codebuild/amazonlinux2-x86_64-standard:3.0"
type = "LINUX_CONTAINER"
image_pull_credentials_type = "CODEBUILD"
environment_variable = []
privileged_mode = true
certificate = null
}]
codebuild_source = [{
type = "CODEPIPELINE"
auth_type = "OAUTH"
resource = null
buildspec = "${data.template_file.buildspec.rendered}"
git_clone_depth = null
fetch_submodules = false
insecure_ssl = null
location = null
report_build_status = null
}]
codepipeline_project = ["${var.codepipeline_project_name}"]
role_arn = module.iam.iam_role_arn["${var.project_name}-${var.environment}-${var.codepipeline_iam_role_name}"]
artifact_store = [{
location = "${var.project_name}-${var.environment}-${var.codepipeline_bucket_name}"
type = "S3"
encryption_key = []
region = null
}]
stage = [{
name = "Source"
action = [{
category = "Source"
owner = "ThirdParty"
name= "Source"
provider = "GitHub"
version = "1"
configuration = {
OAuthToken = "${var.repo_token}"
Owner = "${var.repo_owner}"
Repo = "${var.repo_name}"
Branch = "${var.repo_branch}"
}
input_artifacts = []
output_artifacts = ["source"]
role_arn= null
run_order =null
region = null
namespace = null
}]
},
{
name = "Build"
action = [{
category = "Build"
owner = "AWS"
name= "Build"
provider = "CodeBuild"
version = "1"
configuration = {
ProjectName = "${var.project_name}-${var.environment}-${var.codebuild_project_name}"
}
input_artifacts = ["source"]
output_artifacts = []
role_arn= null
run_order =null
region = null
namespace = null
}]
}]
}
module "cdn" {
source = "github.com/makeen-project/terraform-templates-infra/modules/cdn"
distribution_state = true
default_root_object = "index.html"
alternate_domain_names = ["${var.domain}"]
cloudfront_default_cache_behavior = [{
allowed_http_methods = ["GET", "HEAD"]
cached_http_methods = ["GET", "HEAD"]
automatically_compress_objects = true
default_ttl = 3600
max_ttl = 3600
min_ttl = 0
smooth_streaming = null
trusted_signers = []
target_origin_id = "${module.tapin_admin_web_s3.bucket_id["${var.tapin_admin_web_bucket_name}"]}"
viewer_protocol_policy = "redirect-to-https"
forwarded_values = [{
forward_cookies = "none"
whitelisted_cookies = []
forward_query_string = false
headers = []
}]
lambda_function_association = []
}]
cloudfront_custom_error_response = [{
error_code = 403
response_code = 200
error_caching_min_ttl = 10
response_page_path = "/"
},
{
error_code = 404
response_code = 200
error_caching_min_ttl = 10
response_page_path = "/"
}]
cloudfront_origin = [{
custom_origin_config = []
domain_name = "${module.tapin_admin_web_s3.bucket_domain_name["${var.tapin_admin_web_bucket_name}"]}"
origin_id = "${module.tapin_admin_web_s3.bucket_id["${var.tapin_admin_web_bucket_name}"]}"
origin_path = null
}]
restrictions = [{
locations = []
restriction_type = "none"
}]
viewer_certificate = [{
acm_certificate_arn = "${var.acm_arn}"
cloudfront_default_certificate = false
minimum_protocol_version = null
iam_certificate_id = null
ssl_support_method = "sni-only"
}]
environment = var.environment
project_name = var.project_name
}