terraform-google-modules / terraform-google-vm

Provisions VMs in Google Cloud
https://registry.terraform.io/modules/terraform-google-modules/vm/google
Apache License 2.0
220 stars 368 forks source link

feat: mig labels & most disruptive update policy action update #381

Closed rauny-brandao closed 6 months ago

rauny-brandao commented 6 months ago

Adds support on mig to most_disruptive_allowed_action and to all_instances_config labels

To create this PR, I ran make build, which updated the date and set defaultValue: null in the metadata.yml files. Please let me know if I should keep them.

google-cla[bot] commented 6 months ago

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

g-awmalik commented 6 months ago

/gcbrun

g-awmalik commented 6 months ago

@rauny-brandao - thanks for the PR. Can you please take a look at the lint failures?

rauny-brandao commented 6 months ago

@g-awmalik linting is fixed. Is there a way to see the failures for: terraform-google-vm-int-trigger?

g-awmalik commented 6 months ago

/gcbrun

rauny-brandao commented 6 months ago

@g-awmalik please let me know if we need something else for this to be merged, thank you!

g-awmalik commented 6 months ago

/gcbrun

jlenuffgsoi commented 5 months ago

Since this update, I encounter this error :

│ Error: Invalid value for input variable
│ 
│   on .terraform/modules/mymod/modules/gcp-mig-mymod/mig.tf line 44, in module "mig":
│   44:   update_policy = [{
│   45:     instance_redistribution_type = "PROACTIVE"
│   46:     max_surge_fixed              = 100
│   47:     max_surge_percent            = null
│   48:     max_unavailable_fixed        = null
│   49:     max_unavailable_percent      = null
│   50:     min_ready_sec                = null
│   51:     minimal_action               = "REPLACE"
│   52:     replacement_method           = null
│   53:     type                         = "PROACTIVE"
│   54:   }]
│ 
│ The given value is not suitable for module.mymod.module.mig.var.update_policy declared at .terraform/modules/mymod.mig/modules/mig/variables.tf:100,1-25: element 0: attribute "most_disruptive_allowed_action" is required.
╵

As stated in the official documentation, the update_policy block have these inputs :

type (required)
instance_redistribution_type (optional)
minimal_action (required)
most_disruptive_allowed_action (optional)
max_surge_percent  (optional)
max_unavailable_fixed  (optional)
min_ready_sec  (optional)
replacement_method (optional)

So, why can we replace this variable block :

variable "update_policy" {
  description = "The rolling update policy. https://www.terraform.io/docs/providers/google/r/compute_region_instance_group_manager#rolling_update_policy"
  type = list(object({
    max_surge_fixed                = number
    instance_redistribution_type   = string
    max_surge_percent              = number
    max_unavailable_fixed          = number
    max_unavailable_percent        = number
    min_ready_sec                  = number
    replacement_method             = string
    minimal_action                 = string
    type                           = string
    most_disruptive_allowed_action = string
  }))
  default = []
}

by :

variable "update_policy" {
  description = "The rolling update policy. https://www.terraform.io/docs/providers/google/r/compute_region_instance_group_manager#rolling_update_policy"
  type = list(object({
    instance_redistribution_type   = optional(string)
    max_surge_percent              = optional(number)
    max_unavailable_fixed          = optional(number)
    min_ready_sec                  = optional(number)
    replacement_method             = optional(string)
    minimal_action                 = string
    type                           = string
    most_disruptive_allowed_action = optional(string)
  }))
  default = []
}

?

With this code, the error disappears.

NB : the max_surge_fixed and the max_unavailable_percent are not used anymore

NB2 : the optional TF parameter was released on Sept. 2022 (1.3.0 TF version)

jlenuffgsoi commented 5 months ago

I think this is because you want to be as much compliant as possible : https://github.com/terraform-google-modules/terraform-google-vm/blob/master/modules/mig/versions.tf#L18C3-L18C32

...
terraform {
  required_version = ">=0.13.0"
...