-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.tf
70 lines (61 loc) · 2.53 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
locals {
source_repository_url = "https://bitbucket.org/${var.source_repository}"
//TODO: handle image tag - replace "latest" - should be a build parameter and latest by default
image_uri = "${var.ecr_repo_url}:${var.env_name}"
}
module "code-pipeline" {
source = "./modules/codepipeline"
env_name = var.env_name
source_repository = var.source_repository
s3_bucket = aws_s3_bucket.codepipeline_bucket.bucket
code_build_projects = [module.code-build.attributes.name]
code_deploy_applications = [module.code-deploy.attributes.name]
trigger_branch = var.trigger_branch
trigger_events = ["push", "merge"]
depends_on = [
aws_s3_bucket.codepipeline_bucket,
]
}
module "code-build" {
source = "./modules/codebuild"
env_name = var.env_name
codebuild_name = "build"
s3_bucket = aws_s3_bucket.codepipeline_bucket.bucket
privileged_mode = true
environment_variables_parameter_store = var.environment_variables_parameter_store
environment_variables = merge(var.environment_variables, { APPSPEC = templatefile("${path.module}/templates/appspec.json.tpl", { yoyo = "yo" }) }) //TODO: try to replace with file
buildspec_file = templatefile("buildspec.yml.tpl",
{ IMAGE_URI = local.image_uri,
DOCKERFILE_PATH = var.dockerfile_path,
ECR_REPO_URL = var.ecr_repo_url,
ECR_REPO_NAME = var.ecr_repo_name,
TASK_DEF_NAME = var.task_def_name,
ADO_USER = data.aws_ssm_parameter.ado_user.value,
ADO_PASSWORD = data.aws_ssm_parameter.ado_password.value })
depends_on = [
aws_s3_bucket.codepipeline_bucket,
]
}
module "code-deploy" {
source = "./modules/codedeploy"
env_name = var.env_name
s3_bucket = aws_s3_bucket.codepipeline_bucket.bucket
ecs_service_name = var.ecs_service_name
ecs_cluster_name = var.ecs_cluster_name
alb_listener_arn = var.alb_listener_arn
alb_tg_blue_name = var.alb_tg_blue_name
alb_tg_green_name = var.alb_tg_green_name
ecs_iam_roles_arns = var.ecs_iam_roles_arns
depends_on = [
aws_s3_bucket.codepipeline_bucket
]
}
resource "aws_s3_bucket" "codepipeline_bucket" {
bucket = "s3-codepipeline-${var.app_name}-${var.env_name}"
acl = "private"
force_destroy = true
tags = tomap({
UseWithCodeDeploy = true
created_by = "terraform"
})
}