terraform-aws-observability-accelerator icon indicating copy to clipboard operation
terraform-aws-observability-accelerator copied to clipboard

[Bug]: new eks-cluster example fails when running in a region with only 3 az's

Open lewinkedrs opened this issue 1 year ago • 0 comments

Welcome to the AWS Observability Accelerator

  • [X] Yes, I've searched similar issues on GitHub and didn't find any.

AWS Observability Accelerator Release version

latest

What is your environment, configuration and the example used?

When running the eks-cluster-with-vpc example we use this in main.tf:

data "aws_availability_zones" "available" {}

locals {
  name         = basename(path.cwd)
  cluster_name = coalesce(var.cluster_name, local.name)
  region       = var.aws_region

  vpc_cidr = "10.0.0.0/16"
  azs      = slice(data.aws_availability_zones.available.names, 0, 3)

If you run this in a region with only 3 AZs like us-west-1 you get an error because the end value of the slice (3) exceeds the amount of items in the list (2) These are zero-indexed: If you change the above code to this:

data "aws_availability_zones" "available" {}

locals {
  name         = basename(path.cwd)
  cluster_name = coalesce(var.cluster_name, local.name)
  region       = var.aws_region

  vpc_cidr = "10.0.0.0/16"
  azs      = slice(data.aws_availability_zones.available.names, 0, 2)

You no longer get the error. We probably should read the amount of items in the 'aws_availability_zones' list and use that to set the end value of the slice.

What did you do and What did you see instead?

This worked in us-west-1 by manually changing slice index.

Additional Information

No response

lewinkedrs avatar Jul 13 '23 14:07 lewinkedrs