Skip to content

Import of google_compute_instance with metadata.startup-script set #4388

@kartvep

Description

@kartvep

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 0.12.6
provider google 2.13.0

Affected Resource(s)

  • google_compute_instance

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_instance" "instance" {
  depends_on   = [google_compute_disk.disk]
  count        = var.number
  name         = "${var.name}-${var.start_num + count.index}"
  machine_type = var.instance_type
  zone         = var.availability_zone
  labels       = {
    iow_name = local.label
  }

  boot_disk {
    initialize_params {
      image  = var.base_image
      size   = local.boot_size
      type   = local.boot_type
      labels = {
        boot_disk_label = "${local.label}-sda"
      }
    }

    auto_delete = var.disks_autodelete
  }

  dynamic "attached_disk" {
    for_each = local.disks
    content {
      source = "${var.name}-${var.start_num + count.index}-${
        element(split(":", attached_disk.value), 2)
      }"
    }
  }

  network_interface {
    network    = local.network
    subnetwork = local.subnetwork
    access_config {
      nat_ip = google_compute_address.instance_ip[count.index].address
    }
  }

  metadata = {
    startup-script = var.startup_script != "" ? var.startup_script : data.template_file.startup_script.rendered
  }

}

Expected Behavior

terrafrom import will write startup-script of instance to metadata.startup-script field of resource in terraform state. Changes in startup-script WILL NOT force instance to be replaced.

Actual Behavior

terraform import writes startup-script to metadata_starup_script field. terraform plan after import shows instance replacement - it tryes to move startup-script value from metadata_startup_script to metadata.startup-script and change to metadata_startup_script forces instance to be replaced.

Steps to Reproduce

  1. terraform import google_compute_instance.instance instance-with-startup-script
  2. terraform plan

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions