Skip to content

Commit

Permalink
fix number
Browse files Browse the repository at this point in the history
  • Loading branch information
leiicamundi committed Jan 17, 2025
1 parent 5dfae67 commit a7ccd3a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion modules/eks-cluster/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ module "eks_cluster" {
| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |
| [aws_servicequotas_service_quota.elastic_ip_quota](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/servicequotas_service_quota) | data source |
| [external_external.elastic_ip_quota](https://registry.terraform.io/providers/hashicorp/external/latest/docs/data-sources/external) | data source |
| [external_external.elastic_ips](https://registry.terraform.io/providers/hashicorp/external/latest/docs/data-sources/external) | data source |
| [external_external.elastic_ips_count](https://registry.terraform.io/providers/hashicorp/external/latest/docs/data-sources/external) | data source |
## Inputs

| Name | Description | Type | Default | Required |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ if [ $? -ne 0 ]; then
exit 1
fi

# Return the result in a format Terraform's external data source expects
echo "{\"elastic_ips\": $eips}"
eips_count=$(echo "$eips" | jq length)

# Return the quota value in a format Terraform's external data source expects (string: string)
echo "{\"elastic_ips_count\": \"$eips_count\"}"
4 changes: 2 additions & 2 deletions modules/eks-cluster/get_elastic_ips_quota.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ if [ $? -ne 0 ]; then
exit 1
fi

# Return the quota value in a format Terraform's external data source expects
echo "{\"quota\": $quota}"
# Return the quota value in a format Terraform's external data source expects (string: string)
echo "{\"quota\": \"$quota\"}"
12 changes: 6 additions & 6 deletions modules/eks-cluster/vpc.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,20 @@ data "external" "elastic_ip_quota" {
}


data "external" "elastic_ips" {
program = ["bash", "./get_elastic_ips.sh", var.region]
data "external" "elastic_ips_count" {
program = ["bash", "./get_elastic_ips_count.sh", var.region]
}


check "elastic_ip_quota_check" {
assert {
condition = data.external.elastic_ip_quota.result.quota >= length(local.azs)
error_message = "The Elastic IP quota is insufficient to cover all local availability zones (need: ${length(local.azs)}, have: ${data.external.elastic_ip_quota.result.quota})."
condition = tonumber(data.external.elastic_ip_quota.result.quota) >= length(local.azs)
error_message = "The Elastic IP quota is insufficient to cover all local availability zones (need: ${length(local.azs)}, have: ${tonumber(data.external.elastic_ip_quota.result.quota)})."
}

assert {
condition = (data.external.elastic_ip_quota.result.quota - length(data.external.elastic_ips.result.elastic_ips)) >= length(local.azs)
error_message = "Not enough available Elastic IPs to cover all local availability zones (need: ${length(local.azs)}, have: ${(data.external.elastic_ip_quota.result.quota - length(data.external.elastic_ips.result.elastic_ips))})."
condition = (tonumber(data.external.elastic_ip_quota.result.quota) - tonumber(data.external.elastic_ips_count.result.elastic_ips_count)) >= length(local.azs)
error_message = "Not enough available Elastic IPs to cover all local availability zones (need: ${length(local.azs)}, have: ${(tonumber(data.external.elastic_ip_quota.result.quota) - tonumber(data.external.elastic_ips_count.result.elastic_ips_count))})."
}
}

Expand Down

0 comments on commit a7ccd3a

Please sign in to comment.