Skip to content

Commit 5c0b558

Browse files
committed
BAU: Ensure Proxy resources only deployed in dev
1 parent e1d8cdd commit 5c0b558

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

ci/terraform/account-management/mm-api-dev-access.tf

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,14 @@ resource "aws_instance" "developer_proxy" {
140140
iam_instance_profile = aws_iam_instance_profile.developer_proxy_profile[count.index].name
141141

142142
user_data_replace_on_change = true
143-
user_data = <<-EOT
143+
144+
# TL;DR of user data:
145+
# - Update and upgrade packages
146+
# - Install nginx
147+
# - Write nginx proxy config to /etc/nginx/conf.d/api-proxy.conf
148+
# - Remove `ssm-user` user's sudo access
149+
# - Enable and start nginx
150+
user_data = <<-EOT
144151
#cloud-config
145152
package_update: true
146153
package_upgrade: true
@@ -208,6 +215,9 @@ resource "aws_instance" "developer_proxy" {
208215
}
209216

210217
locals {
218+
# ssm, ssmmessages, ec2messages, logs are required for SSM session manager
219+
# execute-api is required for nginx to connect to the API Gateway
220+
# s3 is required for `dnf` to access the package repositories
211221
required_vpc_interface_endpoints = local.is_dev ? ["ssm", "ssmmessages", "ec2messages", "execute-api", "logs"] : []
212222
required_vpc_gateway_endpoints = local.is_dev ? ["s3"] : []
213223
}

ci/terraform/modules/is-this-the-primary-environment/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,6 @@ which could lead to inconsistencies.
3838
| Name | Description |
3939
|------|-------------|
4040
| <a name="output_is_primary_environment"></a> [is\_primary\_environment](#output\_is\_primary\_environment) | true if this environment is the primary environment in this account:region else false |
41+
| <a name="output_is_primary_environment_with_coresident_dev"></a> [is\_primary\_environment\_with\_coresident\_dev](#output\_is\_primary\_environment\_with\_coresident\_dev) | true if this environment is a primary environment with a coresident dev environment in this account:region else false |
4142
<!-- END_TF_DOCS -->
4243
<!-- prettier-ignore-end -->

ci/terraform/modules/is-this-the-primary-environment/main.tf

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,17 @@ variable "environment" {
2222
}
2323

2424
locals {
25-
primary_environment_names = ["production", "staging", "dev", "build"]
25+
primary_environment_with_coresident_dev_names = ["dev", "build"]
26+
primary_environment_names = concat(local.primary_environment_with_coresident_dev_names, ["production", "staging"])
2627
}
2728

2829
output "is_primary_environment" {
2930
value = contains(local.primary_environment_names, var.environment)
3031
description = "true if this environment is the primary environment in this account:region else false"
3132
}
33+
34+
output "is_primary_environment_with_coresident_dev" {
35+
# This is true if the environment is a primary environment and there is a dev environment in this account:region
36+
value = contains(local.primary_environment_with_coresident_dev_names, var.environment) ? true : false
37+
description = "true if this environment is a primary environment with a coresident dev environment in this account:region else false"
38+
}

ci/terraform/shared/session-manager.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
locals {
2-
session_manager_resource_count = module.primary_environment.is_primary_environment ? 1 : 0
2+
session_manager_resource_count = module.primary_environment.is_primary_environment_with_coresident_dev ? 1 : 0
33
}
44
data "aws_iam_policy_document" "ssm_kms_access" {
55
count = local.session_manager_resource_count

0 commit comments

Comments
 (0)