11locals {
2+ aws_partition = data. aws_partition . current . partition
3+
24 vpc_dns_resolver = module. this . enabled ? cidrhost (data. aws_vpc . lookup [0 ]. cidr_block , 2 ) : " 10.0.0.2"
35 proxies = { for k , v in var . proxies : k => merge (v, { name = k }) }
46 proxies_port_range = [local . proxies . default . listener_port , local . proxies . default . listener_port ]
@@ -27,16 +29,18 @@ locals {
2729 }
2830}
2931
32+ data "aws_partition" "current" {}
33+
3034# ================================================================== service ===
3135
3236module "proxy" {
3337 source = " cloudposse/ec2-autoscale-group/aws"
34- version = " 0.41.0 "
38+ version = " 0.41.1 "
3539
3640 image_id = data. aws_ssm_parameter . linux_ami . value
3741 instance_type = " t3.nano"
3842 health_check_type = " ELB"
39- user_data_base64 = base64encode (module. this . enabled ? data. template_cloudinit_config . this [0 ]. rendered : " " )
43+ user_data_base64 = base64encode (module. this . enabled ? data. cloudinit_config . this [0 ]. rendered : " " )
4044 force_delete = true
4145 disable_api_termination = false
4246 update_default_version = true
@@ -50,39 +54,27 @@ module "proxy" {
5054 }
5155
5256 iam_instance_profile_name = module. this . enabled ? resource. aws_iam_instance_profile . this [0 ]. id : null
53- key_name = " "
57+ key_name = var . key_name
5458 metadata_http_tokens_required = true
5559
5660 autoscaling_policies_enabled = false
5761 desired_capacity = local. capacity . desired
58- min_size = var . capacity . min
59- max_size = var . capacity . max
62+ min_size = local . capacity . min
63+ max_size = local . capacity . max
6064 max_instance_lifetime = " 604800"
6165 wait_for_capacity_timeout = " 300s"
6266 tag_specifications_resource_types = [" instance" , " volume" , " spot-instances-request" ]
6367
6468 mixed_instances_policy = {
6569 instances_distribution = {
66- on_demand_base_capacity = 0
67- on_demand_percentage_above_base_capacity = 0
70+ on_demand_base_capacity = var.spot.enabled ? 0 : 100
71+ on_demand_percentage_above_base_capacity = var.spot.enabled ? 0 : 100
6872 on_demand_allocation_strategy = " prioritized"
69- spot_allocation_strategy = " capacity-optimized "
73+ spot_allocation_strategy = var.spot.allocation_strategy
7074 spot_instance_pools = 0
7175 spot_max_price = " "
7276 }
73- override = [{
74- instance_type = " t3.nano"
75- weighted_capacity = 1
76- }, {
77- instance_type = " t3a.nano"
78- weighted_capacity = 1
79- }, {
80- instance_type = " t3.micro"
81- weighted_capacity = 1
82- }, {
83- instance_type = " t3a.micro"
84- weighted_capacity = 1
85- }]
77+ override = [for x in var . instance_types : { instance_type = x.type, weighted_capacity = x.weight }]
8678 }
8779
8880 associate_public_ip_address = false
@@ -94,7 +86,7 @@ module "proxy" {
9486 context = module. this . context
9587}
9688
97- data "template_cloudinit_config " "this" {
89+ data "cloudinit_config " "this" {
9890 count = module. this . enabled ? 1 : 0
9991
10092 gzip = true
@@ -266,7 +258,7 @@ resource "aws_iam_role_policy_attachment" "ssm_managed_instance_core" {
266258 count = module. this . enabled ? 1 : 0
267259
268260 role = resource. aws_iam_role . this [0 ]. name
269- policy_arn = " arn:aws :iam::aws:policy/AmazonSSMManagedInstanceCore"
261+ policy_arn = " arn:${ local . aws_partition } :iam::aws:policy/AmazonSSMManagedInstanceCore"
270262}
271263
272264resource "aws_iam_policy" "this" {
@@ -307,8 +299,8 @@ data "aws_iam_policy_document" "this" {
307299 " s3:GetBucketLocation" ,
308300 ]
309301 resources = [
310- " arn:aws :s3:::${ var . ssm_sessions . logs_bucket_name } " ,
311- " arn:aws :s3:::${ var . ssm_sessions . logs_bucket_name } /*"
302+ " arn:${ local . aws_partition } :s3:::${ var . ssm_sessions . logs_bucket_name } " ,
303+ " arn:${ local . aws_partition } :s3:::${ var . ssm_sessions . logs_bucket_name } /*"
312304 ]
313305 }
314306 }
0 commit comments