|
| 1 | +provider "aws" { |
| 2 | + region = "ap-south-1" |
| 3 | +} |
| 4 | + |
| 5 | +################################################################################ |
| 6 | +# Capacity Provider |
| 7 | +################################################################################ |
| 8 | + |
| 9 | +run "ecs_capacity_provider_attributes_match" { |
| 10 | + command = plan |
| 11 | + |
| 12 | + module { |
| 13 | + source = "./modules/capacity-provider" |
| 14 | + } |
| 15 | + |
| 16 | + variables { |
| 17 | + ecs_cluster_name = "example-name" |
| 18 | + default_auto_scaling_group_arn = "arn:aws:autoscaling:us-west-2:123456789012:autoScalingGroup:my-asg-group:12345678-1234-1234-1234-123456789012" |
| 19 | + |
| 20 | + capacity_providers = { |
| 21 | + example = { |
| 22 | + name = "example-name" |
| 23 | + managed_scaling = { |
| 24 | + instance_warmup_period = 100 |
| 25 | + status = "ENABLED" |
| 26 | + target_capacity = 100 |
| 27 | + minimum_scaling_step_size = 1 |
| 28 | + maximum_scaling_step_size = 1 |
| 29 | + } |
| 30 | + |
| 31 | + tags = { |
| 32 | + Example = "Tag" |
| 33 | + } |
| 34 | + } |
| 35 | + } |
| 36 | + } |
| 37 | + |
| 38 | + assert { |
| 39 | + condition = aws_ecs_capacity_provider.this["example"].name == var.capacity_providers["example"].name |
| 40 | + error_message = "Name mismatch" |
| 41 | + } |
| 42 | + |
| 43 | + assert { |
| 44 | + condition = aws_ecs_capacity_provider.this["example"].auto_scaling_group_provider[0].auto_scaling_group_arn == var.default_auto_scaling_group_arn |
| 45 | + error_message = "Autoscaling group ARN mismatch" |
| 46 | + } |
| 47 | + |
| 48 | + assert { |
| 49 | + condition = aws_ecs_capacity_provider.this["example"].auto_scaling_group_provider[0].managed_scaling[0].instance_warmup_period == var.capacity_providers["example"].managed_scaling.instance_warmup_period |
| 50 | + error_message = "Instance warmup period mismatch" |
| 51 | + } |
| 52 | + |
| 53 | + assert { |
| 54 | + condition = aws_ecs_capacity_provider.this["example"].auto_scaling_group_provider[0].managed_scaling[0].status == var.capacity_providers["example"].managed_scaling.status |
| 55 | + error_message = "Managed scaling status mismatch" |
| 56 | + } |
| 57 | + |
| 58 | + assert { |
| 59 | + condition = aws_ecs_capacity_provider.this["example"].auto_scaling_group_provider[0].managed_scaling[0].target_capacity == var.capacity_providers["example"].managed_scaling.target_capacity |
| 60 | + error_message = "Managed scaling target capacity mismatch" |
| 61 | + } |
| 62 | + |
| 63 | + assert { |
| 64 | + condition = aws_ecs_capacity_provider.this["example"].auto_scaling_group_provider[0].managed_scaling[0].minimum_scaling_step_size == var.capacity_providers["example"].managed_scaling.minimum_scaling_step_size |
| 65 | + error_message = "Managed scaling minimum scaling step size mismatch" |
| 66 | + } |
| 67 | + |
| 68 | + assert { |
| 69 | + condition = aws_ecs_capacity_provider.this["example"].auto_scaling_group_provider[0].managed_scaling[0].maximum_scaling_step_size == var.capacity_providers["example"].managed_scaling.maximum_scaling_step_size |
| 70 | + error_message = "Managed scaling maximum scaling step size mismatch" |
| 71 | + } |
| 72 | + |
| 73 | + assert { |
| 74 | + condition = aws_ecs_capacity_provider.this["example"].auto_scaling_group_provider[0].managed_termination_protection == "ENABLED" |
| 75 | + error_message = "Managed termination protection mismatch" |
| 76 | + } |
| 77 | + |
| 78 | + assert { |
| 79 | + condition = aws_ecs_capacity_provider.this["example"].tags == var.capacity_providers["example"].tags |
| 80 | + error_message = "Tags mismatch" |
| 81 | + } |
| 82 | +} |
| 83 | + |
| 84 | +################################################################################ |
| 85 | +# ECS Cluster Capacity Providers |
| 86 | +################################################################################ |
| 87 | + |
| 88 | +run "ecs_cluster_capacity_providers_attributes_match" { |
| 89 | + command = plan |
| 90 | + |
| 91 | + module { |
| 92 | + source = "./modules/capacity-provider" |
| 93 | + } |
| 94 | + |
| 95 | + variables { |
| 96 | + ecs_cluster_name = "example-name" |
| 97 | + default_auto_scaling_group_arn = "arn:aws:autoscaling:us-west-2:123456789012:autoScalingGroup:my-asg-group:12345678-1234-1234-1234-123456789012" |
| 98 | + |
| 99 | + capacity_providers = { |
| 100 | + example = { |
| 101 | + name = "example-name" |
| 102 | + managed_scaling = { |
| 103 | + instance_warmup_period = 100 |
| 104 | + status = "ENABLED" |
| 105 | + target_capacity = 100 |
| 106 | + minimum_scaling_step_size = 1 |
| 107 | + maximum_scaling_step_size = 1 |
| 108 | + } |
| 109 | + |
| 110 | + tags = { |
| 111 | + Example = "Tag" |
| 112 | + } |
| 113 | + } |
| 114 | + } |
| 115 | + default_capacity_provider_strategies = [ |
| 116 | + { |
| 117 | + capacity_provider = "example" |
| 118 | + base = 0 |
| 119 | + weight = 1 |
| 120 | + } |
| 121 | + ] |
| 122 | + } |
| 123 | + |
| 124 | + assert { |
| 125 | + condition = aws_ecs_cluster_capacity_providers.this.cluster_name == var.ecs_cluster_name |
| 126 | + error_message = "ECS Cluster name mismatch" |
| 127 | + } |
| 128 | + |
| 129 | + assert { |
| 130 | + condition = aws_ecs_cluster_capacity_providers.this.capacity_providers == toset([for _, v in var.capacity_providers : v.name]) |
| 131 | + error_message = "Capacity providers mismatch" |
| 132 | + } |
| 133 | + |
| 134 | + assert { |
| 135 | + condition = tolist(aws_ecs_cluster_capacity_providers.this.default_capacity_provider_strategy)[0].capacity_provider == var.capacity_providers["example"].name |
| 136 | + error_message = "Default capacity provider strategy's capacity provider mismatch" |
| 137 | + } |
| 138 | + |
| 139 | + assert { |
| 140 | + condition = tolist(aws_ecs_cluster_capacity_providers.this.default_capacity_provider_strategy)[0].base == var.default_capacity_provider_strategies[0].base |
| 141 | + error_message = "Default capacity provider strategy's base mismatch" |
| 142 | + } |
| 143 | + |
| 144 | + assert { |
| 145 | + condition = tolist(aws_ecs_cluster_capacity_providers.this.default_capacity_provider_strategy)[0].weight == var.default_capacity_provider_strategies[0].weight |
| 146 | + error_message = "Default capacity provider strategy's weight mismatch" |
| 147 | + } |
| 148 | +} |
0 commit comments