|
| 1 | +resource "aws_cloudwatch_log_group" "ecslogs" { |
| 2 | + name_prefix = "ecs-" |
| 3 | + retention_in_days = 7 |
| 4 | +} |
| 5 | + |
| 6 | +# Secrets access stuff |
| 7 | +################################################################################ |
| 8 | +data "aws_iam_role" "ecs_task_execution_role" { |
| 9 | + name = "ecsTaskExecutionRole" |
| 10 | +} |
| 11 | + |
| 12 | +# attach aws secrets manager policy to ecs task execution role |
| 13 | +resource "aws_iam_role_policy_attachment" "ecs_task_execution_role_attach" { |
| 14 | + role = data.aws_iam_role.ecs_task_execution_role.name |
| 15 | + policy_arn = "arn:aws:iam::aws:policy/SecretsManagerReadWrite" |
| 16 | +} |
| 17 | + |
| 18 | +# The Apps |
| 19 | +################################################################################ |
| 20 | + |
| 21 | +# Backend Prod |
| 22 | +module "python_backend_prod" { |
| 23 | + source = "./python_backend" |
| 24 | + |
| 25 | + env = "prod" |
| 26 | + vpc_id = data.aws_vpc.use2.id |
| 27 | + logs_group = aws_cloudwatch_log_group.ecslogs.name |
| 28 | + ecs_cluster_id = module.ecs.cluster_id |
| 29 | + task_execution_role = data.aws_iam_role.ecs_task_execution_role.arn |
| 30 | + image_tag = "master" |
| 31 | +} |
| 32 | + |
| 33 | +resource "aws_lb_listener_rule" "python_backend_prod" { |
| 34 | + listener_arn = aws_lb_listener.default_https.arn |
| 35 | + |
| 36 | + action { |
| 37 | + type = "forward" |
| 38 | + target_group_arn = module.python_backend_prod.lb_tg_arn |
| 39 | + } |
| 40 | + |
| 41 | + condition { |
| 42 | + host_header { |
| 43 | + values = ["backend.operationcode.org", "api.operationcode.org"] |
| 44 | + } |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +# Backend Staging |
| 49 | +module "python_backend_staging" { |
| 50 | + source = "./python_backend" |
| 51 | + |
| 52 | + env = "staging" |
| 53 | + vpc_id = data.aws_vpc.use2.id |
| 54 | + logs_group = aws_cloudwatch_log_group.ecslogs.name |
| 55 | + ecs_cluster_id = module.ecs.cluster_id |
| 56 | + task_execution_role = data.aws_iam_role.ecs_task_execution_role.arn |
| 57 | + image_tag = "staging" |
| 58 | +} |
| 59 | + |
| 60 | +resource "aws_lb_listener_rule" "python_backend_staging" { |
| 61 | + listener_arn = aws_lb_listener.default_https.arn |
| 62 | + |
| 63 | + action { |
| 64 | + type = "forward" |
| 65 | + target_group_arn = module.python_backend_staging.lb_tg_arn |
| 66 | + } |
| 67 | + |
| 68 | + condition { |
| 69 | + host_header { |
| 70 | + values = ["backend-staging.operationcode.org", "api.staging.operationcode.org"] |
| 71 | + } |
| 72 | + } |
| 73 | +} |
| 74 | + |
| 75 | +# Redirector for shut down sites |
| 76 | +resource "aws_lb_listener_rule" "shutdown_sites_redirector" { |
| 77 | + listener_arn = aws_lb_listener.default_https.arn |
| 78 | + |
| 79 | + action { |
| 80 | + type = "redirect" |
| 81 | + |
| 82 | + redirect { |
| 83 | + host = "www.operationcode.org" |
| 84 | + port = "443" |
| 85 | + protocol = "HTTPS" |
| 86 | + status_code = "HTTP_301" |
| 87 | + } |
| 88 | + } |
| 89 | + |
| 90 | + condition { |
| 91 | + host_header { |
| 92 | + values = [ |
| 93 | + "resources.operationcode.org", |
| 94 | + "resources.staging.operationcode.org", |
| 95 | + "resources-staging.operationcode.org", |
| 96 | + "pybot.staging.operationcode.org", |
| 97 | + ] |
| 98 | + } |
| 99 | + } |
| 100 | +} |
| 101 | + |
| 102 | + |
| 103 | +# Resources API has been shut down |
| 104 | +# # Resources API prod |
| 105 | +# module "resources_api_prod" { |
| 106 | +# source = "./resources_api" |
| 107 | + |
| 108 | +# env = "prod" |
| 109 | +# vpc_id = data.aws_vpc.use2.id |
| 110 | +# logs_group = aws_cloudwatch_log_group.ecslogs.name |
| 111 | +# ecs_cluster_id = module.ecs.cluster_id |
| 112 | +# task_execution_role = data.aws_iam_role.ecs_task_execution_role.arn |
| 113 | +# image_tag = "202b27d4a8be4418089469e1c79e04277268962e" |
| 114 | +# } |
| 115 | + |
| 116 | +# resource "aws_lb_listener_rule" "resources_api_prod" { |
| 117 | +# listener_arn = aws_lb_listener.default_https.arn |
| 118 | + |
| 119 | +# action { |
| 120 | +# type = "forward" |
| 121 | +# target_group_arn = module.resources_api_prod.lb_tg_arn |
| 122 | +# } |
| 123 | + |
| 124 | +# condition { |
| 125 | +# host_header { |
| 126 | +# values = ["resources.operationcode.org"] |
| 127 | +# } |
| 128 | +# } |
| 129 | +# } |
| 130 | + |
| 131 | +# # Resources API staging |
| 132 | +# module "resources_api_staging" { |
| 133 | +# source = "./resources_api" |
| 134 | + |
| 135 | +# env = "staging" |
| 136 | +# vpc_id = data.aws_vpc.use2.id |
| 137 | +# logs_group = aws_cloudwatch_log_group.ecslogs.name |
| 138 | +# ecs_cluster_id = module.ecs.cluster_id |
| 139 | +# task_execution_role = data.aws_iam_role.ecs_task_execution_role.arn |
| 140 | +# image_tag = "fb8c59d54a5a4aed9f9cf58144eecee69f9fc58e" |
| 141 | +# } |
| 142 | + |
| 143 | +# resource "aws_lb_listener_rule" "resources_api_staging" { |
| 144 | +# listener_arn = aws_lb_listener.default_https.arn |
| 145 | + |
| 146 | +# action { |
| 147 | +# type = "forward" |
| 148 | +# target_group_arn = module.resources_api_staging.lb_tg_arn |
| 149 | +# } |
| 150 | + |
| 151 | +# condition { |
| 152 | +# host_header { |
| 153 | +# values = ["resources.staging.operationcode.org", "resources-staging.operationcode.org"] |
| 154 | +# } |
| 155 | +# } |
| 156 | +# } |
| 157 | + |
| 158 | + |
| 159 | +# note: pybot moving off to Render.com |
| 160 | +# Pybot staging |
| 161 | +# module "pybot_staging" { |
| 162 | +# source = "./pybot" |
| 163 | + |
| 164 | +# env = "staging" |
| 165 | +# vpc_id = data.aws_vpc.use2.id |
| 166 | +# logs_group = aws_cloudwatch_log_group.ecslogs.name |
| 167 | +# ecs_cluster_id = module.ecs.cluster_id |
| 168 | +# task_execution_role = data.aws_iam_role.ecs_task_execution_role.arn |
| 169 | +# image_tag = "staging" |
| 170 | +# } |
| 171 | + |
| 172 | +# resource "aws_lb_listener_rule" "pybot_staging" { |
| 173 | +# listener_arn = aws_lb_listener.default_https.arn |
| 174 | + |
| 175 | +# action { |
| 176 | +# type = "forward" |
| 177 | +# target_group_arn = module.pybot_staging.lb_tg_arn |
| 178 | +# } |
| 179 | + |
| 180 | +# condition { |
| 181 | +# host_header { |
| 182 | +# values = ["pybot.staging.operationcode.org"] |
| 183 | +# } |
| 184 | +# } |
| 185 | + |
| 186 | +# condition { |
| 187 | +# path_pattern { |
| 188 | +# values = ["/slack/*", "/pybot/*", "/airtable/*"] |
| 189 | +# } |
| 190 | +# } |
| 191 | +# } |
0 commit comments