Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(eks-vpc): verify available ec2 elastic ips quotas before apply #136

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
2 changes: 2 additions & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ awscli 2.23.8

golang 1.23.5

jq 1.7.1

just 1.39.0

pre-commit 4.1.0
Expand Down
4 changes: 4 additions & 0 deletions modules/rosa-hcp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
| Name | Type |
|------|------|
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
| [aws_eips.current_usage](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/eips) | data source |
| [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 |
| [aws_vpcs.current_vpcs](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/vpcs) | data source |
## Inputs

| Name | Description | Type | Default | Required |
Expand Down
28 changes: 28 additions & 0 deletions modules/rosa-hcp/rosa.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,38 @@
data "aws_region" "current" {}

locals {
account_role_prefix = "${var.cluster_name}-account"
operator_role_prefix = "${var.cluster_name}-operator"

tags = {
"owner" = data.aws_caller_identity.current.arn
}

availability_zones_count_computed = var.availability_zones == null ? var.availability_zones_count : (length(var.availability_zones) > 0 ? length(var.availability_zones) : var.availability_zones_count)
}

data "aws_servicequotas_service_quota" "elastic_ip_quota" {
service_code = "ec2"
quota_code = "L-0263D0A3" # Quota code for Elastic IP addresses per region
}


data "aws_eips" "current_usage" {}

# Data source to check if the VPC exists
data "aws_vpcs" "current_vpcs" {
tags = {
Name = "${var.cluster_name}-vpc"
}
}

check "elastic_ip_quota_check" {

# Only check the condition when no existing vpc is there.
assert {
condition = length(data.aws_vpcs.current_vpcs.ids) > 0 || (data.aws_servicequotas_service_quota.elastic_ip_quota.value - length(data.aws_eips.current_usage.public_ips)) >= local.availability_zones_count_computed
error_message = "Not enough available Elastic IPs to cover all local availability zones (need: ${local.availability_zones_count_computed}, have: ${(data.aws_servicequotas_service_quota.elastic_ip_quota.value - length(data.aws_eips.current_usage.public_ips))})."
}
}


Expand Down
Loading