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

selectel_vpc_project_v2: Creation of quotas for all zones in the region. #198

Open
Protopopys opened this issue Jun 20, 2022 · 1 comment
Assignees

Comments

@Protopopys
Copy link

Terraform Version

Terraform v1.2.1
on linux_amd64

Selectel provider version

provider "terraform.local/local/selectel" {
  version = "3.8.4"
  hashes = [
    "h1:Em750VxHAYjzt/YR0TkxtznQ0aM0yDNglozd5OK0GT4=",
  ]
}

Affected Resource(s)

  • selectel_vpc_project_v2

Terraform Configuration Files

# Initialize Selectel provider with token.
provider "selectel" {
  token = var.sel_token
}

# (Required) Selectel Provider access token.
variable "sel_token" {
  type = string
}

resource "selectel_vpc_project_v2" "project_1" {
  name        = var.project_name
  auto_quotas = var.auto_quotas
  dynamic "quotas" {
    for_each = var.quotas[*]
    content {
      resource_name = quotas.value["resource_name"]
      resource_quotas {
        region = quotas.value["region"]
        zone = quotas.value["zone"]
        value = quotas.value["value"]
      }
    }
  }
}

variable "quotas" {
  type = list(object({
    resource_name = string
    region = string
    zone = string
    value = number
  }))
  default = [ {
    resource_name = "mks_cluster_regional"
    region = "ru-2"
    zone = null
    value = 1
  },

  {
    resource_name = "compute_cores"
    region = "ru-2"
    zone = "ru-2a"
    value = 8
  },
  {
    resource_name = "compute_cores"
    region = "ru-2"
    zone = "ru-2b"
    value = 8
  },
  {
    resource_name = "compute_cores"
    region = "ru-2"
    zone = "ru-2c"
    value = 8
  },

  {
    resource_name = "compute_ram"
    region = "ru-2"
    zone = "ru-2a"
    value = 32768
  },
  {
    resource_name = "compute_ram"
    region = "ru-2"
    zone = "ru-2b"
    value = 32768
  },  
  {
    resource_name = "compute_ram"
    region = "ru-2"
    zone = "ru-2c"
    value = 32768
  } ]
}


terraform {
  backend "http" {
  }

  required_providers {
    selectel = {
      source = "terraform.local/local/selectel"
    }
  }
  required_version = ">= 0.13"
}

Expected Behavior

1 - A project will be created.
2 - Quotas will be created for three zones in one region.

Actual Behavior

1 - The project was created.
2 - A quota was created for only one zone in the region

Steps to Reproduce

Please list the steps required to reproduce the issue

  1. terraform apply

Important Factoids

As it turned out, in one zone of three resource limit for the account was exhausted - the error did not appear when creating limits in this zone.
When trying to create quotas for two zones where the limits are not exhausted, quotas are created only for one zone.

@dkder3k
Copy link
Collaborator

dkder3k commented Jun 29, 2022

Hello. As described in documentation resource_quotas is an array that is defined inside quotas block.

In your example dynamic block translates in structure like this:

...
quotas {                                                                                         
  resource_name = "compute_cores"                                                              
                                                    
  resource_quotas {                                                                                                                                                                                      
    region = "ru-2"                                                                          
    value  = 8
    zone   = "ru-2a"
  }
}
quotas {                                                                                         
  resource_name = "compute_cores"                                                              

  resource_quotas {
    region = "ru-2"
    value  = 8
    zone   = "ru-2b"
  }
}
...

And because there are 2 quotas block with the same resource_name terraform uses just one of them (in fact just overrides value at some moment).
To achieve your expected result something like this can be used:

...
resource "selectel_vpc_project_v2" "project_1" {
  name        = var.project_name
  auto_quotas = var.auto_quotas

  dynamic "quotas" {
    for_each = var.quotas[*]
    content {
      resource_name = quotas.value["resource_name"]
      dynamic "resource_quotas" {
        for_each = quotas.value["region_zone_quotas"]
        content {
          region = resource_quotas.value["region"]
          zone = resource_quotas.value["zone"]
          value = resource_quotas.value["value"]
        }
      }
    }
  }
}

variable "quotas" {
  type = list(object({
    resource_name = string
    region_zone_quotas = list(object({
      region = string
      zone = string
      value = number
    }))
  }))
  default = [ {
    resource_name = "mks_cluster_regional"
    region_zone_quotas = [{
      region = "ru-2"
      zone = null
      value = 1
    }]
  },
  {
    resource_name = "compute_cores"
    region_zone_quotas = [{
      region = "ru-2"
      zone = "ru-2a"
      value = 8
    },
    {
      region = "ru-2"
      zone = "ru-2b"
      value = 8
    },
    {
      region = "ru-2"
      zone = "ru-2c"
      value = 8
    }]
  },
  {
    resource_name = "compute_ram"
    region_zone_quotas = [{
      region = "ru-2"
      zone = "ru-2a"
      value = 32768
    },
    {
      region = "ru-2"
      zone = "ru-2b"
      value = 32768
    },
    {
      region = "ru-2"
      zone = "ru-2c"
      value = 32768
    }]
  }]
}
...

Note that dynamic block inside dynamic block translates like this:

...
quotas {                                                                                         
  resource_name = "compute_cores"                                                              
                                                    
  resource_quotas {                                                                                                                                                                                      
    region = "ru-2"                                                                          
    value  = 8
    zone   = "ru-2a"
  }
  resource_quotas {
    region = "ru-2"
    value  = 8
    zone   = "ru-2b"
  }
}
...

and works as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants