Skip to content

Commit 468812b

Browse files
authored
feat-polishing (#4)
1 parent 56ed186 commit 468812b

File tree

16 files changed

+430
-116
lines changed

16 files changed

+430
-116
lines changed

README.md

Lines changed: 58 additions & 26 deletions
Large diffs are not rendered by default.

docs/ecs-diagram.png

151 KB
Loading

document_db.tf

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
locals {
22
documentdb_enabled = var.external_documentdb == null
3-
documentdb_subnet_ids = slice(local.private_subnet_ids, 0, min(length(local.private_subnet_ids), var.document_db.cluster_size))
3+
documentdb_subnet_ids = slice(local.private_subnet_ids, 0, min(length(local.private_subnet_ids), max(2, var.document_db.cluster_size)))
44
}
55

66
module "documentdb_cluster" {
@@ -19,7 +19,7 @@ module "documentdb_cluster" {
1919
cluster_size = try(var.document_db["cluster_size"], null)
2020
instance_class = try(var.document_db["instance_class"], null)
2121

22-
master_username = try(var.document_db["master_username"], null)
22+
master_username = random_pet.document_db_username.id
2323

2424
engine_version = try(var.document_db["engine_version"], null)
2525

@@ -30,6 +30,10 @@ module "documentdb_cluster" {
3030
cluster_parameters = try(var.document_db["cluster_parameters"], [])
3131
}
3232

33+
resource "random_pet" "document_db_username" {
34+
length = 1
35+
}
36+
3337
module "document_db_ssm_password" {
3438
source = "cloudposse/ssm-parameter-store/aws"
3539
version = "0.11.0"

ecs-ec2.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ locals {
4949
ECS_ENABLE_HIGH_DENSITY_ENI=true
5050
ECS_ENABLE_SPOT_INSTANCE_DRAINING=true
5151
ECS_ENGINE_AUTH_TYPE=dockercfg
52-
ECS_ENGINE_AUTH_DATA=${sensitive(base64decode(var.ecs_auth_data))} # pragma: allowlist secret
52+
ECS_ENGINE_AUTH_DATA=${sensitive(base64decode(var.ecs_registry_auth_data))} # pragma: allowlist secret
5353
EOF
5454
EOT
5555
}
@@ -286,7 +286,7 @@ module "ecs_cluster" {
286286
cluster_name = module.label.id
287287

288288
cluster_configuration = {
289-
execute_command_configuration = var.ecs_cluster_configuration
289+
execute_command_configuration = var.ecs_cluster_config
290290
}
291291

292292
cluster_service_connect_defaults = {

elasticache.tf

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,11 @@ module "elasticache" {
3131
family = try(var.elasticache["family"], null)
3232
at_rest_encryption_enabled = try(var.elasticache["at_rest_encryption_enabled"], null)
3333
transit_encryption_enabled = try(var.elasticache["transit_encryption_enabled"], null)
34-
auth_token = random_password.redis.result
34+
auth_token = random_password.redis_password.result
3535
parameter = try(var.elasticache["parameter"], null)
3636
}
3737

38-
resource "random_password" "redis" {
39-
keepers = {
40-
ami_id = module.label.id
41-
}
38+
resource "random_password" "redis_password" {
4239
min_upper = 1
4340
min_lower = 1
4441
min_numeric = 1
@@ -55,7 +52,7 @@ module "elasticache_ssm_password" {
5552
parameter_write = [
5653
{
5754
name = "/${module.label.id}/elasticache/auth_token"
58-
value = sensitive(random_password.redis.result)
55+
value = sensitive(random_password.redis_password.result)
5956
type = "SecureString"
6057
overwrite = "true"
6158
description = "Auth token for ${module.elasticache.id} Elasticache"

elasticsearch.tf

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
locals {
2-
elasticsearch_master_username = random_pet.elasticsearch.id
2+
elasticsearch_master_username = random_pet.elasticsearch_username.id
33
elasticsearch_enabled = var.external_elasticsearch == null
44
elasticsearch_subnet_ids = slice(local.private_subnet_ids, 0, min(length(local.private_subnet_ids), var.elasticsearch.instance_count))
55
}
@@ -37,9 +37,9 @@ module "elasticsearch" {
3737
advanced_security_options_enabled = true
3838
advanced_security_options_internal_user_database_enabled = true
3939
advanced_security_options_master_user_name = local.elasticsearch_master_username
40-
advanced_security_options_master_user_password = random_password.elasticsearch.result
40+
advanced_security_options_master_user_password = random_password.elasticsearch_password.result
4141
}
42-
resource "random_password" "elasticsearch" {
42+
resource "random_password" "elasticsearch_password" {
4343
min_upper = 1
4444
min_lower = 1
4545
min_numeric = 1
@@ -48,7 +48,8 @@ resource "random_password" "elasticsearch" {
4848
length = 16
4949
}
5050

51-
resource "random_pet" "elasticsearch" {
51+
resource "random_pet" "elasticsearch_username" {
52+
length = 1
5253
}
5354

5455

@@ -61,7 +62,7 @@ module "elasticsearch_ssm_password" {
6162
parameter_write = [
6263
{
6364
name = "/${module.label.id}/elasticsearch/master_password"
64-
value = sensitive(random_password.elasticsearch.result)
65+
value = sensitive(random_password.elasticsearch_password.result)
6566
type = "SecureString"
6667
overwrite = "true"
6768
description = "Master password for Elasticsearch ${module.elasticsearch.domain_name} "

examples/development/README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Basic example
22

3-
The code in this example shows how to use the module with basic configuration and minimal set of other resources.
3+
The code in this example shows how to use the module with development configuration and minimal set of other resources.
44

55
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
66
## Requirements
@@ -14,7 +14,9 @@ The code in this example shows how to use the module with basic configuration an
1414

1515
| Name | Source | Version |
1616
|------|--------|---------|
17-
| <a name="module_example_module"></a> [example\_module](#module\_example\_module) | ../../ | n/a |
17+
| <a name="module_appmixer_module"></a> [appmixer\_module](#module\_appmixer\_module) | ../../ | n/a |
18+
| <a name="module_subnets"></a> [subnets](#module\_subnets) | cloudposse/dynamic-subnets/aws | 2.4.1 |
19+
| <a name="module_vpc"></a> [vpc](#module\_vpc) | cloudposse/vpc/aws | 2.1.1 |
1820

1921
## Resources
2022

@@ -26,5 +28,7 @@ No inputs.
2628

2729
## Outputs
2830

29-
No outputs.
31+
| Name | Description |
32+
|------|-------------|
33+
| <a name="output_appmixer_module"></a> [appmixer\_module](#output\_appmixer\_module) | n/a |
3034
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

examples/development/main.tf

Lines changed: 149 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,165 @@
1-
module "example_module" {
1+
locals {
2+
vpc_cidr_block = "10.0.0.0/16"
3+
name = "appmixer"
4+
environment = "dev"
5+
namespace = "cio"
6+
}
7+
8+
module "vpc" {
9+
source = "cloudposse/vpc/aws"
10+
version = "2.1.1"
11+
name = local.name
12+
namespace = local.namespace
13+
environment = local.environment
14+
ipv4_primary_cidr_block = local.vpc_cidr_block
15+
assign_generated_ipv6_cidr_block = true
16+
internet_gateway_enabled = true
17+
}
18+
19+
module "subnets" {
20+
source = "cloudposse/dynamic-subnets/aws"
21+
version = "2.4.1"
22+
name = local.name
23+
namespace = local.namespace
24+
environment = local.environment
25+
vpc_id = module.vpc.vpc_id
26+
igw_id = [module.vpc.igw_id]
27+
nat_gateway_enabled = true
28+
ipv4_cidr_block = [local.vpc_cidr_block]
29+
availability_zones = ["eu-central-1a", "eu-central-1b", "eu-central-1c"]
30+
}
31+
32+
33+
module "appmixer_module" {
234
source = "../../"
335

36+
name = local.name
37+
namespace = local.environment
38+
environment = local.environment
39+
440
root_dns_name = "ecs.appmixer.co"
541
zone_id = "XXX"
642

43+
external_vpc = {
44+
vpc_id = module.vpc.vpc_id
45+
public_subnet_ids = module.subnets.public_subnet_ids
46+
private_subnet_ids = module.subnets.private_subnet_ids
47+
}
48+
49+
ecs_registry_auth_data = "XXX"
50+
751
init_user = {
852
email = "XXX"
953
username = "XXX"
1054
password = "XXX"
1155
}
1256

13-
ecs_auth_data = "XXX"
57+
enable_deletion_protection = false
58+
59+
elasticache = {
60+
parameter = [
61+
{
62+
name = "notify-keyspace-events"
63+
value = "lK"
64+
}
65+
]
66+
}
67+
ecs_autoscaling_config = {
68+
on_demand = {
69+
instance_type = "m5.large"
70+
use_mixed_instances_policy = true
71+
mixed_instances_policy = {
72+
instances_distribution = {
73+
on_demand_base_capacity = 1 # min 1 on demand instance
74+
on_demand_percentage_above_base_capacity = 100 # 100% on demand instances
75+
on_demand_allocation_strategy = "lowest-price"
76+
}
77+
override = [
78+
{
79+
instance_type = "m5.large"
80+
weighted_capacity = "1"
81+
},
82+
{
83+
instance_type = "c5.large"
84+
weighted_capacity = "1"
85+
}
86+
]
87+
}
88+
89+
max_size = 2
90+
min_size = 1
91+
capacity_provider = {
92+
maximum_scaling_step_size = 1
93+
minimum_scaling_step_size = 1
94+
target_capacity = 100
95+
default_capacity_provider_strategy = {
96+
weight = 10
97+
base = 1
98+
}
99+
}
100+
}
101+
spot = {
102+
instance_type = "m5.large"
103+
use_mixed_instances_policy = true
104+
mixed_instances_policy = {
105+
instances_distribution = {
106+
on_demand_base_capacity = 0 # min 0 on demand instance
107+
on_demand_percentage_above_base_capacity = 0 # 0% on demand instances
108+
spot_allocation_strategy = "lowest-price"
109+
}
110+
override = [
111+
{
112+
instance_type = "m5.large"
113+
weighted_capacity = "1"
114+
},
115+
{
116+
instance_type = "c5.large"
117+
weighted_capacity = "1"
118+
}
119+
]
120+
}
121+
max_size = 2
122+
min_size = 1
123+
capacity_provider = {
124+
maximum_scaling_step_size = 1
125+
minimum_scaling_step_size = 1
126+
target_capacity = 100
127+
default_capacity_provider_strategy = {
128+
weight = 80
129+
base = 0
130+
}
131+
}
132+
}
133+
}
14134

15135
ecs_common_service_config = {
136+
autoscaling_min_capacity = 2
16137
wait_for_steady_state = true
17-
autoscaling_min_capacity = 1
138+
force_new_deployment = true
139+
ordered_placement_strategy = [
140+
{
141+
type = "spread"
142+
field = "attribute:ecs.availability-zone"
143+
},
144+
{
145+
type = "binpack"
146+
field = "cpu"
147+
},
148+
]
18149
}
150+
151+
# Mongo DB TLS temporary disabled - to enable just remove env variables below
152+
ecs_per_service_config = {
153+
engine = {
154+
env = {
155+
DB_SSL_VALIDATE = "false"
156+
DB_USE_TLS = "false"
157+
DB_TLS_CA_FILE = ""
158+
}
159+
}
160+
}
161+
}
162+
163+
output "appmixer_module" {
164+
value = module.appmixer_module
19165
}

examples/production/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Basic example
22

3-
The code in this example shows how to use the module with basic configuration and minimal set of other resources.
3+
The code in this example shows how to use the module with production configuration and minimal set of other resources.
44

55
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
66
## Requirements
@@ -14,7 +14,7 @@ The code in this example shows how to use the module with basic configuration an
1414

1515
| Name | Source | Version |
1616
|------|--------|---------|
17-
| <a name="module_example_module"></a> [example\_module](#module\_example\_module) | ../../ | n/a |
17+
| <a name="module_appmixer_module"></a> [appmixer\_module](#module\_appmixer\_module) | ../../ | n/a |
1818

1919
## Resources
2020

0 commit comments

Comments
 (0)