terraform: instance_count => initial_count (#1989)

Normalize naming for the "instance_count" / "initial_count" int terraform to always use "initial_count".
This is required, since there is a naming confusion on AWS.
"initial_count" is more precise, since it reflects the fact that this value is ignored when applying the terraform template
after the scaling groups already exist.
This commit is contained in:
Malte Poll 2023-06-30 10:53:00 +02:00 committed by GitHub
parent 00ee11084e
commit 5f8ea1348a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 82 additions and 82 deletions

View file

@ -227,20 +227,20 @@ func (c *Creator) createAzure(ctx context.Context, cl terraformClient, opts Crea
Name: opts.Config.Name, Name: opts.Config.Name,
NodeGroups: map[string]terraform.AzureNodeGroup{ NodeGroups: map[string]terraform.AzureNodeGroup{
"control_plane_default": { "control_plane_default": {
Role: role.ControlPlane.TFString(), Role: role.ControlPlane.TFString(),
InstanceCount: toPtr(opts.ControlPlaneCount), InitialCount: toPtr(opts.ControlPlaneCount),
InstanceType: opts.InsType, InstanceType: opts.InsType,
DiskSizeGB: opts.Config.StateDiskSizeGB, DiskSizeGB: opts.Config.StateDiskSizeGB,
DiskType: opts.Config.Provider.Azure.StateDiskType, DiskType: opts.Config.Provider.Azure.StateDiskType,
Zones: nil, // TODO(elchead): support zones AB#3225 Zones: nil, // TODO(elchead): support zones AB#3225
}, },
"worker_default": { "worker_default": {
Role: role.Worker.TFString(), Role: role.Worker.TFString(),
InstanceCount: toPtr(opts.WorkerCount), InitialCount: toPtr(opts.WorkerCount),
InstanceType: opts.InsType, InstanceType: opts.InsType,
DiskSizeGB: opts.Config.StateDiskSizeGB, DiskSizeGB: opts.Config.StateDiskSizeGB,
DiskType: opts.Config.Provider.Azure.StateDiskType, DiskType: opts.Config.Provider.Azure.StateDiskType,
Zones: nil, Zones: nil,
}, },
}, },
Location: opts.Config.Provider.Azure.Location, Location: opts.Config.Provider.Azure.Location,
@ -427,18 +427,18 @@ func (c *Creator) createQEMU(ctx context.Context, cl terraformClient, lv libvirt
ImageFormat: opts.Config.Provider.QEMU.ImageFormat, ImageFormat: opts.Config.Provider.QEMU.ImageFormat,
NodeGroups: map[string]terraform.QEMUNodeGroup{ NodeGroups: map[string]terraform.QEMUNodeGroup{
"control_plane_default": { "control_plane_default": {
Role: role.ControlPlane.TFString(), Role: role.ControlPlane.TFString(),
InstanceCount: opts.ControlPlaneCount, InitialCount: opts.ControlPlaneCount,
DiskSize: opts.Config.StateDiskSizeGB, DiskSize: opts.Config.StateDiskSizeGB,
CPUCount: opts.Config.Provider.QEMU.VCPUs, CPUCount: opts.Config.Provider.QEMU.VCPUs,
MemorySize: opts.Config.Provider.QEMU.Memory, MemorySize: opts.Config.Provider.QEMU.Memory,
}, },
"worker_default": { "worker_default": {
Role: role.Worker.TFString(), Role: role.Worker.TFString(),
InstanceCount: opts.WorkerCount, InitialCount: opts.WorkerCount,
DiskSize: opts.Config.StateDiskSizeGB, DiskSize: opts.Config.StateDiskSizeGB,
CPUCount: opts.Config.Provider.QEMU.VCPUs, CPUCount: opts.Config.Provider.QEMU.VCPUs,
MemorySize: opts.Config.Provider.QEMU.Memory, MemorySize: opts.Config.Provider.QEMU.Memory,
}, },
}, },
Machine: "q35", // TODO(elchead): make configurable AB#3225 Machine: "q35", // TODO(elchead): make configurable AB#3225

View file

@ -254,7 +254,7 @@ module "instance_group" {
zone = each.value.zone zone = each.value.zone
uid = local.uid uid = local.uid
instance_type = each.value.instance_type instance_type = each.value.instance_type
instance_count = each.value.instance_count initial_count = each.value.initial_count
image_id = var.ami image_id = var.ami
state_disk_type = each.value.disk_type state_disk_type = each.value.disk_type
state_disk_size = each.value.disk_size state_disk_size = each.value.disk_size

View file

@ -71,7 +71,7 @@ resource "aws_autoscaling_group" "autoscaling_group" {
} }
min_size = 1 min_size = 1
max_size = 10 max_size = 10
desired_capacity = var.instance_count desired_capacity = var.initial_count
vpc_zone_identifier = [var.subnetwork] vpc_zone_identifier = [var.subnetwork]
target_group_arns = var.target_group_arns target_group_arns = var.target_group_arns

View file

@ -27,7 +27,7 @@ variable "instance_type" {
description = "Instance type for the nodes." description = "Instance type for the nodes."
} }
variable "instance_count" { variable "initial_count" {
type = number type = number
description = "Number of instances in the instance group." description = "Number of instances in the instance group."
} }

View file

@ -9,12 +9,12 @@ variable "name" {
variable "node_groups" { variable "node_groups" {
type = map(object({ type = map(object({
role = string role = string
instance_count = optional(number) initial_count = optional(number)
instance_type = string instance_type = string
disk_size = number disk_size = number
disk_type = string disk_type = string
zone = string zone = string
})) }))
description = "A map of node group names to node group configurations." description = "A map of node group names to node group configurations."
validation { validation {

View file

@ -234,7 +234,7 @@ module "scale_set_group" {
{ constellation-maa-url = var.create_maa ? azurerm_attestation_provider.attestation_provider[0].attestation_uri : "" }, { constellation-maa-url = var.create_maa ? azurerm_attestation_provider.attestation_provider[0].attestation_uri : "" },
) )
instance_count = each.value.instance_count initial_count = each.value.initial_count
state_disk_size = each.value.disk_size state_disk_size = each.value.disk_size
state_disk_type = each.value.disk_type state_disk_type = each.value.disk_type
location = var.location location = var.location

View file

@ -37,7 +37,7 @@ resource "azurerm_linux_virtual_machine_scale_set" "scale_set" {
resource_group_name = var.resource_group resource_group_name = var.resource_group
location = var.location location = var.location
sku = var.instance_type sku = var.instance_type
instances = var.instance_count instances = var.initial_count
admin_username = "adminuser" admin_username = "adminuser"
admin_password = random_password.password.result admin_password = random_password.password.result
overprovision = false overprovision = false

View file

@ -28,7 +28,7 @@ variable "zones" {
default = null default = null
} }
variable "instance_count" { variable "initial_count" {
type = number type = number
description = "The number of instances in this scale set." description = "The number of instances in this scale set."
} }

View file

@ -5,12 +5,12 @@ variable "name" {
variable "node_groups" { variable "node_groups" {
type = map(object({ type = map(object({
role = string role = string
instance_count = optional(number) initial_count = optional(number)
instance_type = string instance_type = string
disk_size = number disk_size = number
disk_type = string disk_type = string
zones = optional(list(string)) zones = optional(list(string))
})) }))
description = "A map of node group names to node group configurations." description = "A map of node group names to node group configurations."
validation { validation {

View file

@ -158,7 +158,7 @@ module "instance_group" {
zone = each.value.zone zone = each.value.zone
uid = local.uid uid = local.uid
instance_type = each.value.instance_type instance_type = each.value.instance_type
instance_count = each.value.initial_count initial_count = each.value.initial_count
image_id = var.image_id image_id = var.image_id
disk_size = each.value.disk_size disk_size = each.value.disk_size
disk_type = each.value.disk_type disk_type = each.value.disk_type

View file

@ -112,7 +112,7 @@ resource "google_compute_instance_group_manager" "instance_group_manager" {
description = "Instance group manager for Constellation" description = "Instance group manager for Constellation"
base_instance_name = local.name base_instance_name = local.name
zone = var.zone zone = var.zone
target_size = var.instance_count target_size = var.initial_count
dynamic "stateful_disk" { dynamic "stateful_disk" {
for_each = var.role == "control-plane" ? [1] : [] for_each = var.role == "control-plane" ? [1] : []

View file

@ -33,7 +33,7 @@ variable "instance_type" {
description = "Instance type for the nodes." description = "Instance type for the nodes."
} }
variable "instance_count" { variable "initial_count" {
type = number type = number
description = "Number of instances in the instance group." description = "Number of instances in the instance group."
} }

View file

@ -162,7 +162,7 @@ module "instance_group_control_plane" {
source = "./modules/instance_group" source = "./modules/instance_group"
name = local.name name = local.name
role = "control-plane" role = "control-plane"
instance_count = var.control_plane_count initial_count = var.control_plane_count
image_id = openstack_images_image_v2.constellation_os_image.image_id image_id = openstack_images_image_v2.constellation_os_image.image_id
flavor_id = var.flavor_id flavor_id = var.flavor_id
security_groups = [openstack_compute_secgroup_v2.vpc_secgroup.id] security_groups = [openstack_compute_secgroup_v2.vpc_secgroup.id]
@ -183,7 +183,7 @@ module "instance_group_worker" {
source = "./modules/instance_group" source = "./modules/instance_group"
name = local.name name = local.name
role = "worker" role = "worker"
instance_count = var.worker_count initial_count = var.worker_count
image_id = openstack_images_image_v2.constellation_os_image.image_id image_id = openstack_images_image_v2.constellation_os_image.image_id
flavor_id = var.flavor_id flavor_id = var.flavor_id
tags = local.tags tags = local.tags

View file

@ -20,7 +20,7 @@ locals {
resource "openstack_compute_instance_v2" "instance_group_member" { resource "openstack_compute_instance_v2" "instance_group_member" {
name = "${local.name}-${count.index}" name = "${local.name}-${count.index}"
count = var.instance_count count = var.initial_count
image_id = var.image_id image_id = var.image_id
flavor_id = var.flavor_id flavor_id = var.flavor_id
security_groups = var.security_groups security_groups = var.security_groups

View file

@ -17,7 +17,7 @@ variable "role" {
} }
} }
variable "instance_count" { variable "initial_count" {
type = number type = number
description = "Number of instances in the instance group." description = "Number of instances in the instance group."
} }

View file

@ -56,7 +56,7 @@ module "node_group" {
for_each = var.node_groups for_each = var.node_groups
node_group_name = each.key node_group_name = each.key
role = each.value.role role = each.value.role
amount = each.value.instance_count amount = each.value.initial_count
state_disk_size = each.value.disk_size state_disk_size = each.value.disk_size
vcpus = each.value.vcpus vcpus = each.value.vcpus
memory = each.value.memory memory = each.value.memory

View file

@ -1,10 +1,10 @@
variable "node_groups" { variable "node_groups" {
type = map(object({ type = map(object({
role = string role = string
instance_count = number // number of instances in the node group initial_count = number // number of instances in the node group
disk_size = number // size of state disk (GiB) disk_size = number // size of state disk (GiB)
vcpus = number vcpus = number
memory = number // amount of memory per instance (MiB) memory = number // amount of memory per instance (MiB)
})) }))
validation { validation {
condition = can([for group in var.node_groups : group.role == "control-plane" || group.role == "worker"]) condition = can([for group in var.node_groups : group.role == "control-plane" || group.role == "worker"])

View file

@ -199,12 +199,12 @@ func (v *AzureClusterVariables) String() string {
type AzureNodeGroup struct { type AzureNodeGroup struct {
// Role is the role of the node group. // Role is the role of the node group.
Role string `hcl:"role" cty:"role"` Role string `hcl:"role" cty:"role"`
// InstanceCount is optional for upgrades. // InitialCount is optional for upgrades.
InstanceCount *int `hcl:"instance_count" cty:"instance_count"` InitialCount *int `hcl:"initial_count" cty:"initial_count"`
InstanceType string `hcl:"instance_type" cty:"instance_type"` InstanceType string `hcl:"instance_type" cty:"instance_type"`
DiskSizeGB int `hcl:"disk_size" cty:"disk_size"` DiskSizeGB int `hcl:"disk_size" cty:"disk_size"`
DiskType string `hcl:"disk_type" cty:"disk_type"` DiskType string `hcl:"disk_type" cty:"disk_type"`
Zones *[]string `hcl:"zones" cty:"zones"` Zones *[]string `hcl:"zones" cty:"zones"`
} }
// AzureIAMVariables is user configuration for creating the IAM configuration with Terraform on Microsoft Azure. // AzureIAMVariables is user configuration for creating the IAM configuration with Terraform on Microsoft Azure.
@ -335,8 +335,8 @@ func (v *QEMUVariables) String() string {
type QEMUNodeGroup struct { type QEMUNodeGroup struct {
// Role is the role of the node group. // Role is the role of the node group.
Role string `hcl:"role" cty:"role"` Role string `hcl:"role" cty:"role"`
// InstanceCount is the number of instances to create. // InitialCount is the number of instances to create.
InstanceCount int `hcl:"instance_count" cty:"instance_count"` InitialCount int `hcl:"initial_count" cty:"initial_count"`
// DiskSize is the size of the disk to allocate to each node, in GiB. // DiskSize is the size of the disk to allocate to each node, in GiB.
DiskSize int `hcl:"disk_size" cty:"disk_size"` DiskSize int `hcl:"disk_size" cty:"disk_size"`
// CPUCount is the number of CPUs to allocate to each node. // CPUCount is the number of CPUs to allocate to each node.

View file

@ -171,11 +171,11 @@ func TestAzureClusterVariables(t *testing.T) {
Name: "cluster-name", Name: "cluster-name",
NodeGroups: map[string]AzureNodeGroup{ NodeGroups: map[string]AzureNodeGroup{
"control_plane_default": { "control_plane_default": {
Role: "ControlPlane", Role: "ControlPlane",
InstanceCount: to.Ptr(1), InitialCount: to.Ptr(1),
InstanceType: "Standard_D2s_v3", InstanceType: "Standard_D2s_v3",
DiskType: "StandardSSD_LRS", DiskType: "StandardSSD_LRS",
DiskSizeGB: 100, DiskSizeGB: 100,
}, },
}, },
ConfidentialVM: to.Ptr(true), ConfidentialVM: to.Ptr(true),
@ -198,12 +198,12 @@ user_assigned_identity = "my-user-assigned-identity"
confidential_vm = true confidential_vm = true
node_groups = { node_groups = {
control_plane_default = { control_plane_default = {
disk_size = 100 disk_size = 100
disk_type = "StandardSSD_LRS" disk_type = "StandardSSD_LRS"
instance_count = 1 initial_count = 1
instance_type = "Standard_D2s_v3" instance_type = "Standard_D2s_v3"
role = "ControlPlane" role = "ControlPlane"
zones = null zones = null
} }
} }
` `
@ -274,11 +274,11 @@ func TestQEMUClusterVariables(t *testing.T) {
Name: "cluster-name", Name: "cluster-name",
NodeGroups: map[string]QEMUNodeGroup{ NodeGroups: map[string]QEMUNodeGroup{
"control-plane": { "control-plane": {
Role: role.ControlPlane.TFString(), Role: role.ControlPlane.TFString(),
InstanceCount: 1, InitialCount: 1,
DiskSize: 30, DiskSize: 30,
CPUCount: 4, CPUCount: 4,
MemorySize: 8192, MemorySize: 8192,
}, },
}, },
Machine: "q35", Machine: "q35",
@ -298,11 +298,11 @@ func TestQEMUClusterVariables(t *testing.T) {
want := `name = "cluster-name" want := `name = "cluster-name"
node_groups = { node_groups = {
control-plane = { control-plane = {
disk_size = 30 disk_size = 30
instance_count = 1 initial_count = 1
memory = 8192 memory = 8192
role = "control-plane" role = "control-plane"
vcpus = 4 vcpus = 4
} }
} }
machine = "q35" machine = "q35"