terraform: create nodeGroups in tfvars from nodeGroups in config

This commit is contained in:
Malte Poll 2023-08-02 10:41:26 +02:00 committed by Malte Poll
parent d0ec7a3e54
commit 0c20ccb477
3 changed files with 98 additions and 122 deletions

View file

@ -74,8 +74,8 @@ type AWSNodeGroup struct {
// StateDiskSizeGB is the size of the state disk to allocate to each node, in GB.
StateDiskSizeGB int `hcl:"disk_size" cty:"disk_size"`
// InitialCount is the initial number of nodes to create in the node group.
// During upgrades this value is not set.
InitialCount *int `hcl:"initial_count" cty:"initial_count"`
// During upgrades this value ignored.
InitialCount int `hcl:"initial_count" cty:"initial_count"`
// Zone is the AWS availability-zone to use in the given region.
Zone string `hcl:"zone" cty:"zone"`
// InstanceType is the type of the EC2 instance to use.
@ -141,8 +141,8 @@ type GCPNodeGroup struct {
// StateDiskSizeGB is the size of the state disk to allocate to each node, in GB.
StateDiskSizeGB int `hcl:"disk_size" cty:"disk_size"`
// InitialCount is the initial number of nodes to create in the node group.
// During upgrades this value is not set.
InitialCount *int `hcl:"initial_count" cty:"initial_count"`
// During upgrades this value ignored.
InitialCount int `hcl:"initial_count" cty:"initial_count"`
Zone string `hcl:"zone" cty:"zone"`
InstanceType string `hcl:"instance_type" cty:"instance_type"`
DiskType string `hcl:"disk_type" cty:"disk_type"`
@ -219,11 +219,11 @@ type AzureNodeGroup struct {
// Role is the role of the node group.
Role string `hcl:"role" cty:"role"`
// InitialCount is optional for upgrades.
InitialCount *int `hcl:"initial_count" cty:"initial_count"`
InstanceType string `hcl:"instance_type" cty:"instance_type"`
DiskSizeGB int `hcl:"disk_size" cty:"disk_size"`
DiskType string `hcl:"disk_type" cty:"disk_type"`
Zones *[]string `hcl:"zones" cty:"zones"`
InitialCount int `hcl:"initial_count" cty:"initial_count"`
InstanceType string `hcl:"instance_type" cty:"instance_type"`
DiskSizeGB int `hcl:"disk_size" cty:"disk_size"`
DiskType string `hcl:"disk_type" cty:"disk_type"`
Zones []string `hcl:"zones" cty:"zones"`
}
// AzureIAMVariables is user configuration for creating the IAM configuration with Terraform on Microsoft Azure.
@ -371,7 +371,7 @@ type QEMUNodeGroup struct {
// InitialCount is the number of instances to create.
// InitialCount is optional for upgrades.
// Upgrades are not implemented for QEMU. The type is similar to other NodeGroup types for consistency.
InitialCount *int `hcl:"initial_count" cty:"initial_count"`
InitialCount int `hcl:"initial_count" cty:"initial_count"`
// DiskSize is the size of the disk to allocate to each node, in GiB.
DiskSize int `hcl:"disk_size" cty:"disk_size"`
// CPUCount is the number of CPUs to allocate to each node.

View file

@ -22,7 +22,7 @@ func TestAWSClusterVariables(t *testing.T) {
constants.ControlPlaneDefault: {
Role: role.ControlPlane.TFString(),
StateDiskSizeGB: 30,
InitialCount: toPtr(1),
InitialCount: 1,
Zone: "eu-central-1b",
InstanceType: "x1.foo",
DiskType: "foodisk",
@ -30,7 +30,7 @@ func TestAWSClusterVariables(t *testing.T) {
constants.WorkerDefault: {
Role: role.Worker.TFString(),
StateDiskSizeGB: 30,
InitialCount: toPtr(2),
InitialCount: 2,
Zone: "eu-central-1c",
InstanceType: "x1.bar",
DiskType: "bardisk",
@ -105,7 +105,7 @@ func TestGCPClusterVariables(t *testing.T) {
constants.ControlPlaneDefault: {
Role: "control-plane",
StateDiskSizeGB: 30,
InitialCount: toPtr(1),
InitialCount: 1,
Zone: "eu-central-1a",
InstanceType: "n2d-standard-4",
DiskType: "pd-ssd",
@ -113,7 +113,7 @@ func TestGCPClusterVariables(t *testing.T) {
constants.WorkerDefault: {
Role: "worker",
StateDiskSizeGB: 10,
InitialCount: toPtr(1),
InitialCount: 1,
Zone: "eu-central-1b",
InstanceType: "n2d-standard-8",
DiskType: "pd-ssd",
@ -177,7 +177,7 @@ func TestAzureClusterVariables(t *testing.T) {
NodeGroups: map[string]AzureNodeGroup{
constants.ControlPlaneDefault: {
Role: "ControlPlane",
InitialCount: to.Ptr(1),
InitialCount: 1,
InstanceType: "Standard_D2s_v3",
DiskType: "StandardSSD_LRS",
DiskSizeGB: 100,
@ -238,7 +238,6 @@ func TestOpenStackClusterVariables(t *testing.T) {
vars := OpenStackClusterVariables{
Name: "cluster-name",
Cloud: toPtr("my-cloud"),
FlavorID: "flavor-0123456789abcdef",
FloatingIPPoolID: "fip-pool-0123456789abcdef",
ImageURL: "https://example.com/image.raw",
DirectDownload: true,
@ -249,7 +248,8 @@ func TestOpenStackClusterVariables(t *testing.T) {
NodeGroups: map[string]OpenStackNodeGroup{
constants.ControlPlaneDefault: {
Role: "control-plane",
InitialCount: toPtr(1),
InitialCount: 1,
FlavorID: "flavor-0123456789abcdef",
Zone: "az-01",
StateDiskType: "performance-8",
StateDiskSizeGB: 30,
@ -262,6 +262,7 @@ func TestOpenStackClusterVariables(t *testing.T) {
want := `name = "cluster-name"
node_groups = {
control_plane_default = {
flavor_id = "flavor-0123456789abcdef"
initial_count = 1
role = "control-plane"
state_disk_size = 30
@ -270,7 +271,6 @@ node_groups = {
}
}
cloud = "my-cloud"
flavor_id = "flavor-0123456789abcdef"
floating_ip_pool_id = "fip-pool-0123456789abcdef"
image_url = "https://example.com/image.raw"
direct_download = true
@ -290,7 +290,7 @@ func TestQEMUClusterVariables(t *testing.T) {
NodeGroups: map[string]QEMUNodeGroup{
"control-plane": {
Role: role.ControlPlane.TFString(),
InitialCount: toPtr(1),
InitialCount: 1,
DiskSize: 30,
CPUCount: 4,
MemorySize: 8192,