terraform-provider-google icon indicating copy to clipboard operation
terraform-provider-google copied to clipboard

permadiff when setting target_size = 0 inside version block in google_compute_region_instance_group_manager

Open bamartos opened this issue 3 years ago • 5 comments

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request.
  • Please do not leave +1 or me too comments, they generate extra noise for issue followers and do not help prioritize the request.
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment.
  • If an issue is assigned to the modular-magician user, it is either in the process of being autogenerated, or is planned to be autogenerated soon. If an issue is assigned to a user, that user is claiming responsibility for the issue. If an issue is assigned to hashibot, a community member has claimed the issue already.

Terraform Version

Terraform v0.15.0

Affected Resource(s)

  • provider registry.terraform.io/hashicorp/google v3.64.0
  • provider registry.terraform.io/hashicorp/google-beta v3.64.0
  • provider registry.terraform.io/hashicorp/random v3.1.0
  • provider registry.terraform.io/hashicorp/tls v3.1.0

Terraform Configuration Files

# Copy-paste your Terraform configurations here.
#
# For large Terraform configs, please use a service like Dropbox and share a link to the ZIP file.
# For security, you can also encrypt the files using our GPG public key:
#    https://www.hashicorp.com/security
#
# If reproducing the bug involves modifying the config file (e.g., apply a config,
# change a value, apply the config again, see the bug), then please include both:
# * the version of the config before the change, and
# * the version of the config after the change.

resource "google_compute_region_instance_group_manager" "default" {

  name               = "test"
  base_instance_name = "tests-igm"
  region             = "europe-west1"
  description        = "Test"
  target_size        = 1
  project            = "my-project"

  update_policy {
    type                         = "OPPORTUNISTIC"
    minimal_action               = "REPLACE"
    instance_redistribution_type = "NONE"
    replacement_method           = "SUBSTITUTE"
    max_surge_fixed              = 3
    max_unavailable_fixed        = 3
  }

  version {
    name              = "default"
    instance_template = google_compute_instance_template.default.id
  }

  version {
    name              = "canary"
    instance_template = google_compute_instance_template.default.id
    target_size {
      percent = 0
    }
  }
}

resource "google_compute_instance_template" "default" {

  name         = "default-instance-template"
  machine_type = "f1-micro"
  project      = "my-project"

  disk {
    auto_delete  = true
    boot         = true
    source_image = "https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/global/images/ubuntu-2004-focal-v20200729"
  }

  network_interface {
    network = "default"
  }
}


resource "google_compute_instance_template" "canary" {
  name         = "canary-instance-template"
  machine_type = "f1-micro"
  project      = "my-project"

  disk {
    auto_delete  = true
    boot         = true
    source_image = "https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/global/images/ubuntu-2004-focal-v20200729"
  }

  network_interface {
    network = "default"
  }
}

Debug Output

Panic Output

Expected Behavior

Terraform applies normal the configuration the first time (1 instance group manager + 2 instance template versions), but when try to re-apply it shouldn't have any diff to apply.

Actual Behavior

Perma-diff the target_size

  # google_compute_region_instance_group_manager.default will be updated in-place
  ~ resource "google_compute_region_instance_group_manager" "default" {
        id                               = "myproject"
        name                             = "test"
        # (12 unchanged attributes hidden)


      ~ version {
            name              = "canary"
            # (1 unchanged attribute hidden)

          + target_size {
              + percent = 0
            }
        }
        # (2 unchanged blocks hidden)
    }

Steps to Reproduce

  1. terraform apply

Important Factoids

References

  • #0000

bamartos avatar Apr 19 '21 19:04 bamartos

version.target_size.percent will be set in the tf state only if its value greater than 0. Please use the percent value > 0 or not use in the config to avoid permadiff.

venkykuberan avatar Apr 21 '21 17:04 venkykuberan

Hey, if I will not use it, it will result an error since when you define multiple versions you need to provide at least one target size.

Using target size > 0 it will not create permadiff but it doesn't help on my use case.

Setting target_size = 0 it works and solves my usecase but it results in a permadiff thus the reason of this bug report.

Thank you

bamartos avatar Apr 21 '21 18:04 bamartos

@megan07 should we consider >= 0 here https://github.com/hashicorp/terraform-provider-google/blob/f4cc59ec3ab2859f424aa1d604f8b29af8f4c36b/google/resource_compute_instance_group_manager.go#L426?

What are your thoughts ?

venkykuberan avatar Apr 22 '21 17:04 venkykuberan

I'm taking a look at this. It's a bit more complicated since the API returns 0 for both percent and fixed when the entire block is unset, so adding >= 0 there will break any configs (in an undesirable way) that have target_size unset. We will need to fix this to allow for 0, I'm thinking we might need a diff suppress function with it, but haven't decided if that's the best approach yet or not.

megan07 avatar Apr 23 '21 19:04 megan07

@megan07 Our team is also running into this and it is tedious when investigating drift to find that it is a false alarm. Has there been any update on this?

zraider7 avatar Aug 05 '22 12:08 zraider7